/// <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 transition between one <see cref="BehaviourTreeEngine"/>, the submachine; and another <see cref="BehaviourTreeEngine"/>, the supermachine. /// </summary> /// <param name="name">The name of the transition</param> /// <param name="nodeFrom">The exit node of the transition</param> /// <param name="stateTo">The node where the Behaviour tree is coming back</param> /// <param name="superMachine">The supermachine</param> /// <param name="subMachine">The submachine</param> public Transition(string name, TreeNode nodeFrom, LeafNode stateTo, BehaviourTreeEngine superMachine, BehaviourTreeEngine subMachine) { this.Name = name; this.StateFrom = nodeFrom.StateNode; this.StateTo = stateTo.StateNode; this.Perception = new OrPerception(new BehaviourTreeStatusPerception(subMachine, ReturnValues.Succeed, subMachine), new BehaviourTreeStatusPerception(subMachine, ReturnValues.Failed, subMachine), subMachine); 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.GetRootNode().ReturnValue, 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.GetRootNode().ReturnValue, subMachine.GetState("Entry_Machine"), superMachine, subMachine)); } }
/// <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(); }); }
public void SetTransitionType(TRANSITION_TYPE transitionType) { m_transitionType = transitionType; }