/// <summary> /// Creates a transition between two <see cref="BehaviourEngine"/>, one is the submachine the other the supermachine /// </summary> /// <param name="name">The name of the transition</param> /// <param name="stateFrom">The exit state of the transition</param> /// <param name="perception">The perception that activates the transition</param> /// <param name="stateTo">the entry state of the transition</param> /// <param name="superMachine">The supermachine</param> /// <param name="subMachine">The submachine</param> public Transition(string name, State stateFrom, Perception perception, State stateTo, BehaviourEngine superMachine, BehaviourEngine subMachine) { this.Name = name; this.StateFrom = stateFrom; this.Perception = perception; this.StateTo = stateTo; this.type = TRANSITION_TYPE.SUPER_TRANSITION; if (stateFrom.BehaviourEngine == superMachine) // Exits from the super-machine { this.BehaviourEngine = superMachine; Perception.SetBehaviourMachine(superMachine); superMachine.Configure(StateFrom) .OnExit(this.Name, () => Perception.Reset()) .InternalTransition(Perception, this.Name, () => ExitTransition(StateFrom, StateTo, subMachine.GetState("Entry_Machine"), superMachine, subMachine)); } else // Exits from the sub-machine { this.BehaviourEngine = subMachine; Perception.SetBehaviourMachine(subMachine); subMachine.Configure(StateFrom) .OnExit(this.Name, () => Perception.Reset()) .InternalTransition(Perception, this.Name, () => ExitTransition(StateFrom, StateTo, subMachine.GetState("Entry_Machine"), superMachine, subMachine)); } }
/// <summary> /// Creates a state with a sub-machine in it /// </summary> /// <param name="stateName">The name of the state</param> /// <param name="subStateMachine">The sub-state machine that the state has</param> /// <param name="entryState">The entry state of the submachine</param> /// <param name="stateMachineB">The state machine which the state belongs to</param> public State(string stateName, State entrySubMachineState, State stateTo, BehaviourEngine subMachine, BehaviourEngine behaviourEngine) { this.Name = stateName; this.BehaviourEngine = behaviourEngine; this.configurator = new StateConfigurator(StateConfigurator.STATE_TYPE.NOT_EMPTY); BehaviourEngine.Configure(this) .OnEntry(() => EntrySubmachine(entrySubMachineState, stateTo, subMachine, behaviourEngine)); }
/// <summary> /// State that runs a method with no parameters /// </summary> /// <param name="stateName">Name of the state</param> /// <param name="method">Method with no parameters. MUST be a void method</param> /// <param name="behaviourEngine">The machine which the state belongs to</param> public State(string stateName, Action method, BehaviourEngine behaviourEngine) { this.Name = stateName; this.StateActionVoid = method; this.BehaviourEngine = behaviourEngine; this.configurator = new StateConfigurator(StateConfigurator.STATE_TYPE.NOT_EMPTY); BehaviourEngine.Configure(this) .OnEntry(() => method()); }
/// <summary> /// State that runs a method with a <see cref="Perception"/> parameter /// </summary> /// <param name="stateName">Name of the state</param> /// <param name="method">Method with no parameters. MUST be a void method</param> /// <param name="behaviourEngine">The machine which the state belongs to</param> public State(string stateName, Action <Perception> method, BehaviourEngine behaviourEngine) { this.Name = stateName; this.StateActionPerception = method; this.StatePerception = (Perception)method.Method.GetParameters().GetValue(0); this.BehaviourEngine = behaviourEngine; this.configurator = new StateConfigurator(StateConfigurator.STATE_TYPE.NOT_EMPTY); BehaviourEngine.Configure(this) .OnEntry(() => method((Perception)method.Method.GetParameters().GetValue(0))); }
/// <summary> /// Creates a transition between states from a <see cref="BehaviourStateMachine"/> /// </summary> /// <param name="name">The name of the transition</param> /// <param name="stateFrom">The exit state of the transition</param> /// <param name="perception">The perception that activates the transition</param> /// <param name="stateTo">The entry state of the transition</param> /// <param name="behaviourEngine">The machine the transitions belongs to</param> public Transition(string name, State stateFrom, Perception perception, State stateTo, BehaviourEngine behaviourEngine) { this.Name = name; this.StateFrom = stateFrom; this.Perception = perception; this.StateTo = stateTo; this.BehaviourEngine = behaviourEngine; this.type = TRANSITION_TYPE.NORMAL; BehaviourEngine.Configure(StateFrom) .OnExit(this.Name, () => { Perception.Reset(); }); }