Example #1
0
 public virtual bool TryGetLayerTypeAction(EGuideActionLayerType _eLayerType, out TBTAction _selector)
 {
     for (int i = 0; i < GetChildCount(); ++i)
     {
         _selector = GetChild <TBTAction>(i);
         if (_selector != null)
         {
             if (_eLayerType == EGuideActionLayerType.Sequence && _selector is TBTActionSequence)
             {
                 return(true);
             }
             else if (_eLayerType == EGuideActionLayerType.Parallel && _selector is TBTActionParallel)
             {
                 return(true);
             }
             else if (_eLayerType == EGuideActionLayerType.Selector && _selector is TBTActionPrioritizedSelector)
             {
                 return(true);
             }
             else if (_eLayerType == EGuideActionLayerType.LogicSequence && _selector is GuideLogicSequence)
             {
                 return(true);
             }
         }
     }
     _selector = null;
     return(false);
 }
Example #2
0
        static public TBTAction GetBehaviorTreeAction()
        {
            if (_bevTreeAct != null)
            {
                return(_bevTreeAct);
            }
            _bevTreeAct = new TBTActionPrioritizedSelector();
//			_bevTreeAct.AddChild(new TBTActionSequence()
//                    .SetPrecondition(new TBTPreconditionNOT(new CON_HasReachedTarget()))
//                    .AddChild(new NOD_TurnTo())
//                    .AddChild(new NOD_MoveTo()))
//                .AddChild(new NOD_Attack());

            TBTActionSequence actionSequence = new TBTActionSequence();

            _bevTreeAct.AddChild(actionSequence);

            CON_HasReachedTarget hasReachedTarget = new CON_HasReachedTarget();
            TBTPreconditionNOT   preconditionNOT  = new TBTPreconditionNOT(hasReachedTarget);

            actionSequence.SetPrecondition(preconditionNOT);


            NOD_TurnTo turnTo   = new NOD_TurnTo();
            NOD_MoveTo moveTo   = new NOD_MoveTo();
            NOD_Attack attackTo = new NOD_Attack();

            actionSequence.AddChild(turnTo);
            actionSequence.AddChild(moveTo);
            actionSequence.AddChild(attackTo);



            return(_bevTreeAct);
        }
Example #3
0
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            UpdateLogicData(wData);

            GuideRoot_01Context thisContext = getContext <GuideRoot_01Context>(wData);
            int checkedNodeIndex            = -1;

            if (IsIndexValid(thisContext.currentSelectedIndex))
            {
                checkedNodeIndex = thisContext.currentSelectedIndex;
            }
            else
            {
                checkedNodeIndex = 0;
            }
            if (IsIndexValid(checkedNodeIndex))
            {
                TBTAction node = GetChild <TBTAction>(checkedNodeIndex);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = checkedNodeIndex;
                    return(true);
                }
            }
            return(false);
        }
Example #4
0
        protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);
            int runningState = TBTRunningStatus.FINISHED;

            if (thisContext.currentSelectedIndex != thisContext.lastSelectedIndex)
            {
                if (IsIndexValid(thisContext.lastSelectedIndex))
                {
                    TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex);
                    node.Transition(wData);
                }
                thisContext.lastSelectedIndex = thisContext.currentSelectedIndex;
            }
            if (IsIndexValid(thisContext.lastSelectedIndex))
            {
                TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex);
                runningState = node.Update(wData);
                if (TBTRunningStatus.IsFinished(runningState))
                {
                    node.Transition(wData);
                    thisContext.lastSelectedIndex = -1;
                }
            }
            return(runningState);
        }
Example #5
0
 public override void ClearData()
 {
     _BevTree        = null;
     _BevWorkingData = null;
     _PathUtil.ClearData();
     base.ClearData();
 }
Example #6
0
        protected override void onTransition(TBTWorkingData wData)
        {
            GuideRoot_01Context thisContext = getContext <GuideRoot_01Context>(wData);
            TBTAction           node        = GetChild <TBTAction>(thisContext.currentSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }
        }
Example #7
0
        protected override void onTransition(TBTWorkingData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);
            TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }
            thisContext.lastSelectedIndex = -1;
        }
