예제 #1
0
        private void AggressiveAIMelee()
        {
            ScanForObjectsNode  = new CandiceBehaviorAction(CandiceDefaultBehaviors.ScanForObjects, rootNode);
            AvoidObstaclesNode  = new CandiceBehaviorAction(CandiceDefaultBehaviors.AvoidObstacles, rootNode);
            CandicePathfindNode = new CandiceBehaviorAction(CandiceDefaultBehaviors.CandicePathfind, rootNode);
            canSeeEnemyNode     = new CandiceBehaviorAction(CandiceDefaultBehaviors.EnemyDetected, rootNode);
            lookAtNode          = new CandiceBehaviorAction(CandiceDefaultBehaviors.LookAt, rootNode);
            attackNode          = new CandiceBehaviorAction(CandiceDefaultBehaviors.AttackMelee, rootNode);
            rangeAttackNode     = new CandiceBehaviorAction(CandiceDefaultBehaviors.AttackRange, rootNode);
            moveNode            = new CandiceBehaviorAction(CandiceDefaultBehaviors.MoveForwardWithSlopeAlignment, rootNode);
            withinAttackRange   = new CandiceBehaviorAction(CandiceDefaultBehaviors.WithinAttackRange, rootNode);


            attackSequence = new CandiceBehaviorSequence();
            attackSequence.SetNodes(new List <CandiceBehaviorNode> {
                withinAttackRange, lookAtNode, attackNode
            });
            followSequence = new CandiceBehaviorSequence();
            followSequence.SetNodes(new List <CandiceBehaviorNode> { /*AvoidObstaclesNode*/
                lookAtNode, moveNode
            });
            attackOrChaseSelector = new CandiceBehaviorSelector();
            attackOrChaseSelector.SetNodes(new List <CandiceBehaviorNode> {
                attackSequence, followSequence
            });
            rootNode.SetNodes(new List <CandiceBehaviorNode> {
                ScanForObjectsNode, canSeeEnemyNode, attackOrChaseSelector
            });
        }
예제 #2
0
        // Start is called before the first frame update
        void Start()
        {
            aiController = GetComponent <CandiceAIController>();
            rootNode     = new CandiceBehaviorSequence();
            rootNode.Initialise(transform, aiController);

            /*
             * Uncomment to test out the different behaviours.
             * Remember, you can only have one of these functions running at a time.
             */
            AggressiveAIMelee();
            //AggressiveAIRanged();
            //WanderAI();
            //CowardAI();
        }
예제 #3
0
        private void WanderAI()
        {
            ScanForObjectsNode  = new CandiceBehaviorAction(CandiceDefaultBehaviors.ScanForObjects, rootNode);
            AvoidObstaclesNode  = new CandiceBehaviorAction(CandiceDefaultBehaviors.AvoidObstacles, rootNode);
            CandicePathfindNode = new CandiceBehaviorAction(CandiceDefaultBehaviors.CandicePathfind, rootNode);
            canSeeEnemyNode     = new CandiceBehaviorAction(CandiceDefaultBehaviors.EnemyDetected, rootNode);
            lookAtNode          = new CandiceBehaviorAction(CandiceDefaultBehaviors.LookAt, rootNode);
            attackNode          = new CandiceBehaviorAction(CandiceDefaultBehaviors.AttackMelee, rootNode);
            rangeAttackNode     = new CandiceBehaviorAction(CandiceDefaultBehaviors.AttackRange, rootNode);
            moveNode            = new CandiceBehaviorAction(CandiceDefaultBehaviors.MoveForward, rootNode);
            withinAttackRange   = new CandiceBehaviorAction(CandiceDefaultBehaviors.WithinAttackRange, rootNode);
            wanderNode          = new CandiceBehaviorAction(CandiceDefaultBehaviors.Wander, rootNode);

            wanderSequence = new CandiceBehaviorSequence();
            wanderSequence.SetNodes(new List <CandiceBehaviorNode> {
                wanderNode, AvoidObstaclesNode, moveNode
            });
            rootNode.SetNodes(new List <CandiceBehaviorNode> {
                wanderSequence
            });
        }
예제 #4
0
        List <CandiceBehaviorNode> GetChildren(CandiceBehaviorTreeS bt, CandiceBehaviorNodeS node)
        {
            List <CandiceBehaviorNode> children = new List <CandiceBehaviorNode>();
            CandiceBehaviorNodeS       _node    = null;

            if (node.childrenIDs.Count < 1)
            {
                return(children);
            }
            foreach (int id in node.childrenIDs)
            {
                CandiceBehaviorNode newNode = null;
                Debug.LogError("ID: " + id);
                if (GetNodeWithID(id, bt.GetNodes()) != null)
                {
                    _node = GetNodeWithID(id, nodes);

                    switch (_node.type)
                    {
                    case CandiceAIManager.NODE_TYPE_SELECTOR:
                        newNode = new CandiceBehaviorSelector();
                        (newNode as CandiceBehaviorSelector).SetNodes(GetChildren(bt, _node));
                        break;

                    case CandiceAIManager.NODE_TYPE_SEQUENCE:
                        newNode = new CandiceBehaviorSequence();
                        (newNode as CandiceBehaviorSequence).SetNodes(GetChildren(bt, _node));
                        break;

                    case CandiceAIManager.NODE_TYPE_ACTION:
                        CandiceBehaviorAction action = new CandiceBehaviorAction((CandiceBehaviorAction.ActionNodeDelegate)lstFunctions[_node.function].CreateDelegate(typeof(CandiceBehaviorAction.ActionNodeDelegate)), rootNode);
                        newNode = action;
                        break;
                    }
                    children.Add(newNode);
                }
            }
            return(children);
        }