示例#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
        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);
        }