Example #8
0
    public override void SetData(PlayerInfo data, int initBodyLength)
    {
        _BevTree                   = BotFactory.GetBehaviourTree();
        _BevWorkingData            = new BotWorkingData();
        _BevWorkingData._Character = this;
        base.SetData(data, initBodyLength);

        _PathUtil = this.gameObject.AddComponent <BotAStar>();
        _PathUtil.SetData(this);
        _PlayerCamera.SetData(_Head.transform);
    }
 protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
 {
     TBTActionPrioritizedSelector.TBTActionPrioritizedSelectorContext thisContext =
         getContext <TBTActionPrioritizedSelector.TBTActionPrioritizedSelectorContext>(wData);
     //check last node first
     if (IsIndexValid(thisContext.currentSelectedIndex))
     {
         TBTAction node = GetChild <TBTAction>(thisContext.currentSelectedIndex);
         if (node.Evaluate(wData))
         {
             return(true);
         }
     }
     return(base.onEvaluate(wData));
 }
Example #10
0
        protected override int onUpdate(TBTWorkingData wData)
        {
            GuideRoot_01Context thisContext = getContext <GuideRoot_01Context>(wData);
            int       runningStatus         = TBTRunningStatus.FINISHED;
            TBTAction node = GetChild <TBTAction>(thisContext.currentSelectedIndex);

            runningStatus = node.Update(wData);
            if (_continueIfErrorOccors == false && TBTRunningStatus.IsError(runningStatus))
            {
                thisContext.currentSelectedIndex = -1;
                return(runningStatus);
            }

            return(runningStatus);
        }
Example #11
0
        private void Awake()
        {
            _behaviorWorkingData = new AIEntityWorkingData();
            _behaviorWorkingData.entityAnimator = GetComponent <Animator>();
            _behaviorWorkingData.entityTF       = transform;

            _behaviorTree = new TBTActionPrioritizedSelector();
            _behaviorTree
            .AddChild(new TBTActionSequence()
                      .SetPrecondition(new TBTPreconditionNOT(new HasReachedTarget()))
                      .AddChild(new TurnToAction())
                      .AddChild(new MoveToAction()))
            .AddChild(new TBTActionParallel()
                      .AddChild(new TurnToAction())
                      .AddChild(new AttackAction()));
        }
Example #12
0
        private void Awake()
        {
            _behaviorWorkingData = new AIEntityWorkingData();
            _behaviorWorkingData.entityAnimation = GetComponent <Animation>();
            _behaviorWorkingData.entityTF        = transform;

            _behaviorTree = new TBTActionPrioritizedSelector();
            _behaviorTree
            .AddChild(new TBTActionSequence()
                      .SetPrecondition(new TBTPreconditionNOT(new HasReachEnemy()))
                      .AddChild(new LookEnemyAction())
                      .AddChild(new IdleAction()))
            .AddChild(new TBTActionParallel()
                      .AddChild(new LookEnemyAction())
                      .AddChild(new AttackAction()));
        }
Example #13
0
    public BattleUnit(int id, BattleCamp battleCamp, BattleProperty property) : base(id)
    {
        property.id    = id;
        camp           = battleCamp;
        m_Property     = property;
        abilities      = new List <Ability>();
        m_abilityMap   = new Dictionary <AbilityCastType, Ability>(4);
        m_HeroState    = HeroState.IDLE;
        m_BehaviorTree = GetBehaviorTree();
        m_DecisionTree = GetDecisionTree();

        m_DecisionWorkData = new BattleDecisionWorkingData(this);
        m_BehaviorWorkData = new BattleBehaviorWorkingData(this);

        InitAbilities();
    }
 static public TBTAction GetBehaviorTreeDemo1()
 {
     if (_bevTreeDemo1 != null)
     {
         return(_bevTreeDemo1);
     }
     _bevTreeDemo1 = new TBTActionPrioritizedSelector();
     _bevTreeDemo1
     .AddChild(new TBTActionSequence()
               .SetPrecondition(new TBTPreconditionNOT(new CON_HasReachedTarget()))
               .AddChild(new NOD_TurnTo())
               .AddChild(new NOD_MoveTo()))
     .AddChild(new TBTActionSequence()
               .AddChild(new NOD_TurnTo())
               .AddChild(new NOD_Attack()));
     return(_bevTreeDemo1);
 }
Example #15
0
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);

            thisContext.currentSelectedIndex = -1;
            int childCount = GetChildCount();

            for (int i = 0; i < childCount; ++i)
            {
                TBTAction node = GetChild <TBTAction>(i);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = i;
                    return(true);
                }
            }
            return(false);
        }
