Пример #1
0
        private void DrawButtonGUI()
        {
            // Generate button
            GUILayout.Space(10);
            GUIContent generateButton = ContentText.generateNoiseButton;

            switch (CurrentPattern.Type)
            {
            case PatternType.Noise:
                generateButton = ContentText.generateNoiseButton;
                break;

            case PatternType.Dots:
                generateButton = ContentText.generateDotsButton;
                break;

            case PatternType.Lines:
                generateButton = ContentText.generateLinesButton;
                break;

            default:
                Debug.LogWarningFormat(ContentText.buttonMissingPatternTypeWarning, CurrentPattern.Type);
                break;
            }
            if (GUILayout.Button(generateButton))
            {
                Generate(CurrentPattern);
                BeffioDitherEditorUtilities.UpdateMaterialsForTexture(_pattern.Texture);
                CurrentPattern.IsDirty = false;
            }
        }
Пример #2
0
        /* LOADING AND SAVING */
        #region Loading and Saving

        /// <summary>
        ///  Opens a file dialog and loads a .png image to a Texture2D.
        /// </summary>
        private Texture2D SelectAndLoadTexture()
        {
            string path = EditorUtility.OpenFilePanel(ContentText.selectImageDialogText, _loadPath, "png");

            if (path == "")
            {
                return(null);
            }

            _loadPath = Path.GetDirectoryName(path);

            return(BeffioDitherEditorUtilities.LoadTexture(path));
        }
Пример #3
0
        /* EDITOR DRAWING */
        #region Editor Drawing
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Branding
            BeffioDitherEditorUtilities.DrawInspectorBranding();
            GUILayout.Space(10);

            // Cache dirty state to prevent layouting error
            bool isDirty = CurrentPattern.IsDirty;

            // Settings
            EditorGUI.BeginChangeCheck();
            {
                // Texture Settings
                DrawTextureSettingGUI();

                // Type Selection
                DrawPatternTypeSelectionGUI();

                // Pattern Settings
                DrawPatternSettingsGUI();

                // Apply changes to serializedObject
                serializedObject.ApplyModifiedProperties();

                if (EditorGUI.EndChangeCheck())
                {
                    if (_autoGenerate)
                    {
                        Generate(CurrentPattern);
                        BeffioDitherEditorUtilities.UpdateMaterialsForTexture(_pattern.Texture);
                        CurrentPattern.IsDirty = false;
                    }
                    else
                    {
                        CurrentPattern.IsDirty = true;
                    }
                }
            }

            // Buttons
            DrawButtonGUI();

            // Help Message
            if (isDirty)
            {
                EditorGUILayout.HelpBox(ContentText.notGeneratedHelpBox, MessageType.Warning);
            }
        }
        /* INSPECTOR DRAWING */
        #region Inspector Drawing
        protected override void DrawGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
        {
            // Branding
            BeffioDitherEditorUtilities.DrawInspectorBranding();
            EditorGUILayout.Space();

            // Base Information
            FindProperties(properties);

            // Draw Base Paint Settings
            DrawStandardPropertiesGUI(materialEditor, properties);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(ContentText.ditheringHeader, EditorStyles.boldLabel);

            DrawDitheringSettingsGUI(materialEditor);
        }
Пример #5
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Branding
            BeffioDitherEditorUtilities.DrawInspectorBranding();
            GUILayout.Space(10);

            // Warning
            DrawGUIWarning();
            GUILayout.Space(10);

            // Fields
            DrawGUIFields();

            serializedObject.ApplyModifiedProperties();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }
