コード例 #1
0
        public override void OnInspectorGUI()
        {
            // base.OnInspectorGUI();
            serializedObject.Update();


            EditorGUI.BeginChangeCheck();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("Background"));

            List <string> allThemesString = new List <string>();

            themeManager.AllThemes.ForEach(p => allThemesString.Add(p.Name));
            int currentThemeIndex = themeManager.AllThemes.IndexOf(themeManager.CurrentTheme, 0);

            if (currentThemeIndex == -1)
            {
                currentThemeIndex = 0;
            }

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Current Theme: ");
            currentThemeIndex = EditorGUILayout.Popup(themeManager.CurrentThemeIndex, allThemesString.ToArray());
            GUILayout.EndHorizontal();

            //always one selected
            if (currentThemeIndex == -1)
            {
                currentThemeIndex = 0;
            }

            if (themeManager.AllThemes.Count > 0)
            {
                themeManager.CurrentTheme = themeManager.AllThemes[currentThemeIndex];
            }

            themeManager.CurrentThemeIndex = currentThemeIndex;

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            //all themetype first?
            EditorGUILayout.PropertyField(serializedObject.FindProperty("AllColors"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ThemeType"));
            //themeManager.ThemeType = EditorGUILayout("Image Path", myTheme.ImagePath);



            // if (tempThemes == null)
            //  tempThemes = new List<ThemeInfo>();
            //tempThemes.Clear();
            bool deleteTheme      = false;
            int  deleteThemeIndex = 0;

            bool addNewTheme = false;

            if (GUILayout.Button("Add New Theme"))
            {
                addNewTheme = true;
            }
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            for (int i = 0; i < themeManager.AllThemes.Count; i++)
            {
                ThemeInfo myTheme  = themeManager.AllThemes[i];
                ThemeInfo tmpTheme = myTheme;

                EditorGUILayout.LabelField("Theme: " + myTheme.Name);

                // myTheme.ThemeType = EditorGUILayout.Popup(_choiceIndex, themeManager.ThemeType.ToArray());
                tmpTheme.Name = EditorGUILayout.TextField("Name", myTheme.Name);


                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Theme Type: ");
                tmpTheme.ThemeType = EditorGUILayout.Popup(myTheme.ThemeType, themeManager.ThemeType.ToArray());
                GUILayout.EndHorizontal();

                tmpTheme.ImagePath = EditorGUILayout.TextField("Image Path", myTheme.ImagePath);


                if (tmpTheme.AllColors == null)
                {
                    tmpTheme.AllColors = new List <ThemeColorInfo>();
                }


                while (tmpTheme.AllColors.Count < themeManager.AllColors.Count)
                {
                    tmpTheme.AllColors.Add(new ThemeColorInfo());
                }

                //loop all colors
                for (int j = 0; j < themeManager.AllColors.Count; j++)
                {
                    tmpTheme.AllColors[j].Name  = themeManager.AllColors[j];
                    tmpTheme.AllColors[j].Color = EditorGUILayout.ColorField(themeManager.AllColors[j], myTheme.AllColors[j].Color);
                }



                // tempThemes.Add(tmpTheme);

                if (GUILayout.Button("Delete"))
                {
                    deleteTheme      = true;
                    deleteThemeIndex = i;
                }



                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Copy Theme Color"))
                {
                    themeManager.CopyTheme = myTheme;
                }
                if (GUILayout.Button("Paste Theme Color"))
                {
                    // myTheme.AllColors = themeManager.CopyTheme.AllColors;


                    //themeManager.AllThemes[i] = new ThemeInfo();
                    //themeManager.AllThemes[i].AllColors = new List<ThemeColorInfo>();

                    tmpTheme.AllColors = new List <ThemeColorInfo>();

                    //copy color
                    foreach (var myColor in themeManager.CopyTheme.AllColors)
                    {
                        ThemeColorInfo addNewColor = new ThemeColorInfo();
                        addNewColor.Color = myColor.Color;
                        addNewColor.Name  = myColor.Name;

                        tmpTheme.AllColors.Add(addNewColor);
                    }
                }
                GUILayout.EndHorizontal();

                themeManager.AllThemes[i] = tmpTheme;

                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }



            //filePath = EditorGUILayout.TextField("Path", filePath);
            // fileName = EditorGUILayout.TextField("Name", fileName);

            // _choiceIndex = EditorGUILayout.Popup(_choiceIndex, themeManager.ThemeType.ToArray());

            //no need for save
            EditorGUILayout.Space();
            if (GUILayout.Button("Save"))
            {
                PrefabUtility.ApplyPrefabInstance(themeManager.gameObject, InteractionMode.UserAction);
            }

            bool updateTheme = false;

            if (EditorGUI.EndChangeCheck())
            {
                updateTheme = true;
                // Debug.Log("SOMETHING CHANGED IN THEME! UPDATE ALL THEME ELEMENT");
            }

            if (addNewTheme)
            {
                themeManager.AllThemes.Add(new ThemeInfo());
                PrefabUtility.ApplyPrefabInstance(themeManager.gameObject, InteractionMode.UserAction);
            }

            if (deleteTheme)
            {
                themeManager.AllThemes.RemoveAt(deleteThemeIndex);
                PrefabUtility.ApplyPrefabInstance(themeManager.gameObject, InteractionMode.UserAction);
            }


            serializedObject.ApplyModifiedProperties();

            if (updateTheme)
            {
                themeManager.OnThemeUpdate.Invoke();

                editorTimer = 0;
                saveTheme   = true;
            }
        }
コード例 #2
0
        public void UpdateColor(bool immediate = false)
        {
            //  Debug.Log("UPDATE COLOR THEME ELEMENT " + this.name + " " + CurrentThemeColorInfoIndex1 + " " + ThemeManager.Instance.CurrentTheme.Name);

            if (CurrentThemeColorInfoIndex1 == -1)
            {
                return;
            }

            ThemeColorInfo CurrentThemeColorInfo = ThemeManager.Instance.CurrentTheme.AllColors[CurrentThemeColorInfoIndex1];
            var            useColor1             = ColorUtils.ChangeColorBrightness(CurrentThemeColorInfo.Color, ColorBrightness1);

            if (CurrentThemeColorInfoIndex2 == -1)
            {
                CurrentThemeColorInfoIndex2 = 0;
            }

            ThemeColorInfo CurrentThemeColorInfo2 = ThemeManager.Instance.CurrentTheme.AllColors[CurrentThemeColorInfoIndex2];
            var            useColor2 = ColorUtils.ChangeColorBrightness(CurrentThemeColorInfo2.Color, ColorBrightness2);

            //  if (!Application.isPlaying || force)
            // {

            if (CurrentThemeColorInfo == null)
            {
                return;
            }


            if (Gradient != null)
            {
                if (Application.isPlaying && !immediate)
                {
                    DOTween.To(() => Gradient.Vertex1, x => Gradient.Vertex1 = x, useColor1, ThemeManager.Instance.ThemeTransitionSpeed);
                    DOTween.To(() => Gradient.Vertex2, x => Gradient.Vertex2 = x, useColor2, ThemeManager.Instance.ThemeTransitionSpeed);
                }
                else
                {
                    Gradient.Vertex1 = useColor1;
                    Gradient.Vertex2 = useColor2;
                }



                if (Image.enabled)
                {
                    Image.enabled = false;
                    Image.enabled = true;
                }
            }
            else
            {
                if (Image != null)
                {
                    if (Application.isPlaying && !immediate)
                    {
                        Image.DOColor(useColor1, ThemeManager.Instance.ThemeTransitionSpeed);
                    }
                    else
                    {
                        Image.color = useColor1;
                    }


                    if (Image.enabled)
                    {
                        Image.enabled = false;
                        Image.enabled = true;
                    }
                }
            }

            if (Text != null)
            {
                if (Application.isPlaying && !immediate)
                {
                    Text.DOColor(useColor1, ThemeManager.Instance.ThemeTransitionSpeed);
                }
                else
                {
                    Text.color = useColor1;
                }

                if (Text.enabled)
                {
                    Text.enabled = false;
                    Text.enabled = true;
                }
            }

            if (SpriteRenderer != null)
            {
                if (Application.isPlaying && !immediate)
                {
                    SpriteRenderer.DOColor(useColor1, ThemeManager.Instance.ThemeTransitionSpeed);
                }
                else
                {
                    SpriteRenderer.color = useColor1;
                }


                if (SpriteRenderer.enabled)
                {
                    SpriteRenderer.enabled = false;
                    SpriteRenderer.enabled = true;
                }
            }



            //  }
        }