Exemplo n.º 1
0
        protected T GetUserContextData <T>(BtWorkingData workData) where T : class, new()
        {
            BtActionLeafContext actionLeafContext = GetContext <BtActionLeafContext>(workData);
            T t = actionLeafContext.GetUserData <T>();

            return(t);
        }
Exemplo n.º 2
0
        protected override int OnUpdate(BtWorkingData workData)
        {
            BtActionSequenceContext thisContext = GetContext <BtActionSequenceContext>(workData);
            int runningStatus = BtRunningStatus.FINISHED;

            BtAction node = GetChild <BtAction>(thisContext.current_selected_index);

            runningStatus = node.Update(workData);
            if (_continueIfErrorOccors == false && BtRunningStatus.IsError(runningStatus))
            {
                thisContext.current_selected_index = -1;
                return(runningStatus);
            }
            if (BtRunningStatus.IsFinished(runningStatus))
            {
                thisContext.current_selected_index++;
                if (IsIndexValid(thisContext.current_selected_index))
                {
                    runningStatus = BtRunningStatus.EXECUTING;
                }
                else
                {
                    thisContext.current_selected_index = -1;
                }
            }
            return(runningStatus);
        }
Exemplo n.º 3
0
        protected override int OnUpdate(BtWorkingData workData)
        {
            BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData);
            int runningState = BtRunningStatus.FINISHED;

            if (thisContext._currentSelectedIndex != thisContext._lastSelectedIndex)
            {
                if (IsIndexValid(thisContext._lastSelectedIndex))
                {
                    BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex);
                    node.Transition(workData);
                }
                thisContext._lastSelectedIndex = thisContext._currentSelectedIndex;
            }

            if (IsIndexValid(thisContext._lastSelectedIndex))
            {
                BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex);
                runningState = node.Update(workData);
                if (BtRunningStatus.IsFinished(runningState))
                {
                    thisContext._lastSelectedIndex = -1;
                }
            }

            return(runningState);
        }
Exemplo n.º 4
0
        public override bool IsTrue(BtWorkingData workData)
        {
            AIEntityWorkingData this_data   = workData.As <AIEntityWorkingData>();
            Vector3             target_pos  = MathHelper.Vector3ZeroY(this_data.EntityAi.GetBbValue <Vector3>(BtEntityAi.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             current_pos = MathHelper.Vector3ZeroY(this_data.EntityAi.BaseEntity.EntityController.WroldPosition);
            bool result = TMathUtils.GetDistance2D(target_pos, current_pos) < 1f;

            return(result);
        }
Exemplo n.º 5
0
        protected override void OnEnter(BtWorkingData workData)
        {
            //AIEntityWorkingData this_data = work_data.As<AIEntityWorkingData>();
            _userData = GetUserContextData <AiUserContextData>(workData);
            _userData._attackingTime = DefaultWaitingTime;
            LogManager.Log("播放攻击动画OnEnter,[{0}]", TimeModule.RealtimeSinceStartup);
            //this_data.EntityAnimator.CrossFade("attack", 0.2f);

            // 播放攻击动作
        }
Exemplo n.º 6
0
        protected override void OnTransition(BtWorkingData workData)
        {
            BtActionLeafContext leafContext = GetContext <BtActionLeafContext>(workData);

            if (leafContext._needExit)
            {
                OnExit(workData, BtRunningStatus.TRANSITION);
            }

            leafContext.ResetData();
        }
Exemplo n.º 7
0
        protected override void OnTransition(BtWorkingData workData)
        {
            BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData);
            BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex);

            if (node != null)
            {
                node.Transition(workData);
            }
            thisContext._lastSelectedIndex = -1;
        }
Exemplo n.º 8
0
        protected override void OnTransition(BtWorkingData workData)
        {
            BtActionSequenceContext this_context = GetContext <BtActionSequenceContext>(workData);
            BtAction node = GetChild <BtAction>(this_context.current_selected_index);

            if (node != null)
            {
                node.Transition(workData);
            }
            this_context.current_selected_index = -1;
        }
Exemplo n.º 9
0
        /// <summary>
        /// 根据节点的Hashcode值得到节点的ACtionContext
        /// </summary>
        protected T GetContext <T>(BtWorkingData workData) where T : BtActionContext, new()
        {
            int tmpUniqueKey = GetHashCode();
            T   t            = workData.GetContext <T>(tmpUniqueKey);

            if (t == null)
            {
                t = new T();
                workData.AddContext(tmpUniqueKey, t);
            }

            return(t);
        }