Пример #6
0
        private void DrawButtonsGUI()
        {
            // Generate Button
            if (GUILayout.Button(ContentText.generateFromListButton))
            {
                GeneratePaletteTexture(CurrentPalette);
                BeffioDitherEditorUtilities.UpdateMaterialsForTexture(_palette.Texture);
                CurrentPalette.IsDirty = false;
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Random color generation", EditorStyles.boldLabel);
            //EditorGUILayout.LabelField("_______________________________________________________________________________________________________________");

            // Randomize colors button
            if (GUILayout.Button(ContentText.randomizeColors))
            {
                for (int i = 0; i < CurrentPalette.Colors.Count; i++)
                {
                    if (!_randomBW && !_selectiveRandomization)
                    {
                        CurrentPalette.Colors[i] = new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f));
                    }
                    else if (_randomBW)
                    {
                        v = UnityEngine.Random.Range(0f, 1f);
                        CurrentPalette.Colors[i] = new Color(v, v, v);
                    }
                    else if (!_randomBW && _selectiveRandomization)
                    {
                        if (_r && _g && _b)
                        {
                            CurrentPalette.Colors[i] = new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f));
                        }
                        else if (!_r && _g && _b)
                        {
                            CurrentPalette.Colors[i] = new Color(CurrentPalette.Colors[i].r, UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f));
                        }
                        else if (_r && !_g && _b)
                        {
                            CurrentPalette.Colors[i] = new Color(UnityEngine.Random.Range(0f, 1f), CurrentPalette.Colors[i].g, UnityEngine.Random.Range(0f, 1f));
                        }
                        else if (_r && _g && !_b)
                        {
                            CurrentPalette.Colors[i] = new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), CurrentPalette.Colors[i].b);
                        }
                        else if (!_r && _g && !_b)
                        {
                            CurrentPalette.Colors[i] = new Color(CurrentPalette.Colors[i].r, UnityEngine.Random.Range(0f, 1f), CurrentPalette.Colors[i].b);
                        }
                        else if (_r && !_g && !_b)
                        {
                            CurrentPalette.Colors[i] = new Color(UnityEngine.Random.Range(0f, 1f), CurrentPalette.Colors[i].g, CurrentPalette.Colors[i].b);
                        }
                        else if (!_r && !_g && _b)
                        {
                            CurrentPalette.Colors[i] = new Color(CurrentPalette.Colors[i].r, CurrentPalette.Colors[i].g, UnityEngine.Random.Range(0f, 1f));
                        }
                        else if (!_r && !_g && !_b)
                        {
                            CurrentPalette.Colors[i] = new Color(CurrentPalette.Colors[i].r, CurrentPalette.Colors[i].g, CurrentPalette.Colors[i].b);
                        }
                    }
                }

                GeneratePaletteTexture(CurrentPalette);
                BeffioDitherEditorUtilities.UpdateMaterialsForTexture(_palette.Texture);
                CurrentPalette.IsDirty = false;
            }
        }
