void UpdateColour(ColourManager colourManager, Colourise colourise)           //, bool paletteChanged) {
        // Create an array of palette colour names to be used as Popup dropdown
        {
            _colours = new string[colourManager.ColoursPerPalette];
            for (int i = 0; i < colourManager.ColoursPerPalette; i++)
            {
                _colours[i] = "Colour." + (i + 1);
            }

            // Detect changes to our palette colour listing and Add/Remove as necessary
            if (colourise.ColouriseComponents.Count > selectedColours.Count)
            {
                for (int i = selectedColours.Count; i < colourise.ColouriseComponents.Count; i++)
                {
                    selectedColours.Add(i);
                }
            }
            if (colourise.ColouriseComponents.Count < selectedColours.Count)
            {
                for (int i = selectedColours.Count - 1; i >= colourise.ColouriseComponents.Count; i--)
                {
                    selectedColours.RemoveAt(i);
                }
            }

            // Find our selected colour (via name vs index), assign and update as necessary
            for (int c = 0; c < colourise.ColouriseComponents.Count; c++)
            {
                ColouriseComponent cc = colourise.ColouriseComponents[c];

                // Reset values
                if (string.IsNullOrEmpty(cc.PaletteColour))
                {
                    _colourIndex = 0;
                }
                else
                {
                    List <string> lcolours = new List <string>(_colours);
                    _colourIndex = lcolours.FindIndex(f => f == cc.PaletteColour);
                    if (_colourIndex < 0)
                    {
                        _colourIndex = _colours.Length - 1;
                    }
                }

                // Assign values
                _colourIndex     = EditorGUILayout.Popup(cc.Name, _colourIndex, _colours);
                cc.PaletteColour = _colours[_colourIndex];

                // Detect changes
                cc.IsChanged = false;
                if (_colourIndex != selectedColours[c])
                {
                    selectedColours[c] = _colourIndex;
                    cc.ColourIndex     = _colourIndex;
                    cc.IsChanged       = true;
                    colourise.ReColour();
                }
            }
        }
        public void SaveComponents(List <Component> comps)
        {
            List <ColouriseComponent> colouriseComponents = new List <ColouriseComponent>();

            for (int i = 0; i < comps.Count; i++)
            {
                Component   c = comps[i];
                System.Type t = c.GetType();

                if (t.FullName == "CandyCabinets.Components.Colour.Colourise")
                {
                    continue;
                }

                PropertyInfo[] propertyInfo = t.GetProperties();
                foreach (PropertyInfo info in propertyInfo)
                {
                    // Give special treatment to SpriteRenderer if running in WebGL
                    // NOTE: We can add other Renderers below if WebGL is having difficulty detecting them..
                    if (Application.platform == RuntimePlatform.WebGLPlayer && t.Name == "SpriteRenderer")
                    {
                        SpriteRenderer spriteRenderer = c.GetComponent <SpriteRenderer>();
                        if (spriteRenderer == null)
                        {
                            break;
                        }
                        colouriseComponents.Add(new ColouriseComponent(t.Name + "." + info.PropertyType.Name, t.FullName, t.Name));
                        break;
                    }

                    if (info.PropertyType.FullName == "UnityEngine.Color")
                    {
                        colouriseComponents.Add(new ColouriseComponent(t.Name + "." + info.PropertyType.Name, t.FullName, t.Name));
                        break;
                    }
                }
            }

            // If we didn't find any component, reset our list
            if (colouriseComponents.Count <= 0)
            {
                ColouriseComponents = new List <ColouriseComponent>();
                return;
            }

            // Verify, add new and colourise
            colouriseComponents.ForEach(x => {
                ColouriseComponent match = ColouriseComponents.Find(c => c.Name == x.Name);
                if (match == null)
                {
                    ColouriseComponents.Add(x);
                    ReColour();
                }
            });

            // Verify and delete old
            List <ColouriseComponent> toRemove = new List <ColouriseComponent>();

            ColouriseComponents.ForEach(x => {
                ColouriseComponent match = colouriseComponents.Find(c => c.Name == x.Name);
                if (match == null)
                {
                    toRemove.Add(x);
                }
            });
            toRemove.ForEach(r => {
                ColouriseComponents.Remove(r);
            });
        }