Ejemplo n.º 1
0
        protected virtual bool DoSearch()
        {
            bool changed;

            searchString = FsmGUIUtility.SearchField(searchString, out changed);
            return(changed);
        }
Ejemplo n.º 2
0
        private bool DoHeader()
        {
            bool foldOut = EditorPrefs.GetBool("FsmVariables", true);
            Rect rect    = GUILayoutUtility.GetRect(new GUIContent("Variables"), FsmEditorStyles.variableHeader, GUILayout.ExpandWidth(true));

            rect.x     -= 1;
            rect.width += 2;
            Rect rect2 = new Rect(rect.width - 10, rect.y + 2, 25, 25);

            EventType eventType = FsmEditorUtility.ReserveEvent(rect2);

            if (GUI.Button(rect, "Variables" + (foldOut?"":"[Click to expand]"), FsmEditorStyles.variableHeader))
            {
                if (Event.current.button == 0)
                {
                    EditorPrefs.SetBool("FsmVariables", !foldOut);
                }
            }

            FsmEditorUtility.ReleaseEvent(eventType);

            bool isEnabled = GUI.enabled;

            GUI.enabled = FsmEditor.Active != null;
            if (GUI.Button(rect2, FsmEditorStyles.toolbarPlus, FsmEditorStyles.label))
            {
                FsmGUIUtility.SubclassMenu <FsmVariable>(CreateVariable);
                Event.current.Use();
            }
            GUI.enabled = isEnabled;
            return(foldOut);
        }
Ejemplo n.º 3
0
        private void DrawCreateGUI()
        {
            variableName = EditorGUILayout.TextField("Name", variableName);
            bool flag = !string.IsNullOrEmpty(variableName);

            if (!flag)
            {
                EditorGUILayout.HelpBox("Please enter a unique name for the variable before you continue.", MessageType.Warning);
            }

            if (flag)
            {
                foreach (FsmVariable variable in globalVariables.Variables)
                {
                    if (variable != null && variable.Name == variableName)
                    {
                        flag = false;
                    }
                }
            }

            GUI.enabled = flag;
            GUILayout.BeginHorizontal();
            GUILayout.Label("Type", GUILayout.Width(80));
            if (variableType == null)
            {
                variableType       = typeof(FsmBool);
                variableTypeString = variableType.Name.Replace("Fsm", "");
            }

            if (GUILayout.Button(variableTypeString, EditorStyles.toolbarDropDown))
            {
                FsmGUIUtility.SubclassMenu <FsmVariable>(delegate(Type type){
                    variableType       = type;
                    variableTypeString = variableType.Name.Replace("Fsm", "");
                });
            }

            if (GUILayout.Button("Add", EditorStyles.toolbarButton, GUILayout.Width(70)))
            {
                CreateVariable();
            }
            GUILayout.Space(5);
            GUILayout.EndHorizontal();
            GUILayout.Space(3);
            GUILayout.Box(GUIContent.none, "PopupCurveSwatchBackground", GUILayout.Height(2), GUILayout.ExpandWidth(true));

            if (!flag)
            {
                GUI.enabled = true;
            }
        }
Ejemplo n.º 4
0
 private void ComponentHint(SerializedProperty component, SerializedProperty property)
 {
     if (GUILayout.Button(GUIContent.none, "MiniPullDown", GUILayout.Width(15f)))
     {
         GUI.FocusControl(null);
         FsmGUIUtility.SubclassMenu <Component> (delegate(Type type) {
             component.serializedObject.Update();
             component.stringValue = type.Name;
             property.stringValue  = string.Empty;
             component.serializedObject.ApplyModifiedProperties();
             ErrorChecker.CheckForErrors();
         });
         EditorGUIUtility.ExitGUI();
     }
 }
