public void OnDisable()
 {
     FsmEditor.SelectTransition(null);
 }
Beispiel #2
0
		protected override void OnEnable ()
		{
			base.OnEnable ();
			FsmEditor.instance = this;
			variableEditor = new VariableEditor ();
			if (mainToolbar == null) {
				mainToolbar= new MainToolbar();			
			}
			centerView = true;
			EditorApplication.playmodeStateChanged += OnPlayModeStateChanged;
			ErrorChecker.CheckForErrors ();
		}
 private void SelectTransition(int index)
 {
     this.transition = transitions [index];
     FsmEditor.SelectTransition(this.transition);
     this.ResetConditionList();
 }
		private void OnSelectionChange ()
		{
			FsmEditor.SelectGameObject (Selection.activeGameObject);
		}
Beispiel #5
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            if (GUILayout.Button("Refresh", EditorStyles.toolbarButton))
            {
                FindFsms();
            }
            GUILayout.FlexibleSpace();
            FsmTool.Loaction mloc = (FsmTool.Loaction)EditorGUILayout.EnumPopup(location, EditorStyles.toolbarPopup, GUILayout.Width(100f));
            if (location != mloc)
            {
                location = mloc;
                FindFsms();
            }
            GUILayout.EndHorizontal();
            scroll = EditorGUILayout.BeginScrollView(scroll);
            for (int i = 0; i < fsms.Length; i++)
            {
                StateMachine fsm   = fsms[i];
                GUIStyle     style = FsmEditorStyles.elementBackground;
                if (i == index)
                {
                    style = new GUIStyle("MeTransitionSelectHead")
                    {
                        stretchHeight = false,
                    };
                    style.overflow = new RectOffset(-1, -2, -2, 2);
                }
                GUILayout.BeginVertical(style);
                GUILayout.Label(location == Loaction.Project? AssetDatabase.GetAssetPath(fsm):targets[i] + " : " + fsm.Name);

                Rect  elementRect = GUILayoutUtility.GetLastRect();
                Event ev          = Event.current;
                switch (ev.rawType)
                {
                case EventType.MouseDown:
                    if (elementRect.Contains(Event.current.mousePosition))
                    {
                        if (Event.current.button == 0)
                        {
                            DragAndDrop.objectReferences = new Object[1] {
                                fsm
                            };
                            dragIndex = i;
                            Event.current.Use();
                        }
                    }
                    break;

                case EventType.MouseUp:
                    if (elementRect.Contains(Event.current.mousePosition))
                    {
                        if (Event.current.button == 0)
                        {
                            index = i;
                            if (FsmEditor.instance == null)
                            {
                                FsmEditor.ShowWindow();
                            }
                            if (location == Loaction.Scene)
                            {
                                FsmEditor.SelectGameObject(targets[i]);
                            }
                            FsmEditor.SelectStateMachine(fsm);
                            Event.current.Use();
                        }
                    }
                    dragIndex = -1;
                    break;

                case EventType.MouseDrag:
                    if (dragIndex != -1)
                    {
                        DragAndDrop.StartDrag("Drag");
                        dragIndex = -1;
                        Event.current.Use();
                    }
                    break;
                }
                GUILayout.EndVertical();
            }
            EditorGUILayout.EndScrollView();
        }
