예제 #1
0
        void Draw()
        {
            gradientPreveiwRect = new Rect(borderSize, borderSize, position.width - (borderSize * 2), 25);

            GUI.DrawTexture(gradientPreveiwRect, gradient.GetTexture((int)gradientPreveiwRect.width));
            keyRects = new Rect[gradient.NumKeys];
            for (int i = 0; i < gradient.NumKeys; i++)
            {
                ColorKey key = gradient.GetKey(i);

                Rect keyRect = new Rect(gradientPreveiwRect.x + gradientPreveiwRect.width * key.Time - (keyWidth / 2f), gradientPreveiwRect.yMax + borderSize, keyWidth, keyHeight);
                if (i == selectedKeyIndex)
                {
                    EditorGUI.DrawRect(new Rect(keyRect.x - 2, keyRect.y - 2, keyRect.width + 4, keyRect.height + 4), Color.black);
                }

                EditorGUI.DrawRect(keyRect, key.Color);
                keyRects[i] = keyRect;
            }

            Rect settingsRect = new Rect(borderSize, keyRects[0].y + borderSize + keyHeight, position.width - borderSize * 2, position.height - (borderSize + keyHeight * 4));

            GUILayout.BeginArea(settingsRect);
            EditorGUI.BeginChangeCheck();
            Color newcolor = EditorGUILayout.ColorField(gradient.GetKey(selectedKeyIndex).Color);

            if (EditorGUI.EndChangeCheck())
            {
                gradient.UpdateKeyColor(selectedKeyIndex, newcolor);
            }
            // display gradient
            gradient.blendMode      = (MegaGradient.BlendMode)EditorGUILayout.EnumPopup("Blend Mode", gradient.blendMode);
            gradient.randomizeColor = EditorGUILayout.Toggle("Randomize New Color", gradient.randomizeColor);
            GUILayout.EndArea();
        }
예제 #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            MegaGradient gradient = (MegaGradient)fieldInfo.GetValue(property.serializedObject.targetObject);

            if (gradient.hide)
            {
                //	GUI.Label(position, new GUIContent("Hidden"));
                return;
            }
            else
            {
                Event guiEvent = Event.current;

                float labelWidth  = GUI.skin.label.CalcSize(label).x + LABEL_BUFFER;
                Rect  textureRect = new Rect(position.x + labelWidth, position.y, position.width - labelWidth, position.height);

                // display gradient on inspector
                if (guiEvent.type == EventType.Repaint)
                {
                    GUI.Label(position, label);
                    GUI.DrawTexture(textureRect, gradient.GetTexture((int)position.width));
                }
                else
                {
                    // if mouse down and left mouse button click
                    if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
                    {
                        // if mouse position inside the gradient box
                        if (textureRect.Contains(guiEvent.mousePosition))
                        {
                            MegaGradientEditor window = EditorWindow.GetWindow <MegaGradientEditor>();
                            window.SetGradient(gradient);
                        }
                    }
                }
            }
        }