Ejemplo n.º 1
0
        //create state editor and its state
        public static StateEditor CreateState(StateMachineEditor sm, Vector2 position)
        {
            StateEditor stateEd = CreateInstance <StateEditor>();

            stateEd.sm   = sm;
            stateEd.name = "New State Editor";
            sm.Add(stateEd);
            stateEd.state = CreateInstance <State>();
            AssetDatabase.AddObjectToAsset(stateEd.state, sm.stateMachine);
            stateEd.state.name = "New State";
            stateEd.back       = new List <SMElementEditor>();
            stateEd.next       = new List <SMElementEditor>();
            stateEd.position   = position;
            return(stateEd);
        }
Ejemplo n.º 2
0
        private void Menu(Event e)
        {
            GenericMenu menu = new GenericMenu();

            SMElementEditor elem = sm.GetSelected(e.mousePosition, null);

            if (elem)
            {
                elem.Menu(menu);
            }
            else
            {
                menu.AddItem(new GUIContent("Add State"), false, () => { StateEditor s = StateEditor.CreateState(sm, sm.DrawPosToRealPos(e.mousePosition)); });
                menu.AddItem(new GUIContent("Add Transition"), false, () => { TransitionEditor s = TransitionEditor.CreateTransition(sm, sm.DrawPosToRealPos(e.mousePosition)); });
            }

            menu.ShowAsContext();
        }
        public override void OnInspectorGUI()
        {
            StateEditor stateE = (StateEditor)target;
            State       state  = stateE.state;

            GUILayout.BeginVertical();
            state.name  = EditorGUILayout.DelayedTextField("Name", state.name); //name field
            stateE.name = state.name + " Editor";

            int toRemove = -1;

            //show behaviours settings (if not hidden)
            for (int i = 0; i < state.behaviours.Count; ++i)
            {
                if (stateE.fold[i] = EditorGUILayout.Foldout(stateE.fold[i], state.behaviours[i].GetType().Name))
                {
                    CreateEditor(state.behaviours[i]).OnInspectorGUI();
                    VarHandleTemplateInspector.ShowVars(state.behaviours[i], stateE.sm.stateMachine.variables);
                    if (GUILayout.Button("Remove"))
                    {
                        toRemove = i;
                    }
                }
            }

            if (toRemove >= 0)
            {
                stateE.RemoveBehaviour(toRemove);
            }

            GUILayout.FlexibleSpace();
            //show add behaviour popup
            if (GUILayout.Button("Add"))
            {
                PopupWindow.Show(buttonRect, new AddBehaviourPopup(stateE));
            }
            if (Event.current.type == EventType.Repaint)
            {
                buttonRect = GUILayoutUtility.GetLastRect();
            }
            GUILayout.EndVertical();
        }
Ejemplo n.º 4
0
 //create popup for state s
 public AddBehaviourPopup(StateEditor s)
 {
     this.s = s;
 }
Ejemplo n.º 5
0
 private void OnEnable()
 {
     stateE = (StateEditor)target;
 }