public void Restart() { // Init BB m_Blackboard = new Blackboard(); m_Blackboard.Trans = transform; m_Blackboard.Player = GameObject.FindGameObjectWithTag("Player").transform; m_Blackboard.Destination = transform.position + new Vector3(10, 0, 5); m_Bt = new BehaviorTree(); m_Bt.m_Blackboard = m_Blackboard; // Init tree Repeat repeat = new Repeat(ref m_Bt, -1); Sequence randomMove = new Sequence(ref m_Bt); PickRandomTarget pickTarget = new PickRandomTarget(); MoveToPoint moveBehavior = new MoveToPoint(); randomMove.m_Children.Add(moveBehavior); randomMove.m_Children.Add(pickTarget); // Try out Chase behavior m_Chase = new Chase(moveBehavior, m_Bt); m_Flee = new Flee(moveBehavior, m_Bt); repeat.m_Child = randomMove; m_Bt.Start(repeat, this.SequenceComplete); }
public void SequenceComplete(Status status) { PickRandomTarget pickTarget = new PickRandomTarget(); MoveToPoint moveBehavior = new MoveToPoint(); randomMove.m_Children.Add(moveBehavior); randomMove.m_Children.Add(pickTarget); }
public void Restart() { // Creating and setting some basic values for the blackboard m_Blackboard = new Blackboard(); m_Blackboard.Trans = transform; m_Blackboard.StartPoint = transform.position; GameObject player = GameObject.FindGameObjectWithTag("Player"); if (player) { m_Blackboard.Player = player.transform; } m_Blackboard.Destination = transform.position + new Vector3(10, 0, 5); m_Blackboard.LookAtObject = GetComponent<Looker>(); //------------------------------------------------------------------------- // Higher level sequence/selectors which we'll add leaf behaviors to later //------------------------------------------------------------------------- Sequence randomMove = new Sequence(); Sequence moveToBeacon = new Sequence(); //---------------------------------------------------------------------------------- // Create leaf behaviors. Should only need one of each. // Some of these get used often (MoveToPoint), others are specific (CheckForBeacon) //---------------------------------------------------------------------------------- MoveToPoint moveToPoint = new MoveToPoint(); PickRandomTarget pickRandomTarget = new PickRandomTarget(); CheckForBeacon checkForBeacon = new CheckForBeacon(); ChasePlayer chasePlayer = new ChasePlayer(); Stunned stunned = new Stunned(); //--------------------------------------------------------------------------------------- // Building the subtrees. // Add children to subtrees in left to right order, since each AddChild is doing a push_back //---------------------------------------------------------------------------------------- moveToBeacon.AddChild(checkForBeacon); moveToBeacon.AddChild(moveToPoint); randomMove.AddChild(pickRandomTarget); randomMove.AddChild(moveToPoint); //-------------------------------------------------- // Add subtrees to the root. // Like before, add behaviors in left to right order //-------------------------------------------------- m_Root.AddChild(stunned); m_Root.AddChild(moveToBeacon); m_Root.AddChild(chasePlayer); m_Root.AddChild(randomMove); //m_Blackboard.MovementPath = NavGraphConstructor.Instance.FindPathToLocation(m_Blackboard.Trans.position, m_Blackboard.Destination); //m_Blackboard.PathCurrentIdx = 0; // repeat.m_Child = randomMove; // // // Try out Chase behavior // m_Chase = new Chase(moveBehavior, m_Bt); // m_Flee = new Flee(moveBehavior, m_Bt); // // List<Behavior> tree = new List<Behavior>(); // tree.Add(repeat); // tree.Add(m_Chase); // // root.m_Children = tree; // // m_Bt.Start(root, this.SequenceComplete); }