Ejemplo n.º 1
0
        public static void Apply(ColorKey ck)
        {
            ColorBank bank = GetInstance();

            if (bank == null)
            {
                Debug.LogWarning("Can not find any instance of ColorBank in scene");
            }
            else
            {
                if (ck.NameInBank == null)
                {
                    ck.NameInBank = string.Empty;
                }
                if (bank.Colors != null)
                {
                    ColorData cd = FindColor(bank.Colors, ck.NameInBank);
                    if (cd != null)
                    {
                        UnityEngine.UI.Text text = ck.GetComponent <UnityEngine.UI.Text>();
                        if (text != null)
                        {
                            text.color    = cd.Color.normalColor;
                            text.material = cd.Material;
                            return;
                        }

                        UnityEngine.UI.Button button = ck.GetComponent <UnityEngine.UI.Button>();
                        if (button != null)
                        {
                            button.colors = cd.Color;
                            return;
                        }

                        UnityEngine.UI.Image image = ck.GetComponent <UnityEngine.UI.Image>();
                        if (image != null)
                        {
                            image.color = cd.Color.normalColor;
                            return;
                        }

                        ToggleTextColor ttc = ck.GetComponent <ToggleTextColor>();
                        if (ttc != null)
                        {
                            ttc.On  = cd.Color.normalColor;
                            ttc.Off = cd.Color.disabledColor;
                            return;
                        }
                    }
                    else
                    {
                        Debug.LogWarning("can not find color with name : " + ck.NameInBank + "in ColorBank");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void UpdateFromBank()
        {
            UnityEngine.UI.Text   text   = GetComponent <UnityEngine.UI.Text>();
            UnityEngine.UI.Button button = GetComponent <UnityEngine.UI.Button>();
            UnityEngine.UI.Image  image  = GetComponent <UnityEngine.UI.Image>();
            ToggleTextColor       ttc    = GetComponent <ToggleTextColor>();

            if (text != null)
            {
                UnityEditor.Undo.RecordObject(text, "Change Color");
            }
            if (button != null)
            {
                UnityEditor.Undo.RecordObject(button, "Change Color");
            }
            if (image != null)
            {
                UnityEditor.Undo.RecordObject(image, "Change Color");
            }
            if (ttc != null)
            {
                UnityEditor.Undo.RecordObject(ttc, "Change Color");
            }

            ColorBank.Apply(this);

            if (text != null)
            {
                UnityEditor.EditorUtility.SetDirty(text);
            }
            if (button != null)
            {
                UnityEditor.EditorUtility.SetDirty(button);
            }
            if (image != null)
            {
                UnityEditor.EditorUtility.SetDirty(image);
            }
            if (ttc != null)
            {
                UnityEditor.EditorUtility.SetDirty(ttc);
            }
        }