Exemple #1
0
 private static ColorBank GetInstance()
 {
     if (_Instance == null)
     {
         _Instance = FindObjectOfType <ColorBank>();
     }
     return(_Instance);
 }
Exemple #2
0
 protected override void OnDestroy()
 {
     base.OnDestroy();
     if (_Instance == this)
     {
         _Instance = null;
     }
 }
Exemple #3
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");
                    }
                }
            }
        }
Exemple #4
0
 /// <summary> Awake </summary>
 protected override void Awake()
 {
     base.Awake();
     if (_Instance == null)
     {
         _Instance = this;
     }
     else
     {
         Destroy(this.gameObject);
     }
 }
Exemple #5
0
        public static void UpdateAllKeys()
        {
            ColorBank bank = GetInstance();

            if (bank == null)
            {
                Debug.LogWarning("Can not find any instance of ColorBank in scene");
            }
            else
            {
                ColorKey[] colorKeys = FindObjectsOfType <ColorKey>();
                foreach (var ck in colorKeys)
                {
                    Apply(ck);
                }
            }
        }
Exemple #6
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);
            }
        }
Exemple #7
0
 void Start()
 {
     ColorBank.Apply(this);
 }