Ejemplo n.º 5
0
 public override void OnPropertyField(SerializedProperty property, GUIContent label)
 {
     base.OnPropertyField(property, label);
     if (GUILayout.Button(GUIContent.none, "MiniPullDown", GUILayout.Width(18f)))
     {
         GUI.FocusControl(null);
         Type mType = fieldInfo.GetAttribute <ComponentAttribute>().Type ?? typeof(Component);
         FsmGUIUtility.SubclassMenu(mType, delegate(Type type){
             property.serializedObject.Update();
             property.stringValue = type.Name;
             property.serializedObject.ApplyModifiedProperties();
             ErrorChecker.CheckForErrors();
         });
         EditorGUIUtility.ExitGUI();
     }
 }
Ejemplo n.º 6
0
        private void OnConditionElement(int index, bool selected)
        {
            Condition condition = transition.Conditions [index];
            bool      enabled   = condition.IsEnabled;

            condition.IsOpen    = GUIDrawer.ObjectTitlebar(condition, condition.IsOpen, ref enabled, FsmGUIUtility.ExecutableContextMenu(condition, node));
            condition.IsEnabled = enabled;
            if (condition.IsOpen)
            {
                GUIDrawer.OnGUI(condition);
            }
        }
Ejemplo n.º 7
0
        private void ResetConditionList()
        {
            if (transition == null)
            {
                return;
            }
            this.conditions    = this.transition.Conditions;
            this.conditionList = new ReorderableList(this.conditions, "Condition", true, true)
            {
                drawElementCallback = new ReorderableList.ElementCallbackDelegate(this.OnConditionElement),
                onReorderCallback   = new ReorderableList.ReorderCallbackDelegate(this.OnReorderConditionList),
                onAddCallback       = new ReorderableList.AddCallbackDelegate(delegate(){
                    FsmGUIUtility.SubclassMenu <Condition> (CreateCondition);
                }),
                onContextClick = new ReorderableList.ContextCallbackDelegate(delegate(int index){
                    FsmGUIUtility.ExecutableContextMenu(conditions[index], node).ShowAsContext();
                }),
                onHeaderClick = new ReorderableList.OnHeaderClick(delegate(){
                    GenericMenu menu = new GenericMenu();

                    if (conditions.Length > 0)
                    {
                        menu.AddItem(new GUIContent("Copy"), false, delegate {
                            copy = transition;
                        });
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Copy"));
                    }
                    if (copy != null && copy.Conditions.Length > 0)
                    {
                        menu.AddItem(new GUIContent("Paste After"), false, delegate() {
                            for (int i = 0; i < copy.Conditions.Length; i++)
                            {
                                ExecutableNode dest   = FsmUtility.Copy(copy.Conditions[i]);
                                transition.Conditions = ArrayUtility.Add <Condition>(transition.Conditions, (Condition)dest);
                                FsmEditorUtility.ParentChilds(transition);
                                NodeInspector.Dirty();
                            }
                        });
                        menu.AddItem(new GUIContent("Paste Before"), false, delegate() {
                            for (int i = 0; i < copy.Conditions.Length; i++)
                            {
                                ExecutableNode dest   = FsmUtility.Copy(copy.Conditions[i]);
                                transition.Conditions = ArrayUtility.Insert <Condition>(transition.Conditions, (Condition)dest, 0);
                                FsmEditorUtility.ParentChilds(transition);
                                NodeInspector.Dirty();
                            }
                        });
                        if (copy != transition)
                        {
                            menu.AddItem(new GUIContent("Replace"), false, delegate() {
                                for (int i = 0; i < transition.Conditions.Length; i++)
                                {
                                    FsmEditorUtility.DestroyImmediate(transition.Conditions[i]);
                                }
                                transition.Conditions = new Condition[0];
                                ResetConditionList();

                                for (int i = 0; i < copy.Conditions.Length; i++)
                                {
                                    ExecutableNode dest   = FsmUtility.Copy(copy.Conditions[i]);
                                    transition.Conditions = ArrayUtility.Add <Condition>(transition.Conditions, (Condition)dest);
                                    FsmEditorUtility.ParentChilds(transition);
                                    NodeInspector.Dirty();
                                }
                            });
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent("Replace"));
                        }
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Paste After"));
                        menu.AddDisabledItem(new GUIContent("Paste Before"));
                        menu.AddDisabledItem(new GUIContent("Replace"));
                    }
                    menu.ShowAsContext();
                }),
            };
            this.host.Repaint();
            if (FsmEditor.instance != null)
            {
                FsmEditor.instance.Repaint();
            }
        }
