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); } }
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); } }
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]); } }
private void DeleteTransition(int stateIndex, int transitionIndex) { Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[] { stateMachine, this }, "Transition Deleted"); transitions[stateIndex].RemoveAt(transitionIndex); StateMachineReflections.SetTransitions(stateMachine, transitions.Select(a => a.ToArray()).ToArray()); bool[][] isDurationsEnd = StateMachineReflections.GetIsDurationsEnd(stateMachine); List <bool> isDurationEnd = new List <bool>(isDurationsEnd[transitionIndex]); isDurationEnd.RemoveAt(transitionIndex); isDurationsEnd[transitionIndex] = isDurationEnd.ToArray(); StateMachineReflections.SetIsDurationsEnd(stateMachine, isDurationsEnd); Condition[][][] conditions = StateMachineReflections.GetConditions(stateMachine); List <Condition[]> stateConditions = new List <Condition[]>(conditions[stateIndex]); stateConditions.RemoveAt(transitionIndex); conditions[stateIndex] = stateConditions.ToArray(); StateMachineReflections.SetConditions(stateMachine, conditions); }
private void CreateTransition(Vector2 mousePosition) { int stateIndex = GetStateIndex(mousePosition); if (stateIndex != -1 && stateIndex != creatingTransitionFromStateIndex) { Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[] { stateMachine, this }, "Transition Created"); transitions[creatingTransitionFromStateIndex].Add(stateIndex); StateMachineReflections.SetTransitions(stateMachine, transitions.Select(a => a.ToArray()).ToArray()); bool[][] isDurationsEnd = StateMachineReflections.GetIsDurationsEnd(stateMachine); List <bool> isDurationEnd = new List <bool>(isDurationsEnd[creatingTransitionFromStateIndex]); isDurationEnd.Add(false); isDurationsEnd[creatingTransitionFromStateIndex] = isDurationEnd.ToArray(); StateMachineReflections.SetIsDurationsEnd(stateMachine, isDurationsEnd); Condition[][][] conditions = StateMachineReflections.GetConditions(stateMachine); List <Condition[]> stateConditions = new List <Condition[]>(conditions[creatingTransitionFromStateIndex]); stateConditions.Add(new Condition[0]); conditions[creatingTransitionFromStateIndex] = stateConditions.ToArray(); StateMachineReflections.SetConditions(stateMachine, conditions); } }