private void OnGUI()
        {
            ColorAssistantUtils.DrawHeader();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            var buttonText = _texture == null ? "Import Image" : "Replace Image";

            if (GUILayout.Button(buttonText))
            {
                _texture = ColorAssistantUtils.GetTextureFromExplorer();
            }
            if (_texture)
            {
                (_width, _texRect) = ColorAssistantUtils.DrawTexture(_texture, _maxHeight);
            }
            EditorGUILayout.EndVertical();

            if (_texture)
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.BeginHorizontal();
                _tolerance = EditorGUILayout.Slider("Tolerance Filter", _tolerance, 0.1f, 1f);
                if (GUILayout.Button("Process"))
                {
                    _tempTex = ColorAssistantUtils.GetCopyTexture(_texture);
                    ProcessTempTexture();
                }
                EditorGUILayout.EndHorizontal();
                ColorAssistantUtils.DrawColorPalette(_filteredColors, 200, 20);
                EditorGUILayout.EndVertical();
            }
        }
 private static void HeaderSection()
 {
     ColorAssistantUtils.DrawHeader();
     EditorGUILayout.BeginVertical(EditorStyles.helpBox);
     GUILayout.Label("Create a palette for a certain palette settings", ColorAssistantUtils.GUIMessageStyle);
     EditorGUILayout.EndVertical();
     EditorGUILayout.Space();
 }
        private void ProcessTempTexture()
        {
            var pixelColors = new List <Color>();

            _filteredColors = new List <Color>();
            pixelColors     = ColorAssistantUtils.GetColors(_tempTex);
            _filteredColors = FilterPixels(pixelColors, ToleranceFilter);
            Debug.Log("Processing Complete! Colors Extracted: " + _filteredColors.Count);
        }
Exemple #4
0
        public override void OnInspectorGUI()
        {
            ColorAssistantUtils.DrawHeader();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.Space();
            HeaderSection();

            serializedObject.Update();
            var colorIdsProperty = serializedObject.FindProperty("colorIds");

            EditorList.Show("Color Keys", "Key", colorIdsProperty);
            serializedObject.ApplyModifiedProperties();

            EditorGUILayout.EndVertical();
        }
Exemple #5
0
        private void Debug()
        {
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            if (GUILayout.Button("Init Process"))
            {
                ProcessInit();
            }

            if (GUILayout.Button("Step")) //_maxSp > _threshold2
            {
                ProcessStep();
            }

            if (_texture)
            {
                GUILayout.Label("1. Squared Texture");
                ColorAssistantUtils.DrawTexture(_texture);
            }


            GUILayout.BeginHorizontal();
            _threshold2 = EditorGUILayout.FloatField("Sp Threshold", Mathf.Max(0f, _threshold2));
            if (GUILayout.Button("Auto threshold"))
            {
                _threshold2 = (_texture.width * _texture.height) / 1000f;
            }
            GUILayout.EndHorizontal();
            GUILayout.Label("Threshold 2: " + _threshold2.ToString("F1"));

            if (_binCreatedTex)
            {
                GUILayout.Label("2. Create 10x10 Bins From Texture");
                ColorAssistantUtils.DrawTexture(_binCreatedTex);
            }

            if (_voteTex)
            {
                GUILayout.Label("3. Populated votes");
                ColorAssistantUtils.DrawTexture(_voteTex);
            }

            GUILayout.Label("4. Max voted bin total votes: " + _maxVotedBin.TotalVotes);
            GUILayout.Label("5. Max sp: " + _maxSp);
            EditorGUILayout.EndVertical();
        }
