Пример #1
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);
                        }
                    }
                }
            }
        }
Пример #2
0
 public void SetGradient(MegaGradient gradient)
 {
     this.gradient = gradient;
 }