Exemplo n.º 1
0
 public void Draw(Rect position, Vector2 drag)
 {
     StratusGUIStyles.DrawBackgroundColor(position, background);
     offset += drag * 0.5f;
     DrawGrid(position, innerGrid);
     DrawGrid(position, outerGrid);
 }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            StratusGUIStyles.OverrideDefaultFont();

            // Invoke the very first time
            if (!this.doneFirstUpdate)
            {
                this.DoFirstUpdate();
            }

            // Now fulfill any custom requests at the end of inspection
            this.ProcessEndOfFrameRequests();

            // Update the serialized object, saving data
            this.serializedObject.Update();

            // Show any messages, if present
            if (this.messages.NotEmpty())
            {
                this.DrawMessages();
            }

            // Now draw the base editor
            if (this.drawnProperties > 0)
            {
                this.OnBaseEditorGUI();
            }

            // Now draw invokable methods
            if (this.buttons.NotEmpty())
            {
                this.DrawButtons();
            }

            // Now draw any custom draw functions
            if (this.drawGroupRequests.Count > 0)
            {
                foreach (DrawGroupRequest drawRequest in this.drawGroupRequests)
                {
                    if (drawRequest.isValid)
                    {
                        Rect rect = EditorGUILayout.BeginVertical(this.backgroundStyle);
                        drawRequest.onDraw(rect);
                        EditorGUILayout.EndVertical();
                    }
                }
            }
        }
Exemplo n.º 3
0
        //------------------------------------------------------------------------/
        // Fields
        //------------------------------------------------------------------------/


        //------------------------------------------------------------------------/
        // CTOR
        //------------------------------------------------------------------------/
        //public GUIObject(string label = null)
        //{
        //  this.label = label;
        //  onValidateDrag = null;
        //  dragData = null;
        //  dragDataIdentifier = null;
        //  onDrag = null;
        //  onDrop = null;
        //  onRightClickDown = onRightClickUp = null;
        //  onLeftClickDown = onLeftClickUp= null;
        //  onMiddleClickDown = onMiddleClickUp= null;
        //  showDescription = descriptionsWithLabel = false;
        //  tooltip = description = string.Empty;
        //  backgroundColor = Color.white;
        //}

        //------------------------------------------------------------------------/
        // Methods
        //------------------------------------------------------------------------/
        /// <summary>
        /// Draws this button using Unity's GUILayout system
        /// </summary>
        /// <param name="style"></param>
        /// <param name="options"></param>
        /// <returns>True if the mouse was moused over this control</returns>
        public bool Draw(GUIStyle style = null, params GUILayoutOption[] options)
        {
            GUIContent content = new GUIContent(showDescription ? $"{label}\n{description}" : label, tooltip);

            if (backgroundColor != default(Color))
            {
                GUI.backgroundColor = backgroundColor;
            }
            {
                GUILayout.Box(content, style, options);
                rect = GUILayoutUtility.GetLastRect();
            }
            if (backgroundColor != default(Color))
            {
                GUI.backgroundColor = Color.white;
            }
            if (outlineColor != default(Color) && isSelected)
            {
                StratusGUIStyles.DrawOutline(rect, outlineColor);
            }

            //Vector2 style .CalcSize(content)

            // Keyboard
            if (isSelected)
            {
                if (OnKey())
                {
                    return(true);
                }
            }

            // Mouse
            if (isMousedOver)
            {
                OnMouse();
                return(true);
            }

            return(false);
        }
        private void Draw <T>(T baseTrigger, Color backgroundColor, System.Action <T> selectFunction, System.Action <T> removeFunction, System.Action <T, GenericMenu> contextMenuSetter) where T : TriggerBase
        {
            string name = baseTrigger.GetType().Name;

            System.Action onLeftClick = () =>
            {
                selectedName = name;
                selected     = baseTrigger;
                selectFunction(baseTrigger);
                GUI.FocusControl(string.Empty);
                UpdateConnections();
            };

            System.Action onRightClick = () =>
            {
                var menu = new GenericMenu();
                contextMenuSetter(baseTrigger, menu);
                menu.AddSeparator("");
                // Enable
                menu.AddItem(new GUIContent(baseTrigger.enabled ? "Disable" : "Enable"), false, () =>
                {
                    baseTrigger.enabled = !baseTrigger.enabled;
                });
                // Duplicate
                menu.AddItem(new GUIContent("Duplicate/New"), false, () =>
                {
                    target.gameObject.DuplicateComponent(baseTrigger, false);
                });
                menu.AddItem(new GUIContent("Duplicate/Copy"), false, () =>
                {
                    target.gameObject.DuplicateComponent(baseTrigger, true);
                    UpdateConnections();
                });
                //// Reset
                //menu.AddItem(new GUIContent("Reset"), false, () => { baseTrigger.Invoke("Reset", 0f); });
                // Remove
                menu.AddItem(new GUIContent("Remove"), false, () =>
                {
                    removeFunction(baseTrigger);
                    UpdateConnections();
                });
                menu.ShowAsContext();
            };

            System.Action onDrag = () =>
            {
            };

            System.Action <object> onDrop = (object other) =>
            {
                if (baseTrigger is Trigger)
                {
                    if (other is Trigger)
                    {
                        triggerSwapOperations.Add(new Tuple <Trigger, Trigger>(baseTrigger as Trigger, other as Trigger));
                    }
                    else if (other is Triggerable)
                    {
                        Connect(baseTrigger as Trigger, other as Triggerable);
                    }
                }
                else if (baseTrigger is Triggerable)
                {
                    if (other is Triggerable)
                    {
                        triggerableSwapOperations.Add(new Tuple <Triggerable, Triggerable>(baseTrigger as Triggerable, other as Triggerable));
                    }
                    else if (other is Trigger)
                    {
                        Connect(other as Trigger, baseTrigger as Triggerable);
                    }
                }
            };

            Func <object, bool> onValidateDrag = (object other) =>
            {
                if (other is Trigger || other is Triggerable)
                {
                    return(true);
                }
                return(false);
            };

            var button = new GUIObject();

            button.label                 = baseTrigger.enabled ? name : $"<color=grey>{name}</color>";
            button.description           = $"<i><size={descriptionSize}>{baseTrigger.description}</size></i>";
            button.showDescription       = showDescriptions;
            button.descriptionsWithLabel = target.descriptionsWithLabel;
            button.tooltip               = baseTrigger.description;
            button.onLeftClickUp         = onLeftClick;
            button.onRightClickDown      = onRightClick;
            button.onDrag                = onDrag;
            button.onDrop                = onDrop;
            button.dragDataIdentifier    = "Stratus Trigger System Button";
            button.dragData              = baseTrigger;
            button.onValidateDrag        = onValidateDrag;
            button.AddKey(KeyCode.Delete, () =>
            {
                removeFunction(baseTrigger);
                UpdateConnections();
            });
            button.isSelected = selected == baseTrigger;
            //button.outlineColor = backgroundColor;

            if (target.outlines)
            {
                button.backgroundColor = Color.white;
                button.Draw(buttonStyle, columnWidth);
                StratusGUIStyles.DrawOutline(button.rect, backgroundColor, baseTrigger is Trigger ? StratusGUIStyles.Border.Right : StratusGUIStyles.Border.Left);
            }
            else
            {
                button.backgroundColor = backgroundColor;
                button.outlineColor    = Color.black;
                button.Draw(buttonStyle, columnWidth);
            }
        }