Example #1
0
        /// <summary>
        /// Draws the gui related
        /// </summary>
        /// <returns>True if there's a need to call the Repaint() method, false otherwise</returns>
        public bool DrawGUI()
        {
            repaint = false;
            Rect windowRect = GUILayoutUtility.GetRect(100, 1000, 60, 60);

            gradientPreviewRect  = new Rect(windowRect.x + 10, windowRect.y + 10, windowRect.width - 20, 25);
            keySelectionAreaRect = new Rect(gradientPreviewRect.x - 10, gradientPreviewRect.yMax, gradientPreviewRect.width + 20, 25);
            GUI.DrawTexture(gradientPreviewRect, gradient.GetTexture());
            if (keyRects == null || keyRects.Length != gradient.keys.Count)
            {
                keyRects = new Rect[gradient.keys.Count];
            }
            Rect selectedRect = Rect.zero;

            for (int i = 0; i < gradient.keys.Count; i++)
            {
                Rect keyRect = new Rect(gradientPreviewRect.x + gradientPreviewRect.width * gradient.keys[i].Time - 10, gradientPreviewRect.yMax, 20, 25);
                keyRects[i] = keyRect;
                if (i == selectedKeyIndex)
                {
                    selectedRect = keyRect;
                }
                else
                {
                    GUI.DrawTexture(keyRect, TSConstants.UpColor);
                    GUI.DrawTexture(keyRect, TSConstants.UpColorInternal, ScaleMode.ScaleToFit, true, 0, gradient.keys[i].Color, 0, 0);
                }
            }
            if (selectedRect != Rect.zero)
            {
                GUI.DrawTexture(selectedRect, TSConstants.UpColorSelected);
                GUI.DrawTexture(selectedRect, TSConstants.UpColorInternal, ScaleMode.ScaleToFit, true, 0, gradient.keys[selectedKeyIndex].Color, 0, 0);
            }

            Color col = EditorGUILayout.ColorField("Color", gradient.keys[selectedKeyIndex].Color);

            if (!col.Equals(gradient.keys[selectedKeyIndex].Color))
            {
                gradient.UpdateKeyColor(selectedKeyIndex, col);
            }

            float time = EditorGUILayout.FloatField("Location", gradient.keys[selectedKeyIndex].Time);

            if (time != gradient.keys[selectedKeyIndex].Time)
            {
                gradient.UpdateKeyTime(selectedKeyIndex, time);
            }

            rampWidth = (RampWidth)EditorGUILayout.EnumPopup("Ramp size", rampWidth);
            if ((int)rampWidth != gradient.GetTexture().width)
            {
                gradient.UpdateTextureWidth((int)rampWidth);
            }

            blendMode = (GradientTexture.BlendMode)EditorGUILayout.EnumPopup("Blend mode", blendMode);
            if (blendMode != gradient.blendMode)
            {
                gradient.blendMode = blendMode;
                gradient.UpdateTexture();
            }

            HandleEvents();
            EditorGUILayout.Space();
            return(repaint);
        }
Example #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 public GradientEditor()
 {
     gradient  = new GradientTexture(1024);
     rampWidth = RampWidth.L_1024;
     blendMode = GradientTexture.BlendMode.Linear;
 }