Пример #7
0
        /* EDITOR DRAWING */
        #region Editor Drawing
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Branding
            BeffioDitherEditorUtilities.DrawInspectorBranding();
            GUILayout.Space(10);

            // Cache dirty and texture states to prevent layouting error
            bool hasTexture = CurrentPalette.HasTexture;
            bool isDirty    = CurrentPalette.IsDirty;

            EditorGUI.BeginChangeCheck();
            {
                // Settings
                DrawSettingsGUI();

                // Color List
                DrawColorListGUI();

                // Apply Changes to serializedObject
                serializedObject.ApplyModifiedProperties();

                if (EditorGUI.EndChangeCheck())
                {
                    if (_autoGenerate)
                    {
                        GeneratePaletteTexture(CurrentPalette);
                        BeffioDitherEditorUtilities.UpdateMaterialsForTexture(_palette.Texture);
                        CurrentPalette.IsDirty = false;
                    }
                    else
                    {
                        CurrentPalette.IsDirty = true;
                    }
                }
            }

            GUILayout.Space(10);

            // Auto generate checkbox
            _autoGenerate = EditorGUILayout.Toggle(ContentText.autoGenerate, _autoGenerate);

            // Buttons
            DrawButtonsGUI();

            // BW randomization checkbox
            _randomBW = EditorGUILayout.Toggle(ContentText.randomizeColorsBW, _randomBW);
            if (!_randomBW)
            {
                _selectiveRandomization = EditorGUILayout.Toggle(ContentText.selectiveRandomization, _selectiveRandomization);
                if (_selectiveRandomization)
                {
                    EditorGUI.indentLevel = 1;
                    _r = EditorGUILayout.Toggle("R", _r);
                    _g = EditorGUILayout.Toggle("G", _g);
                    _b = EditorGUILayout.Toggle("B", _b);
                    EditorGUI.indentLevel = 0;
                }
            }

            // Help Messages
            DrawHelpBoxGUI(hasTexture, isDirty);
        }
        private void DrawDitheringSettingsGUI(MaterialEditor materialEditor)
        {
            // Hack:    Get Palette and Pattern objects.
            //          Because it's not possible to save references to other objects within a shader or material object,
            //			This hack saves the instance id's in shader properties, by converting the exact bit setup to vectors.
            //_palette =    BeffioDitherEditorUtilities.GetAssetFromVector(_paletteRefProperty.vectorValue) as Palette;
            //_pattern =    BeffioDitherEditorUtilities.GetAssetFromVector(_patternRefProperty.vectorValue) as Pattern;

            if (_palette == null)
            {
                _palette = AssetDatabase.LoadAssetAtPath <Palette>(_defaultPalettePath);
            }

            if (_pattern == null)
            {
                _pattern = AssetDatabase.LoadAssetAtPath <Pattern>(_defaultPatternPath);
            }

            bool hasPatternTexture = (_hasPatternTextureProperty.floatValue > 0.5f);

            EditorGUI.indentLevel = 2;

            // Palette
            _palette = EditorGUILayout.ObjectField(ContentText.paletteProperty, _palette, typeof(Palette), false) as Palette;
            if (_palette != null)
            {
                _colorCountProperty.floatValue    = _palette.MixedColorCount;
                _paletteHeightProperty.floatValue = _palette.Texture.height;
                _paletteTexProperty.textureValue  = _palette.Texture;
                _paletteRefProperty.vectorValue   = BeffioDitherEditorUtilities.AssetToVector4GUID(_palette);
            }
            else
            {
                _colorCountProperty.floatValue    = 0;
                _paletteHeightProperty.floatValue = Texture2D.whiteTexture.height;
                _paletteTexProperty.textureValue  = Texture2D.whiteTexture;
                _paletteRefProperty.vectorValue   = Vector4.zero;
            }

            // Pattern Asset
            if (!hasPatternTexture)
            {
                EditorGUI.BeginChangeCheck();
                {
                    _pattern = EditorGUILayout.ObjectField(ContentText.patternProperty, _pattern, typeof(Pattern), false) as Pattern;
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (_pattern != null)
                        {
                            _patternSizeProperty.floatValue  = _pattern.Texture.height;
                            _patternTexProperty.textureValue = _pattern.Texture;
                            _patternRefProperty.vectorValue  = BeffioDitherEditorUtilities.AssetToVector4GUID(_pattern);
                        }
                        else
                        {
                            _patternSizeProperty.floatValue  = 0;
                            _patternTexProperty.textureValue = null;
                            _patternRefProperty.vectorValue  = Vector4.zero;
                        }
                        _hasPatternTextureProperty.floatValue = 0;
                    }
                }
            }


            // Pattern Texture
            if (_pattern == null)
            {
                EditorGUI.BeginChangeCheck();
                {
                    EditorGUI.indentLevel = 0;
                    materialEditor.TexturePropertySingleLine(ContentText.patternTextureProperty, _patternTexProperty);
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (_patternTexProperty.textureValue)
                        {
                            _patternSizeProperty.floatValue = _patternTexProperty.textureValue.height;
                        }
                        else
                        {
                            _patternSizeProperty.floatValue = 0;
                        }
                        _hasPatternTextureProperty.floatValue = (_patternTexProperty.textureValue == null ? 0 : 1);
                    }
                }
            }

            EditorGUI.indentLevel = 2;

            // Pattern Scale
            materialEditor.FloatProperty(_patternScaleProperty, ContentText.patternScaleProperty.text);

            // Screen Space Dithering
            EditorGUI.BeginChangeCheck();
            {
                bool enabled = EditorGUILayout.Toggle(ContentText.screenSpaceProperty, _targetMat.IsKeywordEnabled("_SCREENSPACEDITHER"));
                if (EditorGUI.EndChangeCheck())
                {
                    EnableKeyword("_SCREENSPACEDITHER", enabled, ContentText.screenSpaceUndo);
                }
            }

            // Alpha Cutout
            if (_targetMat.HasProperty("_Cutout"))
            {
                materialEditor.ShaderProperty(_cutoutProperty, ContentText.cutoutProperty.text);
            }
        }