Exemple #6
0
        public override void OnInspectorGUI()
        {
            ColorAssistantUtils.DrawHeader();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label("This is a singleton scriptable object. Use this to define your project's color palette." +
                            " Keep only one instance of this asset", ColorAssistantUtils.GUIMessageStyle);
            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.Space();
            GUILayout.Label("Palette Settings", EditorStyles.boldLabel);
            EditorGUILayout.Space();

            //Palette Settings
            serializedObject.Update();
            var paletteSettings = serializedObject.FindProperty("paletteSettings");

            paletteSettings.objectReferenceValue = (ColorPaletteSettings)EditorGUILayout.ObjectField("Palette Settings", _projectColorSetup.paletteSettings,
                                                                                                     typeof(ColorPaletteSettings), false);
            serializedObject.ApplyModifiedProperties();


            EditorGUILayout.BeginHorizontal();
            //Active Palette
            if (_projectColorSetup.paletteSettings != null)
            {
                var activePalette = serializedObject.FindProperty("activePalette");

                //Load available color palettes
                _configsGUIDs        = UnityEditor.AssetDatabase.FindAssets("t:" + typeof(ColorPalette).Name);
                _colorPalettes       = new List <ColorPalette>();
                _colorPalettesString = new List <string>();

                for (int i = 0; i < _configsGUIDs.Length; i++)
                {
                    var path         = AssetDatabase.GUIDToAssetPath(_configsGUIDs[i]);
                    var colorPalette = (ColorPalette)AssetDatabase.LoadAssetAtPath(path, typeof(ColorPalette));
                    if (_projectColorSetup.paletteSettings == colorPalette.settings)
                    {
                        _colorPalettes.Add(colorPalette);
                        _colorPalettesString.Add(colorPalette.name);
                    }
                }

                if (_colorPalettes.Count > 0)
                {
                    _activePaletteIndex = (activePalette.objectReferenceValue != null)
                        ? _colorPalettes.IndexOf((ColorPalette)activePalette.objectReferenceValue)
                        : 0;
                    if (_activePaletteIndex < 0)
                    {
                        _activePaletteIndex = 0;
                    }

                    //show palettes popup
                    _activePaletteIndex =
                        EditorGUILayout.Popup("Palette", _activePaletteIndex, _colorPalettesString.ToArray());
                    var palette = _colorPalettes[_activePaletteIndex];

                    if (palette == null)
                    {
                        activePalette.objectReferenceValue = null;
                    }
                    else if (palette.settings == _projectColorSetup.paletteSettings)
                    {
                        if (activePalette.objectReferenceValue != palette)
                        {
                            activePalette.objectReferenceValue = palette;
                            serializedObject.ApplyModifiedProperties();
                            _projectColorSetup.UpdateSceneMaterialColors();
                        }
                    }
                    else
                    {
                        activePalette.objectReferenceValue = null;
                    }

                    if (GUILayout.Button("Find"))
                    {
                        for (int i = 0; i < _configsGUIDs.Length; i++)
                        {
                            var path         = AssetDatabase.GUIDToAssetPath(_configsGUIDs[i]);
                            var colorPalette = (ColorPalette)AssetDatabase.LoadAssetAtPath(path, typeof(ColorPalette));
                            if (_projectColorSetup.activePalette == colorPalette)
                            {
                                Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(path);
                            }
                        }
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("Create a Palette with the given palette settings", MessageType.Error);
                }

                serializedObject.ApplyModifiedProperties();
            }
            else
            {
                EditorGUILayout.HelpBox("A Palette Settings is required", MessageType.Error);
            }



            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            //Helper
//            if (GUILayout.Button("Force Update"))
//                _projectColorSetup.UpdateSceneMaterialColors();
//
            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();
            EditorGUILayout.Space();


            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.Space();
            GUILayout.Label("Final Color Modifier", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label("Use these to modify the final color." +
                            " Works in editor only. Mainly used while making gameplay videos to adjust the contrast", ColorAssistantUtils.GUIMessageStyle);
            EditorGUILayout.EndVertical();

            //Check Contrast
            var checkContrast = serializedObject.FindProperty("checkContrast");

            checkContrast.boolValue = EditorGUILayout.ToggleLeft("Check Contrast", checkContrast.boolValue);
            if (_renderGrayscale == null)
            {
                _renderGrayscale = Camera.main.transform.GetComponent <RenderGrayscale>();
                if (_renderGrayscale == null)
                {
                    _renderGrayscale = Camera.main.gameObject.AddComponent <RenderGrayscale>();
                }
            }
            _renderGrayscale.greyScaleAmount = checkContrast.boolValue ? 1f : 0f;
            serializedObject.ApplyModifiedProperties();

            //Modify Properties
            var modifyProperties = serializedObject.FindProperty("modifyProperties");

            modifyProperties.boolValue = EditorGUILayout.ToggleLeft("Modify Final Color", modifyProperties.boolValue);
            if (_renderBsc == null)
            {
                _renderBsc = Camera.main.transform.GetComponent <RenderBSC>();
                if (_renderBsc == null)
                {
                    _renderBsc = Camera.main.gameObject.AddComponent <RenderBSC>();
                }
            }
            if (modifyProperties.boolValue)
            {
                _renderBsc.enabled = true;

                var brightness = serializedObject.FindProperty("brightness");
                brightness.floatValue = EditorGUILayout.Slider("Brightness", brightness.floatValue, 0f, 2f);

                var saturation = serializedObject.FindProperty("saturation");
                saturation.floatValue = EditorGUILayout.Slider("Saturation", saturation.floatValue, 0f, 2f);

                var contrast = serializedObject.FindProperty("contrast");
                contrast.floatValue = EditorGUILayout.Slider("Contrast", contrast.floatValue, 0f, 3f);

                _renderBsc.brightness = brightness.floatValue;
                _renderBsc.saturation = saturation.floatValue;
                _renderBsc.contrast   = contrast.floatValue;
            }
            else
            {
                _renderBsc.enabled = false;
            }

            EditorGUILayout.EndVertical();
            serializedObject.ApplyModifiedProperties();
        }
Exemple #7
0
        private void OnGUI()
        {
            ColorAssistantUtils.DrawHeader();

            //Get Resize and draw texture
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            var buttonText = _texture == null ? "Import Image" : "Replace Image";

            if (GUILayout.Button(buttonText))
            {
                _palette.Clear();
                _texture         = ColorAssistantUtils.GetTextureFromExplorer();
                _originalTexture = Instantiate(_texture);
                _texture         = ColorAssistantUtils.RescaleTexture(_texture, 100, true);
                _binCreatedTex   = null;
                _voteTex         = null;
            }

            EditorGUILayout.EndVertical();

            _debug = EditorGUILayout.Foldout(_debug, "Debug");
            if (_debug)
            {
                Debug();
            }
            GUILayout.Space(10);

            if (_originalTexture)
            {
                ColorAssistantUtils.DrawTexture(_originalTexture, 300);
            }

            GUILayout.Space(10);
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.BeginHorizontal();
            _threshold1 = EditorGUILayout.Slider("Color Difference Threshold", _threshold1, 0f, 1f);
            if (GUILayout.Button("Auto threshold"))
            {
                _threshold1 = 0.45f;
            }
            GUILayout.EndHorizontal();
            if (GUILayout.Button("Generate Palette"))
            {
                ProcessInit();
                for (int i = 0; i < 20; i++)
                {
                    ProcessStep();
                    if (_maxSp < _threshold2)
                    {
                        break;
                    }
                }
            }

            if (GUILayout.Button("Clear Data"))
            {
                _palette.Clear();
            }
            ColorAssistantUtils.DrawColorPalette(_palette, 200, 20);
            GUILayout.EndVertical();
        }