private void SetupStateChart(StateChart chart)
        {
            var playerTurnState           = CreateState <PlayerTurnState>(Match3State.PlayerTurn);
            var swapInProgressState       = CreateState <SwapInProgressState>(Match3State.SwapInProgress);
            var revertSwapInProgressState = CreateState <RevertSwapInProgressState>(Match3State.RevertSwapInProgress);
            var matchesSearchState        = CreateState <MatchesSearchState>(Match3State.MatchesSearch);
            var fallingState  = CreateState <FallingState>(Match3State.MatchesFall);
            var gameOverState = CreateState <GameOverState>(Match3State.GameOver);

            var editor = new StateMachineEditor(chart);

            editor.Initial().Transition().Target(playerTurnState);

            playerTurnState.Event(BoardStateEvents.StartSwapEvent).Target(swapInProgressState);

            swapInProgressState.Event(BoardStateEvents.SwapCompleteEvent).Target(matchesSearchState);
            revertSwapInProgressState.Event(BoardStateEvents.SwapCompleteEvent).Target(playerTurnState);

            matchesSearchState.Event(BoardStateEvents.RevertSwapEvent).Target(revertSwapInProgressState);
            matchesSearchState.Event(BoardStateEvents.NoMatchesFoundEvent).Target(playerTurnState);
            matchesSearchState.Event(BoardStateEvents.MatchesFoundEvent).Target(fallingState);

            playerTurnState.Event(BoardStateEvents.NoTurnsLeftEvent).Target(gameOverState);

            fallingState.Event(BoardStateEvents.FallingCompleteEvent).Target(matchesSearchState);

            gameOverState.Event(BoardStateEvents.ExitBoardEvent).Target(editor.Final());
        }
Beispiel #2
0
                public static StateEditorGUI CreateStateEditorGUI(StateMachineEditor editor, State state)
                {
                    if (_editorGUIConstructorMap == null)
                    {
                        _editorGUIConstructorMap = new Dictionary <Type, Type>();
                        Type[] types = SystemUtils.GetAllSubTypes(typeof(StateEditorGUI));

                        foreach (Type type in types)
                        {
                            StateCustomEditorGUIAttribute eventAttribute = SystemUtils.GetAttribute <StateCustomEditorGUIAttribute>(type);
                            if (eventAttribute != null)
                            {
                                _editorGUIConstructorMap.Add(eventAttribute.StateType, type);
                            }
                        }
                    }

                    //Check for custom editor class
                    Type editorGUIType;

                    if (!_editorGUIConstructorMap.TryGetValue(state.GetType(), out editorGUIType))
                    {
                        //Use generic editor gui class
                        editorGUIType = typeof(StateEditorGUI);
                    }

                    StateEditorGUI editorGUI = (StateEditorGUI)CreateInstance(editorGUIType);

                    editorGUI.Init(editor, state);

                    return(editorGUI);
                }
Beispiel #3
0
                private bool DrawAddBackgroundLogicButton()
                {
                    int index = 0;

                    Type[] logicTypes = SystemUtils.GetAllSubTypes(typeof(ConditionalStateBackgroundLogic));

                    string[] logicTypeNames = new string[logicTypes.Length + 1];
                    logicTypeNames[index++] = "(Add State Background Logic)";

                    foreach (Type type in logicTypes)
                    {
                        logicTypeNames[index] = type.Name;
                        index++;
                    }

                    int newIndex = EditorGUILayout.Popup(string.Empty, 0, logicTypeNames);

                    if (0 != newIndex)
                    {
                        Type branchType = logicTypes[newIndex - 1];

                        ConditionalStateBackgroundLogic newBackgroundLogic = Activator.CreateInstance(branchType) as ConditionalStateBackgroundLogic;
                        ConditionalState conditionalState = (ConditionalState)GetEditableObject();

                        ArrayUtils.Add(ref conditionalState._backgroundLogic, newBackgroundLogic);

                        StateMachineEditor editor = (StateMachineEditor)GetEditor();
                        editor.OnAddedNewObjectToTimeline(newBackgroundLogic);

                        return(true);
                    }

                    return(false);
                }
                public override void DrawLabel(GUIStyle style)
                {
                    EventGoToState evnt = (EventGoToState)GetEditableObject();

                    GUIContent labelContent = new GUIContent(kLabelText);
                    Vector2    labelSize    = style.CalcSize(labelContent);
                    Rect       labelRect    = new Rect(0, 1, labelSize.x, labelSize.y);

                    GUI.Label(labelRect, labelContent, style);

                    GUIContent buttonContent = new GUIContent(evnt._state.GetStateName());
                    Vector2    buttonSize    = style.CalcSize(buttonContent) + kButtonPadding;

                    Rect buttonRect = new Rect(labelSize.x, 1, buttonSize.x, buttonSize.y);

                    if (GUI.Button(buttonRect, evnt._state.GetStateName()))
                    {
                        StateMachineEditor stateMachineEditor = GetTimelineEditor().GetParent() as StateMachineEditor;

                        if (stateMachineEditor != null)
                        {
                            stateMachineEditor.ShowStateDetails(evnt._state.GetStateID());
                        }
                    }
                }