Example #16
0
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            GuideWorkingData gWData      = wData as GuideWorkingData;
            EStage_State     tmpCurState = EStage_State.ESS_NONE;
            int tmpNoviceID = -1;

            if (gWData != null)
            {
                tmpCurState = gWData.GuideStateBB.GetValue <EStage_State>(EGuideStateBBKey.GameStageState, EStage_State.ESS_NONE);
                tmpNoviceID = gWData.GuideStateBB.GetValue <int>(EGuideStateBBKey.PlayerNoviceGuideType, -1);
            }

            if (m_eOldStage != EStage_State.ESS_NONE && m_eOldStage != tmpCurState)
            {
                GuideManager.Instance.DestroyOldDynamicGuideRoot(wData);
            }
            else if (m_eOldStage != EStage_State.ESS_NONE && m_eOldStage == tmpCurState)
            {
                if (tmpNoviceID != -1 && tmpNoviceID != m_nNoviceID)
                {
                    GuideManager.Instance.DestroyOldDynamicGuideRoot(wData);
                }
            }
            m_eOldStage = tmpCurState;
            m_nNoviceID = tmpNoviceID;


            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);

            thisContext.currentSelectedIndex = -1;
            int childCount = GetChildCount();

            for (int i = 0; i < childCount; ++i)
            {
                TBTAction node = GetChild <TBTAction>(i);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = i;
                    return(true);
                }
            }
            return(false);
        }
Example #17
0
        public AIEntity Init()
        {
            _behaviorTree = AIEntityBehaviourTreeFactory.GetBehaviourTreeDemo();

            _behaviorWorkingData                = new AIEntityWorkingData();
            _behaviorWorkingData.entity         = this;
            _behaviorWorkingData.entityTF       = this.transform;
            _behaviorWorkingData.entityAnimator = GetComponent <Animator>();

            _blackboard = new TBlackBoard();

            _nextTimeToGenMovingTarget = 0f;
            _lastTriggeredAnimation    = string.Empty;

            _isDead = false;

            _targetDummyObject = GameResourceManager.Instance.LoadResource("AttackTarget");

            return(this);
        }
Example #18
0
        public AIEntity Init(GameObject targetObj)
        {
            _behaviorTree = AIEntityBehaviorTreeFactory.GetBehaviorTreeAction();

            _behaviorWorkingData                = new AIEntityWorkingData();
            _behaviorWorkingData.entity         = this;
            _behaviorWorkingData.entityTF       = this.transform;
            _behaviorWorkingData.entityAnimator = GetComponent <Animator>();

            _blackboard = new TBlackBoard();

            _nextTimeToGenMovingTarget = 0;

            _targetDummyObject = targetObj;

            _navagent = GetComponent <UnityEngine.AI.NavMeshAgent>();


            return(this);
        }
Example #19
0
        public void CreateNewDynamicGuideRoot(TBTWorkingData wData)
        {
            if (m_GuideDynamicRoot == null)
            {
                GuideWorkingData data = wData as GuideWorkingData;
                if (data != null && data.GuideDynamicBB != null)
                {
                    int GuideStateID = data.GuideStateBB.GetValue <int>(EGuideStateBBKey.GuideStateID, -1);
                    SSchemeGuideStateData stateData = GetGuideStateData(GuideStateID);
                    if (stateData != null)
                    {
                        m_GuideDynamicRoot = CreateDynamicRoot(stateData.GuideRootType);


                        for (int j = 0; j < stateData.GuideNodeIDList.Count; ++j)
                        {
                            EGuideNodeID         guideNodeID   = (EGuideNodeID)stateData.GuideNodeIDList[j];
                            SSchemeGuideNodeData guideNodeData = null;
                            if (dicGuideConfigTable.TryGetValue(guideNodeID, out guideNodeData))
                            {
                                //先根据引导节点需要挂接的父节点类型处理
                                EGuideActionLayerType layerType       = (EGuideActionLayerType)guideNodeData.nGuideActionLayerType;
                                TBTAction             layerTypeAction = null;
                                if (!m_GuideDynamicRoot.TryGetLayerTypeAction(layerType, out layerTypeAction))
                                {
                                    layerTypeAction = CreateLayerTypeAction(layerType);
                                    m_GuideDynamicRoot.AddChild(layerTypeAction);
                                }

                                layerTypeAction.AddChild(getNodeDataInstance(guideNodeID));
                            }
                            else
                            {
                                Trace.LogWarning("没有引导ID为:" + guideNodeID + " 的引导数据,配错了?");
                            }
                        }
                    }
                }
            }
        }