UnityEditor.GradientEditor.ShowSwatchArray C# (CSharp) Method

ShowSwatchArray() private method

private ShowSwatchArray ( Rect position, List swatches, bool isAlpha ) : void
position UnityEngine.Rect
swatches List
isAlpha bool
return void
        private void ShowSwatchArray(Rect position, List<Swatch> swatches, bool isAlpha)
        {
            bool flag2;
            int controlID = GUIUtility.GetControlID(0x26e20929, FocusType.Passive);
            Event current = Event.current;
            float time = this.GetTime((Event.current.mousePosition.x - position.x) / position.width);
            Vector2 point = new Vector3(position.x + (time * position.width), Event.current.mousePosition.y);
            EventType typeForControl = current.GetTypeForControl(controlID);
            switch (typeForControl)
            {
                case EventType.MouseDown:
                {
                    Rect rect = position;
                    rect.xMin -= 10f;
                    rect.xMax += 10f;
                    if (rect.Contains(current.mousePosition))
                    {
                        GUIUtility.hotControl = controlID;
                        current.Use();
                        if ((!swatches.Contains(this.m_SelectedSwatch) || this.m_SelectedSwatch.m_IsAlpha) || !this.CalcSwatchRect(position, this.m_SelectedSwatch).Contains(current.mousePosition))
                        {
                            flag2 = false;
                            foreach (Swatch swatch2 in swatches)
                            {
                                if (this.CalcSwatchRect(position, swatch2).Contains(point))
                                {
                                    flag2 = true;
                                    this.m_SelectedSwatch = swatch2;
                                    break;
                                }
                            }
                            break;
                        }
                        if (current.clickCount == 2)
                        {
                            GUIUtility.keyboardControl = controlID;
                            ColorPicker.Show(GUIView.current, this.m_SelectedSwatch.m_Value, false, false, null);
                            GUIUtility.ExitGUI();
                        }
                    }
                    return;
                }
                case EventType.MouseUp:
                    if (GUIUtility.hotControl == controlID)
                    {
                        GUIUtility.hotControl = 0;
                        current.Use();
                        if (!swatches.Contains(this.m_SelectedSwatch))
                        {
                            this.m_SelectedSwatch = null;
                        }
                        this.RemoveDuplicateOverlappingSwatches();
                    }
                    return;

                case EventType.MouseDrag:
                    if ((GUIUtility.hotControl == controlID) && (this.m_SelectedSwatch != null))
                    {
                        current.Use();
                        if (((current.mousePosition.y + 5f) >= position.y) && ((current.mousePosition.y - 5f) <= position.yMax))
                        {
                            if (!swatches.Contains(this.m_SelectedSwatch))
                            {
                                swatches.Add(this.m_SelectedSwatch);
                            }
                        }
                        else if (swatches.Count > 1)
                        {
                            swatches.Remove(this.m_SelectedSwatch);
                            this.AssignBack();
                            return;
                        }
                        this.m_SelectedSwatch.m_Time = time;
                        this.AssignBack();
                    }
                    return;

                case EventType.KeyDown:
                    if (current.keyCode == KeyCode.Delete)
                    {
                        if (this.m_SelectedSwatch != null)
                        {
                            List<Swatch> rGBSwatches;
                            if (!this.m_SelectedSwatch.m_IsAlpha)
                            {
                                rGBSwatches = this.m_RGBSwatches;
                            }
                            else
                            {
                                rGBSwatches = this.m_AlphaSwatches;
                            }
                            if (rGBSwatches.Count > 1)
                            {
                                rGBSwatches.Remove(this.m_SelectedSwatch);
                                this.AssignBack();
                                HandleUtility.Repaint();
                            }
                        }
                        current.Use();
                    }
                    return;

                case EventType.Repaint:
                {
                    bool flag = false;
                    foreach (Swatch swatch in swatches)
                    {
                        if (this.m_SelectedSwatch == swatch)
                        {
                            flag = true;
                        }
                        else
                        {
                            this.DrawSwatch(position, swatch, !isAlpha);
                        }
                    }
                    if (flag && (this.m_SelectedSwatch != null))
                    {
                        this.DrawSwatch(position, this.m_SelectedSwatch, !isAlpha);
                    }
                    return;
                }
                default:
                    switch (typeForControl)
                    {
                        case EventType.ValidateCommand:
                            if (current.commandName == "Delete")
                            {
                                Event.current.Use();
                            }
                            return;

                        case EventType.ExecuteCommand:
                            if (current.commandName == "ColorPickerChanged")
                            {
                                GUI.changed = true;
                                this.m_SelectedSwatch.m_Value = ColorPicker.color;
                                this.AssignBack();
                                HandleUtility.Repaint();
                            }
                            else if ((current.commandName == "Delete") && (swatches.Count > 1))
                            {
                                swatches.Remove(this.m_SelectedSwatch);
                                this.AssignBack();
                                HandleUtility.Repaint();
                            }
                            return;

                        default:
                            return;
                    }
                    break;
            }
            if (!flag2)
            {
                if (swatches.Count < 8)
                {
                    Color color = this.m_Gradient.Evaluate(time);
                    if (isAlpha)
                    {
                        color = new Color(color.a, color.a, color.a, 1f);
                    }
                    else
                    {
                        color.a = 1f;
                    }
                    this.m_SelectedSwatch = new Swatch(time, color, isAlpha);
                    swatches.Add(this.m_SelectedSwatch);
                    this.AssignBack();
                }
                else
                {
                    Debug.LogWarning(string.Concat(new object[] { "Max ", 8, " color keys and ", 8, " alpha keys are allowed in a gradient." }));
                }
            }
        }