Beispiel #5
0
    public void DrawTransitions()
    {
        if (outputTransitions.Count <= 0)
        {
            return;
        }

        Rect inputRect = nodeRect;

        foreach (NodeTransition transition in outputTransitions)
        {
            Rect outputRect = new Rect(transition.toNode.nodeRect);

            if (inputTransitions.Count > 0)
            {
                NodeTransition inputTransition = (NodeTransition)CreateInstance("NodeTransition");
                inputTransition.fromNode = transition.toNode;
                inputTransition.toNode   = transition.fromNode;

                if (inputTransitions.Contains(inputTransition))
                {
                    outputRect.x -= 20;
                }
            }

            StateMachineEditor.DrawNodeTransitionLine(inputRect, outputRect);
        }
    }
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        StateMachineEditor window = (StateMachineEditor)EditorWindow.GetWindow(typeof(StateMachineEditor));

        window.Show();

        //EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged;
    }
Beispiel #7
0
                private void CreateEditor()
                {
                    if (_stateMachineEditor == null || _stateMachineEditor.GetEditorWindow() == null)
                    {
                        StateMachineEditorStyle style = new StateMachineEditorStyle();
                        style._defaultStateColor = new Color(61f / 255f, 154f / 255f, 92f / 255f);
                        style._linkColor         = Color.white;

                        _stateMachineEditor = StateMachineEditor.CreateInstance <StateMachineEditor>();
                        _stateMachineEditor.Init(kWindowTitle, this, kWindowTag, SystemUtils.GetAllSubTypes(typeof(ITimelineStateEvent)), style);
                    }
                }
Beispiel #8
0
        private void SetupStateChart(StateChart chart)
        {
            var bootState  = new StateVertex(diContainer.Instantiate <BootState>());
            var mapState   = new StateVertex(diContainer.Instantiate <LevelSelectionState>());
            var boardState = new StateVertex(diContainer.Instantiate <BoardState>());

            var editor = new StateMachineEditor(chart);

            editor.Initial().Transition().Target(mapState);
            bootState.Transition().Target(mapState);
            mapState.Event(GameStateEvents.StartLevelEvent).Target(boardState);
            boardState.Event(GameStateEvents.ExitBoardEvent).Target(mapState);
            mapState.Event(GameStateEvents.DisposedEvent).Target(editor.Final());
        }
                public override bool RenderObjectProperties(GUIContent label)
                {
                    bool dataChanged = false;

                    dataChanged |= RenderStateDescriptionField();
                    dataChanged |= RenderStateColorField();

                    if (GUILayout.Button("Edit Timeline"))
                    {
                        StateMachineEditor timelineStateMachineEditor = (StateMachineEditor)GetEditor();
                        timelineStateMachineEditor.ShowStateDetails(GetEditableObject()._stateId);
                    }

                    return(dataChanged);
                }
                public override bool RenderObjectProperties(GUIContent label)
                {
                    EditorGUI.BeginChangeCheck();

                    GUILayout.Label("External State Link: " + ExternalStateRef, EditorStyles.centeredGreyMiniLabel);

                    EditorGUILayout.Separator();

                    if (GUILayout.Button("Open State machine"))
                    {
                        StateMachineEditor timelineStateMachineEditor = (StateMachineEditor)GetEditor();
                        timelineStateMachineEditor.LoadExternalState(this);
                    }

                    return(EditorGUI.EndChangeCheck());
                }
Beispiel #11
0
    public void OnInspectorGUI(Rect rect, StateMachineEditor graph)
    {
        GUILayout.BeginArea(rect, GUI.skin.box);
        EditorGUILayout.BeginVertical();
        object selected = graph.GetSelected();

        if (selected is StateMachineNode)
        {
            DrawState((StateMachineNode)selected);
        }
        if (selected is LZFighterStateTransition)
        {
            DrawTransition((LZFighterStateTransition)selected);
        }
        EditorGUILayout.EndVertical();

        ProcessEvents(Event.current);
        GUILayout.EndArea();
    }
Beispiel #12
0
                private bool DrawAddConditionButton()
                {
                    EditorGUILayout.BeginHorizontal(GUILayout.Width(20.0f));
                    {
                        if (GUILayout.Button("Add New Condition"))
                        {
                            ConditionalState       conditionalState = (ConditionalState)GetEditableObject();
                            ConditionalStateBranch newCondition     = new ConditionalStateBranch();
                            ArrayUtils.Add(ref conditionalState._branches, newCondition);

                            StateMachineEditor editor = (StateMachineEditor)GetEditor();
                            editor.OnAddedNewObjectToTimeline(newCondition);

                            return(true);
                        }

                        GUILayout.FlexibleSpace();
                    }
                    GUILayout.EndHorizontal();

                    return(false);
                }
Beispiel #13
0
 private void SetStateEditor()
 {
     graphEditor = new StateMachineEditor(fighter.stateMachine, fighter);
 }
                public override void OnDoubleClick()
                {
                    StateMachineEditor editor = (StateMachineEditor)GetEditor();

                    editor.ShowStateDetails(GetStateId());
                }
                public override void OnDoubleClick()
                {
                    StateMachineEditor editor = (StateMachineEditor)GetEditor();

                    editor.LoadExternalState(this);
                }