Ejemplo n.º 8
0
        public static bool ObjectTitlebar(UnityEngine.Object targetObject, bool foldout, ref bool enabled, GenericMenu settings)
        {
            int        controlID = EditorGUIUtility.GetControlID(FocusType.Passive);
            GUIContent content   = new GUIContent(targetObject.name.Replace("/", "."), targetObject.GetTooltip());

            Debug.Log(FsmEditorStyles.inspectorTitle.fixedWidth);
            Rect position = GUILayoutUtility.GetRect(GUIContent.none, FsmEditorStyles.inspectorTitle);

            position.x     += 1f;
            position.width -= 3f;
            Rect rect  = new Rect(position.x + (float)FsmEditorStyles.inspectorTitle.padding.left, position.y + (float)FsmEditorStyles.inspectorTitle.padding.top, 16f, 16f);
            Rect rect1 = new Rect(position.xMax - (float)FsmEditorStyles.inspectorTitle.padding.right - 2f - 16f, rect.y, 16f, 16f);
            Rect rect4 = rect1;

            rect4.x = rect4.x - 18f;

            Rect rect2 = new Rect(position.x + 2f + 2f + 16f * 2, rect.y, 100f, rect.height)
            {
                xMax = rect4.xMin - 2f
            };
            Rect rect3 = new Rect(position.x + 16f, rect.y, 16f, 16f);

            enabled = GUI.Toggle(rect3, enabled, GUIContent.none);
            string url = targetObject.GetHelpUrl();

            if (ErrorChecker.HasErrors(targetObject))
            {
                Rect rect5 = rect4;
                rect5.y += 1.0f;
                if (!string.IsNullOrEmpty(url))
                {
                    rect5.x    = rect5.x - 18f;
                    rect2.xMax = rect5.x;
                }

                GUI.Label(rect5, FsmEditorStyles.errorIcon, FsmEditorStyles.inspectorTitleText);
            }

            if (GUI.Button(rect1, FsmEditorStyles.popupIcon, FsmEditorStyles.inspectorTitleText))
            {
                settings.ShowAsContext();
            }

            if (!string.IsNullOrEmpty(url) && GUI.Button(rect4, FsmEditorStyles.helpIcon, FsmEditorStyles.inspectorTitleText))
            {
                Application.OpenURL(url);
            }

            EventType eventType = Event.current.type;

            if (eventType != EventType.MouseDown)
            {
                if (eventType == EventType.Repaint)
                {
                    FsmEditorStyles.inspectorTitle.Draw(position, GUIContent.none, controlID, foldout);
                    Color color = GUI.contentColor;
                    if (FsmEditor.Active != null && FsmEditor.Active.Owner != null)
                    {
                        ICodeBehaviour behaviour = FsmEditor.Active.Owner;
                        if (behaviour.ActiveNode is State && (behaviour.ActiveNode as State).ActiveAction == targetObject)
                        {
                            GUI.contentColor = Color.green;
                        }
                    }
                    FsmEditorStyles.inspectorTitleText.Draw(rect2, content, controlID, foldout);
                    GUI.contentColor = color;
                }
            }
            position.width = 15;

            bool flag = FsmGUIUtility.DoToggleForward(position, controlID, foldout, GUIContent.none, GUIStyle.none);

            return(flag);
        }
        private void ResetActionList()
        {
            SerializedObject   obj      = new SerializedObject(state);
            SerializedProperty elements = obj.FindProperty("actions");

            actionList = new ReorderableObjectList(obj, elements);

            actionList.drawHeaderCallback = delegate(Rect rect) {
                EditorGUI.LabelField(rect, "Actions");
            };

            actionList.onAddCallback = delegate(ReorderableObjectList list) {
                FsmGUIUtility.SubclassMenu <StateAction> (delegate(Type type){
                    StateAction action = (StateAction)ScriptableObject.CreateInstance(type);
                    action.name        = type.GetCategory() + "." + type.Name;
                    action.hideFlags   = HideFlags.HideInHierarchy;
                    state.Actions      = ArrayUtility.Add <StateAction> (state.Actions, action);

                    if (EditorUtility.IsPersistent(state))
                    {
                        AssetDatabase.AddObjectToAsset(action, state);
                        AssetDatabase.SaveAssets();
                    }
                    list.index = list.count;
                    EditorUtility.SetDirty(state);
                });
            };

            actionList.drawElementCallback = delegate(int index, bool selected) {
                StateAction action  = state.Actions [index];
                bool        enabled = action.IsEnabled;
                if (selected)
                {
                    GUIStyle selectBackground = new GUIStyle("MeTransitionSelectHead")
                    {
                        stretchHeight = false,
                    };
                    selectBackground.overflow = new RectOffset(-1, -2, -2, 2);
                    GUILayout.BeginVertical(selectBackground);
                }
                action.IsOpen = GUIDrawer.ObjectTitlebar(action, action.IsOpen, ref enabled, FsmGUIUtility.ExecutableContextMenu(action, state));
                if (selected)
                {
                    GUILayout.EndVertical();
                }
                action.IsEnabled = enabled;
                if (action.IsOpen)
                {
                    GUIDrawer.OnGUI(action);
                }
            };

            actionList.onRemoveCallback = delegate(ReorderableObjectList list) {
                StateAction action = state.Actions[list.index];
                state.Actions = ArrayUtility.Remove <StateAction> (state.Actions, action);
                FsmEditorUtility.DestroyImmediate(action);
                list.index = list.index - 1;
                ErrorChecker.CheckForErrors();
                EditorUtility.SetDirty(state);
            };

            actionList.onContextClick = delegate(int index) {
                FsmGUIUtility.ExecutableContextMenu(state.Actions [index], state).ShowAsContext();
            };

            actionList.onHeaderContextClick = delegate() {
                GenericMenu menu = new GenericMenu();

                if (state.Actions.Length > 0)
                {
                    menu.AddItem(new GUIContent("Copy"), false, delegate {
                        copy      = new List <StateAction>(state.Actions);
                        copyState = state;
                    });
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Copy"));
                }

                if (copy == null)
                {
                    copy = new List <StateAction>();
                }

                copy.RemoveAll(x => x == null);
                if (copy.Count > 0)
                {
                    menu.AddItem(new GUIContent("Paste After"), false, delegate() {
                        for (int i = 0; i < copy.Count; i++)
                        {
                            ExecutableNode dest = FsmUtility.Copy(copy[i]);
                            state.Actions       = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest);
                            FsmEditorUtility.ParentChilds(state);
                            EditorUtility.SetDirty(state);
                            //	NodeInspector.Dirty();
                            ErrorChecker.CheckForErrors();
                        }
                    });
                    menu.AddItem(new GUIContent("Paste Before"), false, delegate() {
                        for (int i = 0; i < copy.Count; i++)
                        {
                            ExecutableNode dest = FsmUtility.Copy(copy[i]);
                            state.Actions       = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, 0);
                            FsmEditorUtility.ParentChilds(state);
                            EditorUtility.SetDirty(state);
                            //	NodeInspector.Dirty();
                            ErrorChecker.CheckForErrors();
                        }
                    });
                    if (copyState != state)
                    {
                        menu.AddItem(new GUIContent("Replace"), false, delegate() {
                            for (int i = 0; i < state.Actions.Length; i++)
                            {
                                FsmEditorUtility.DestroyImmediate(state.Actions[i]);
                            }
                            state.Actions = new StateAction[0];
                            ResetActionList();

                            for (int i = 0; i < copy.Count; i++)
                            {
                                ExecutableNode dest = FsmUtility.Copy(copy[i]);
                                state.Actions       = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest);
                                FsmEditorUtility.ParentChilds(state);
                                EditorUtility.SetDirty(state);
                                //	NodeInspector.Dirty();
                                ErrorChecker.CheckForErrors();
                            }
                        });
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Replace"));
                    }
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Paste After"));
                    menu.AddDisabledItem(new GUIContent("Paste Before"));
                    menu.AddDisabledItem(new GUIContent("Replace"));
                }
                menu.ShowAsContext();
            };

            this.host.Repaint();
            if (FsmEditor.instance != null)
            {
                FsmEditor.instance.Repaint();
            }
        }