Exemplo n.º 10
0
        protected override int OnExecute(BtWorkingData workData)
        {
            AIEntityWorkingData thisData = workData.As <AIEntityWorkingData>();

            if (_userData._attackingTime > 0)
            {
                _userData._attackingTime -= thisData.DeltaTime;
                if (_userData._attackingTime < 0)
                {
                    LogManager.Log("播放攻击动画OnExecute,[{0}]", TimeModule.RealtimeSinceStartup);
                }
            }
            return(BtRunningStatus.EXECUTING);
        }
Exemplo n.º 11
0
        protected override bool OnEvaluate(BtWorkingData workData)
        {
            BtActionPrioritizedSelectorContext thisContext =
                GetContext <BtActionPrioritizedSelectorContext>(workData);

            //check last node first
            if (IsIndexValid(thisContext._currentSelectedIndex))
            {
                BtAction node = GetChild <BtAction>(thisContext._currentSelectedIndex);
                if (node.Evaluate(workData))
                {
                    return(true);
                }
            }
            return(base.OnEvaluate(workData));
        }
Exemplo n.º 12
0
        protected override bool OnEvaluate(BtWorkingData workData)
        {
            BtActionSequenceContext thisContext = GetContext <BtActionSequenceContext>(workData);
            int checkedNodeIndex = IsIndexValid(thisContext.current_selected_index) ?
                                   thisContext.current_selected_index : 0;

            if (IsIndexValid(checkedNodeIndex))
            {
                BtAction node = GetChild <BtAction>(checkedNodeIndex);
                if (node.Evaluate(workData))
                {
                    thisContext.current_selected_index = checkedNodeIndex;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 13
0
        protected override bool OnEvaluate(BtWorkingData workData)
        {
            BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData);

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

            for (int i = 0; i < childCount; i++)
            {
                BtAction node = GetChild <BtAction>(i);
                if (node.Evaluate(workData))
                {
                    thisContext._currentSelectedIndex = i;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 14
0
        protected override int OnUpdate(BtWorkingData workData)
        {
            int runningState = BtRunningStatus.FINISHED;
            BtActionLeafContext leafContext = GetContext <BtActionLeafContext>(workData);
            int currStatus = leafContext._status;

            if (currStatus == ACTION_READY)
            {
                OnEnter(workData);
                leafContext.OnEnter();
            }

            if (currStatus == ACTION_RUNNING)
            {
                runningState = OnExecute(workData);
                if (BtRunningStatus.IsFinished(runningState))
                {
                    leafContext.OnFinish();
                }
            }

            if (currStatus == ACTION_FINISHED)
            {
                if (leafContext._needExit)
                {
                    OnExit(workData, runningState);
                }
                else
                {
                    LogManager.Error("节点退出错误,[{0}]", TbName);
                }
                leafContext.OnExit();
            }

            return(runningState);
        }
Exemplo n.º 15
0
 public void Transition(BtWorkingData workData)
 {
     OnTransition(workData);
 }
Exemplo n.º 16
0
 public int Update(BtWorkingData workData)
 {
     return(OnUpdate(workData));
 }
Exemplo n.º 17
0
 public bool Evaluate(BtWorkingData workData)
 {
     return((_precondition == null || _precondition.IsTrue(workData)) && OnEvaluate(workData));
 }
Exemplo n.º 18
0
 public override bool IsTrue(BtWorkingData workData)
 {
     return(false);
 }
Exemplo n.º 19
0
 protected virtual void OnExit(BtWorkingData workData, int runningStatus)
 {
 }
Exemplo n.º 20
0
 public override bool IsTrue(BtWorkingData workData)
 {
     return(!GetFirst().IsTrue(workData));
 }
Exemplo n.º 21
0
 protected virtual int OnUpdate(BtWorkingData workData)
 {
     return(0);
 }
Exemplo n.º 22
0
 protected virtual void OnEnter(BtWorkingData workData)
 {
 }
Exemplo n.º 23
0
 public abstract bool IsTrue(BtWorkingData workData);
Exemplo n.º 24
0
 protected virtual bool OnEvaluate(BtWorkingData workData)
 {
     return(true);
 }
Exemplo n.º 25
0
 protected virtual int OnExecute(BtWorkingData workData)
 {
     return(BtRunningStatus.FINISHED);
 }
Exemplo n.º 26
0
 protected virtual void OnTransition(BtWorkingData workData)
 {
 }
Exemplo n.º 27
0
 public override bool IsTrue(BtWorkingData workData)
 {
     return(GetChild <BtPreconditionNode>(0).IsTrue(workData) ^
            GetChild <BtPreconditionNode>(1).IsTrue(workData));
 }