Example #1
0
        public string GetOrCreateColor(Color existingColor, int tolerance, string newColorName)
        {
            string closest      = string.Empty;
            int    closestSoFar = Int32.MaxValue;

            foreach (KeyValuePair <string, Color> colorPair in mCustomColorLookup)
            {
                int rDiff = (int)Mathf.Abs(existingColor.r - colorPair.Value.r) * 255;
                int gDiff = (int)Mathf.Abs(existingColor.g - colorPair.Value.g) * 255;
                int bDiff = (int)Mathf.Abs(existingColor.b - colorPair.Value.b) * 255;
                if (rDiff < closestSoFar && rDiff <= tolerance &&
                    gDiff < closestSoFar && gDiff <= tolerance &&
                    bDiff < closestSoFar && bDiff <= tolerance)
                {
                    closestSoFar = Mathf.Max(rDiff, gDiff);
                    closestSoFar = Mathf.Max(closestSoFar, bDiff);
                    closest      = colorPair.Key;
                }
            }

            if (string.IsNullOrEmpty(closest))
            {
                ColorKey ck = new ColorKey();
                ck.Name  = newColorName;
                ck.color = existingColor;
                ColorKeys.Add(ck);
                UnityEditor.EditorUtility.SetDirty(gameObject);
                UnityEditor.EditorUtility.SetDirty(this);
                closest = newColorName;
            }

            return(closest);
        }
Example #2
0
        public override void WakeUp()
        {
            base.WakeUp();

            PathColors   = gameObject.GetComponent <PathColorManager>();
            BannerColors = gameObject.GetComponent <BannerColorManager>();

            if (mStandardColorLookup.Count == 0)
            {
                //build the color lookup
                FieldInfo[] fields = this.GetType().GetFields();
                foreach (FieldInfo field in fields)
                {
                    if (field.FieldType == typeof(Color))                       //TODO find best way to clean fields
                    {
                        string colorName = field.Name;
                        Color  color     = (Color)field.GetValue(this);
                        if (field.IsDefined(typeof(InterfaceColorAttribute), true))
                        {
                            ColorKey cc = new ColorKey();
                            cc.Name  = field.Name;
                            cc.color = color;
                            mDefaultInterfaceColors.Add(cc);
                        }
                        mStandardColorLookup.Add(colorName, color);
                    }
                }

                foreach (FlagsetColor flagsetColor in FlagsetColors)
                {
                    Dictionary <int, Color> lookup = null;
                    if (!mColorFromFlagsetLookup.TryGetValue(flagsetColor.Flagset, out lookup))
                    {
                        lookup = new Dictionary <int, Color>();
                        mColorFromFlagsetLookup.Add(flagsetColor.Flagset, lookup);
                    }
                    lookup.Add(flagsetColor.Flags, flagsetColor.Color);
                }

                foreach (ColorKey colorKey in ColorKeys)
                {
                    mStandardColorLookup.Add(colorKey.Name, colorKey.color);
                }
            }
            Get = this;
        }
Example #3
0
        public List <ColorKey> InterfaceColorKeys()
        {
            List <ColorKey> colorKeys = new List <ColorKey>();

            System.Type type   = typeof(Colors);
            FieldInfo[] fields = type.GetFields();
            foreach (FieldInfo f in fields)
            {
                if (f.IsDefined(typeof(InterfaceColorAttribute), true))
                {
                    ColorKey cc = new ColorKey();
                    cc.Name  = f.Name;
                    cc.color = (Color)f.GetValue(this);
                    colorKeys.Add(cc);
                }
            }
            return(colorKeys);
        }