override protected void Action() { if (actionSequence == null) { actionSequence = createActionSequence(); if (actionSequence == null) { return; } Agent.AddBehaviour(actionSequence); } if (actionSequence != null && actionSequence.GetState() == State.Finished) { actionSequence = null; collected++; } if (actionSequence != null && actionSequence.GetState() == State.Stopped) { actionSequence = null; } if (amount - collected == 0) { Finish(); notifyFinished(); return; } }
private void ConstructBehaviourTree() { /* Constructing the full behaviour tree, * first it checks if the player is powered, if so it will flee from the player * if not it checks if the player is in range, if so chase towards the player * if it is also not in range of the player it patrols to somewhere on the map * if there are only a few pills left it is enraged and chases the player even faster */ // Constructing the bottom tier nodes ChaseNode chaseNode = new ChaseNode(blackboard, agent, chasingSpeed); RangeNode rangeNode = new RangeNode(spotPlayerRange, blackboard, this.transform); PatrolNode patrolNode = new PatrolNode(this, agent, blackboard, patrollingSpeed, enragedSpeed, pillsRemainingToEnraged); FleeNode fleeNode = new FleeNode(blackboard, agent, this.transform, fleeingSpeed); IsPlayerImortalNode IsPlayerImortalNode = new IsPlayerImortalNode(this); // Constructing the middle tier nodes SequenceBehaviour fleeSequence = new SequenceBehaviour(new List <Node> { IsPlayerImortalNode, fleeNode }); SequenceBehaviour chaseSequence = new SequenceBehaviour(new List <Node> { rangeNode, chaseNode }); // Constructing the top tier node topNode = new SelectorBehaviour(new List <Node> { fleeSequence, chaseSequence, patrolNode }); }
public SequenceContext(SequenceBehaviour sequence, TrackBehaviour[] tracks, IReadOnlyList <Blackboard> blackboards) { SetState(SequenceStatus.Stoppped); m_Sequence = sequence; m_TrackContexts = new TrackContext[tracks.Length]; for (int i = 0; i < m_TrackContexts.Length; i++) { m_TrackContexts[i] = tracks[i].CreateContext(sequence.FrameRate, sequence, blackboards); } }
private SequenceBehaviour createActionSequence() { SequenceBehaviour actionSequence = new SequenceBehaviour(Agent); Rigidbody rigidbody = gameObject.GetComponent(typeof(Rigidbody)) as Rigidbody; WoodComponent nearestWoodComponent = getNearestWoodComponent(rigidbody.transform.position); if (nearestWoodComponent == null) { Stop(); notifyFinished(); return(null); } StorageComponent storageComponent = getNearestStorageComponent(nearestWoodComponent.transform.position); if (storageComponent == null) { Stop(); notifyFinished(); return(null); } BackpackComponent backpackComponent = gameObject.GetComponent(typeof(BackpackComponent)) as BackpackComponent; if (backpackComponent == null) { Stop(); notifyFinished(); return(null); } MoveTowardsBehaviour moveTowardsStorageBehaviour = new MoveTowardsBehaviour(Agent, rigidbody, speed, storageComponent.transform.position); PutMaterialsIntoStorageBehaviour putMaterialsIntoStorageBehaviour = new PutMaterialsIntoStorageBehaviour(Agent, storageComponent, backpackComponent); if (!backpackComponent.hasWood) { MoveTowardsBehaviour moveTowardsWoodBehaviour = new MoveTowardsBehaviour(Agent, rigidbody, speed, nearestWoodComponent.transform.position); GatherWoodBehaviour gatherWoodBehaviour = new GatherWoodBehaviour(Agent, backpackComponent, nearestWoodComponent); actionSequence.AddSequentialBehaviour(moveTowardsWoodBehaviour); actionSequence.AddSequentialBehaviour(gatherWoodBehaviour); } actionSequence.AddSequentialBehaviour(moveTowardsStorageBehaviour); actionSequence.AddSequentialBehaviour(putMaterialsIntoStorageBehaviour); return(actionSequence); }
public SequenceContext Prepare(SequenceBehaviour sequence = null, TickMode mode = TickMode.Auto) { m_Mode = mode; if (m_Context != null) { m_Context.Dispose(); m_Context = null; } if (sequence != null) { m_Sequence = sequence; } if (m_Sequence == null) { return(null); } m_Context = m_Sequence.CreateContext(Blackboard); return(m_Context); }
public ClipContext(ClipBehaviour clip, float frameRate, SequenceBehaviour sequence, IReadOnlyList <Blackboard> blackboards) { m_Clip = clip; m_Clip.OnCreate(sequence, blackboards); m_FrameRate = frameRate; }
public TrackContext(TrackBehaviour track, ClipBehaviour[] clips, float frameRate, SequenceBehaviour sequence, IReadOnlyList <Blackboard> blackboards) { m_CurrentTime = -1f; m_Track = track; m_Track.OnCreate(sequence, blackboards); m_ClipContexts = new ClipContext[clips.Length]; for (int i = 0; i < m_ClipContexts.Length; i++) { m_ClipContexts[i] = clips[i].CreateContext(frameRate, sequence, blackboards); } }
public PlayableSequenceContext(SequenceBehaviour sequence, TrackBehaviour[] tracks, IReadOnlyList <Blackboard> blackboards) : base(sequence, tracks, blackboards) { }