Ejemplo n.º 1
0
            private void SaveDuration()
            {
                List <Duration> durations = new List <Duration>(StateMachineReflections.GetDurations(stateMachine));

                durations[stateIndex] = duration;
                StateMachineReflections.SetDurations(stateMachine, durations.ToArray());
            }
Ejemplo n.º 2
0
        private void DeleteState(int stateIndex)
        {
            Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[] { stateMachine, nodesInfo, this }, "State Deleted");

            DeleteStateReferencesInTransitions(stateIndex);

            nodesInfo.StatesCount--;
            nodesInfo.Names.RemoveAt(stateIndex);
            nodesInfo.Rects.RemoveAt(stateIndex);

            transitions.RemoveAt(stateIndex);

            List <Action[]> actions = new List <Action[]>(StateMachineReflections.GetActions(stateMachine));

            actions.RemoveAt(stateIndex);
            List <bool[]> isDurationEnd = new List <bool[]>(StateMachineReflections.GetIsDurationsEnd(stateMachine));

            isDurationEnd.RemoveAt(0);
            List <Duration> durations = new List <Duration>(StateMachineReflections.GetDurations(stateMachine));

            durations.RemoveAt(0);
            List <Condition[][]> conditions = new List <Condition[][]>(StateMachineReflections.GetConditions(stateMachine));

            conditions.RemoveAt(stateIndex);

            SaveStateMachine(actions.ToArray(), isDurationEnd.ToArray(), durations.ToArray(), conditions.ToArray());

            if (startStateIndex == stateIndex)
            {
                StateMachineReflections.SetStartStateIndex(stateMachine, startStateIndex = nodesInfo.StatesCount > 0 ? 0 : -1);
            }
        }
Ejemplo n.º 3
0
        private void CreateState(Vector2 mousePosition)
        {
            Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[] { stateMachine, nodesInfo, this }, "State Created");

            nodesInfo.StatesCount++;
            nodesInfo.Names.Add("New State");
            nodesInfo.Rects.Add(new Rect(mousePosition, NODE_SIZE));

            transitions.Add(new List <int>());

            List <Action[]> actions = new List <Action[]>(StateMachineReflections.GetActions(stateMachine));

            actions.Add(new Action[0]);
            List <bool[]> isDurationEnd = new List <bool[]>(StateMachineReflections.GetIsDurationsEnd(stateMachine));

            isDurationEnd.Add(new bool[0]);
            List <Duration> durations = new List <Duration>(StateMachineReflections.GetDurations(stateMachine));

            durations.Add(new ConstantDuration());
            List <Condition[][]> conditions = new List <Condition[][]>(StateMachineReflections.GetConditions(stateMachine));

            conditions.Add(new Condition[0][]);

            SaveStateMachine(actions.ToArray(), isDurationEnd.ToArray(), durations.ToArray(), conditions.ToArray());

            if (nodesInfo.StatesCount == 1)
            {
                StateMachineReflections.SetStartStateIndex(stateMachine, startStateIndex = 0);
            }
        }
Ejemplo n.º 4
0
            public State(StateMachineController stateMachine, NodesInfo nodesInfo, int stateIndex)
            {
                this.stateMachine = stateMachine;
                this.nodesInfo    = nodesInfo;
                this.stateIndex   = stateIndex;

                transitionsIndexes = StateMachineReflections.GetTransitions(stateMachine);
                isDurationsEnd     = StateMachineReflections.GetIsDurationsEnd(stateMachine);
                conditions         = StateMachineReflections.GetConditions(stateMachine);

                name     = nodesInfo.Names[stateIndex];
                duration = StateMachineReflections.GetDurations(stateMachine)[stateIndex];
                actions  = StateMachineReflections.GetActions(stateMachine)[stateIndex];

                transitions = new Transition[transitionsIndexes[stateIndex].Length];
                for (int i = 0; i < transitions.Length; i++)
                {
                    transitions[i] = new Transition("=> " + nodesInfo.Names[transitionsIndexes[stateIndex][i]], isDurationsEnd[stateIndex][i], conditions[stateIndex][i]);
                }
            }