Ejemplo n.º 10
0
        private void ResetActionList()
        {
            this.actions    = this.state.Actions;
            this.actionList = new ReorderableList(this.actions, "Action", true, true)
            {
                drawElementCallback = new ReorderableList.ElementCallbackDelegate(this.OnActionElement),
                onReorderCallback   = new ReorderableList.ReorderCallbackDelegate(this.OnReorderList),
                onAddCallback       = new ReorderableList.AddCallbackDelegate(delegate(){
                    FsmGUIUtility.SubclassMenu <StateAction> (CreateAction);
                }),
                onContextClick = new ReorderableList.ContextCallbackDelegate(delegate(int index){
                    FsmGUIUtility.ExecutableContextMenu(actions[index], state).ShowAsContext();
                }),
                onHeaderClick = new ReorderableList.OnHeaderClick(delegate(){
                    GenericMenu menu = new GenericMenu();

                    if (actions.Length > 0)
                    {
                        menu.AddItem(new GUIContent("Copy"), false, delegate {
                            copy      = new List <StateAction>(actions);
                            copyState = state;
                        });
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Copy"));
                    }

                    if (copy == null)
                    {
                        copy = new List <StateAction>();
                    }

                    copy.RemoveAll(x => x == null);
                    if (copy.Count > 0)
                    {
                        menu.AddItem(new GUIContent("Paste After"), false, delegate() {
                            for (int i = 0; i < copy.Count; i++)
                            {
                                ExecutableNode dest = FsmUtility.Copy(copy[i]);
                                state.Actions       = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest);
                                FsmEditorUtility.ParentChilds(state);
                                NodeInspector.Dirty();
                            }
                        });
                        menu.AddItem(new GUIContent("Paste Before"), false, delegate() {
                            for (int i = 0; i < copy.Count; i++)
                            {
                                ExecutableNode dest = FsmUtility.Copy(copy[i]);
                                state.Actions       = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, 0);
                                FsmEditorUtility.ParentChilds(state);
                                NodeInspector.Dirty();
                            }
                        });
                        if (copyState != state)
                        {
                            menu.AddItem(new GUIContent("Replace"), false, delegate() {
                                for (int i = 0; i < state.Actions.Length; i++)
                                {
                                    FsmEditorUtility.DestroyImmediate(state.Actions[i]);
                                }
                                state.Actions = new StateAction[0];
                                ResetActionList();

                                for (int i = 0; i < copy.Count; i++)
                                {
                                    ExecutableNode dest = FsmUtility.Copy(copy[i]);
                                    state.Actions       = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest);
                                    FsmEditorUtility.ParentChilds(state);
                                    NodeInspector.Dirty();
                                }
                            });
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent("Replace"));
                        }
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Paste After"));
                        menu.AddDisabledItem(new GUIContent("Paste Before"));
                        menu.AddDisabledItem(new GUIContent("Replace"));
                    }
                    menu.ShowAsContext();
                }),
            };
            this.host.Repaint();
            if (FsmEditor.instance != null)
            {
                FsmEditor.instance.Repaint();
            }
        }
Ejemplo n.º 11
0
        private void OnActionElement(int index, bool selected)
        {
            StateAction action  = actions [index];
            bool        enabled = action.IsEnabled;

            action.IsOpen    = GUIDrawer.ObjectTitlebar(action, action.IsOpen, ref enabled, FsmGUIUtility.ExecutableContextMenu(action, state));
            action.IsEnabled = enabled;
            if (action.IsOpen)
            {
                GUIDrawer.OnGUI(action);
            }
        }