Beispiel #6
0
        private void OnGUI()
        {
            List <FsmError> errors = ErrorChecker.GetErrors();

            if (selectedFsmErrors)
            {
                if (FsmEditor.instance != null)
                {
                    errors = errors.FindAll(x => x.State.Parent == FsmEditor.Active).ToList();
                }
                else
                {
                    errors.Clear();
                }
            }
            //Toolbar
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            if (GUILayout.Button("Refresh", EditorStyles.toolbarButton))
            {
                ErrorChecker.CheckForErrors();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Selected FSM Only", (selectedFsmErrors?(GUIStyle)"TE toolbarbutton" : EditorStyles.toolbarButton)))
            {
                selectedFsmErrors = !selectedFsmErrors;
                ErrorChecker.CheckForErrors();
                EditorPrefs.SetBool("SelectedFSMOnly", selectedFsmErrors);
            }
            GUILayout.EndHorizontal();

            scroll = EditorGUILayout.BeginScrollView(scroll);
            for (int i = 0; i < errors.Count; i++)
            {
                FsmError error = errors[i];
                GUIStyle style = FsmEditorStyles.elementBackground;
                if (i == index)
                {
                    style = new GUIStyle("MeTransitionSelectHead")
                    {
                        stretchHeight = false,
                    };
                    style.overflow = new RectOffset(-1, -2, -2, 2);
                }
                GUILayout.BeginVertical(style);
                GUILayout.Label(error.Type.ToString());
                GUILayout.Label(error.State.Parent.Name + " : " + error.State.Name + " : " + error.ExecutableNode.name + (error.FieldInfo != null? " : " + error.FieldInfo.Name:""));
                GUILayout.EndVertical();
                Rect  elementRect = new Rect(0, i * 19f * 2f, Screen.width, 19f * 2f);
                Event ev          = Event.current;
                switch (ev.rawType)
                {
                case EventType.MouseDown:
                    if (elementRect.Contains(Event.current.mousePosition))
                    {
                        if (Event.current.button == 0)
                        {
                            index = i;
                            if (FsmEditor.instance == null)
                            {
                                FsmEditor.ShowWindow();
                            }
                            FsmEditor.SelectNode(error.State);
                            Event.current.Use();
                        }
                    }
                    break;
                }
            }
            EditorGUILayout.EndScrollView();
        }
        public void ResetTransitionList()
        {
            SerializedObject   obj      = new SerializedObject(node);
            SerializedProperty elements = obj.FindProperty("transitions");

            transitionList = new ReorderableObjectList(obj, elements);
            transitionList.drawHeaderCallback = delegate(Rect rect) {
                EditorGUI.LabelField(rect, "Transitions");
                EditorGUI.LabelField(new Rect(rect.width - 25, rect.y, 50, 20), "Mute");
            };

            transitionList.onSelectCallback = delegate(int index) {
                if (node.Transitions.Length > 0)
                {
                    FsmEditor.SelectTransition(this.node.Transitions[index]);
                    this.ResetConditionList();
                }
            };

            transitionList.onRemoveCallback = delegate(ReorderableObjectList list) {
                Transition transition = node.Transitions[list.index];
                node.Transitions = ArrayUtility.Remove(node.Transitions, transition);
                FsmEditorUtility.DestroyImmediate(transition);
                list.index = Mathf.Clamp(list.index - 1, 0, list.count - 1);
                ErrorChecker.CheckForErrors();
                EditorUtility.SetDirty(node);
            };
            transitionList.drawElementCallback = delegate(int index, bool selected) {
                Transition transition = node.Transitions [index];
                if (selected)
                {
                    GUIStyle selectBackground = new GUIStyle("MeTransitionSelectHead")
                    {
                        stretchHeight = false,
                    };
                    selectBackground.overflow = new RectOffset(-1, -2, -2, 2);
                    GUILayout.BeginVertical(selectBackground);
                }
                GUILayout.BeginHorizontal();
                for (int i = 0; i < transition.Conditions.Length; i++)
                {
                    Condition condition = transition.Conditions[i];
                    if (ErrorChecker.HasErrors(condition))
                    {
                        GUILayout.Label(FsmEditorStyles.errorIcon);
                        break;
                    }
                }
                GUILayout.Label(transition.FromNode.Name + " -> " + transition.ToNode.Name, selected?EditorStyles.whiteLabel:EditorStyles.label);
                GUILayout.FlexibleSpace();
                transition.Mute = GUILayout.Toggle(transition.Mute, GUIContent.none, GUILayout.Width(15));
                GUILayout.Space(22f);
                GUILayout.EndHorizontal();
                if (selected)
                {
                    GUILayout.EndVertical();
                }
            };

            transitionList.onReorderCallback = delegate(ReorderableObjectList list) {
                FsmEditor.SelectTransition(this.node.Transitions[list.index]);
                this.ResetConditionList();
            };
            transitionList.onContextClick = delegate(int index) {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Remove"), false, delegate() {
                    Transition transition = node.Transitions[index];
                    node.Transitions      = ArrayUtility.Remove(node.Transitions, transition);
                    FsmEditorUtility.DestroyImmediate(transition);

                    transitionList.index = Mathf.Clamp((index == transitionList.index?index - 1:(index < transitionList.index?transitionList.index - 1:transitionList.index)), 0, node.Transitions.Length - 1);
                    ErrorChecker.CheckForErrors();
                    EditorUtility.SetDirty(node);
                });
                menu.ShowAsContext();
            };

            this.ResetConditionList();
            this.host.Repaint();
            if (FsmEditor.instance != null)
            {
                FsmEditor.instance.Repaint();
            }
        }
 public static void OpenFsmEditor()
 {
     FsmEditor.ShowWindow();
 }