コード例 #1
0
ファイル: Sequencer.cs プロジェクト: ndp1100/BehaviorTreeYOLO
        protected override BehaviorTree.ResultCode OnAct(Actor actor, Blackboard local)
        {
            int executing = 0;

            if (!local.GetValue <int>(INDEX_FIELD_NAME, out executing))
            {
                return(BehaviorTree.ResultCode.Error);
            }

            if (Children.Count <= executing)
            {
                return(BehaviorTree.ResultCode.Error);
            }

            BehaviorTree.ResultCode result = BehaviorTree.ResultCode.Success;

            while (result == BehaviorTree.ResultCode.Success && executing < Children.Count)

            {
                result = Children[executing].Act(actor);

                if (m_continueOnFail && result == BehaviorTree.ResultCode.Failure)
                {
                    result = BehaviorTree.ResultCode.Success;
                }

                if (result == BehaviorTree.ResultCode.Success)
                {
                    executing++;
                    local.SetValue <int>(INDEX_FIELD_NAME, executing);
                }
            }

            return(result);
        }
コード例 #2
0
        public BehaviorTree.ResultCode Act(Actor actor)
        {
            Blackboard local = actor.Blackboards.GetBlackboard(this);

            BehaviorTree.ResultCode result = BehaviorTree.ResultCode.Error;

            bool running;
            bool runningExists;

            runningExists = local.GetValue <bool>(RUNNING_STATUS_FIELD_NAME, out running);

            if (!running || !runningExists)
            {
                OnEnter(actor, local);
            }

            result = OnAct(actor, local);

            if (result == BehaviorTree.ResultCode.Running)
            {
                local.SetValue <bool>(RUNNING_STATUS_FIELD_NAME, true);
            }
            else
            {
                local.SetValue <bool>(RUNNING_STATUS_FIELD_NAME, false);
                OnExit(actor, local);
            }

            return(result);
        }
コード例 #3
0
ファイル: Actor.cs プロジェクト: Ralph-sa/UnityBehaviorTrees
        protected virtual void Update()
        {
            if ( Behavior != null )
            {
                if ( Blackboards == null )
                {
                    Blackboards = new BlackboardCache();
                }

                if ( Result == BehaviorTree.ResultCode.Running )
                {
                    Result = Behavior.Act( this );
                }
            }
        }
コード例 #4
0
        protected virtual void Update()
        {
            if (Behavior != null)
            {
                if (Blackboards == null)
                {
                    Blackboards = new BlackboardCache();
                }

                if (Result == BehaviorTree.ResultCode.Running)
                {
                    Result = Behavior.Act(this);
                }
            }
        }
コード例 #5
0
ファイル: Repeater.cs プロジェクト: ndp1100/BehaviorTreeYOLO
        protected override BehaviorTree.ResultCode OnAct(Actor actor, Blackboard local)
        {
            if (Children.Count < 1)
            {
                return(BehaviorTree.ResultCode.Error);
            }

            BehaviorTree.ResultCode result = Children[0].Act(actor);

            switch (result)
            {
            default:
            case BehaviorTree.ResultCode.Running:
            case BehaviorTree.ResultCode.Error:
                return(result);

            case BehaviorTree.ResultCode.Success:
            case BehaviorTree.ResultCode.Failure:
                if (m_stopOnFail && result == BehaviorTree.ResultCode.Failure)
                {
                    return(BehaviorTree.ResultCode.Success);
                }

                int repeated = 0;

                if (!local.GetValue <int>(COUNTER_FIELD_NAME, out repeated))
                {
                    repeated = 0;
                }

                repeated++;
                local.SetValue <int>(COUNTER_FIELD_NAME, repeated);

                if (repeated < m_repeatCount || m_repeatCount <= 0)
                {
                    return(BehaviorTree.ResultCode.Running);
                }

                return(BehaviorTree.ResultCode.Success);
            }
        }
コード例 #6
0
ファイル: Inverter.cs プロジェクト: ndp1100/BehaviorTreeYOLO
        protected override BehaviorTree.ResultCode OnAct(Actor actor, Blackboard local)
        {
            if (Children.Count < 1)
            {
                return(BehaviorTree.ResultCode.Error);
            }

            BehaviorTree.ResultCode result = Children[0].Act(actor);

            switch (result)
            {
            default:
            case BehaviorTree.ResultCode.Running:
            case BehaviorTree.ResultCode.Error:
                return(result);

            case BehaviorTree.ResultCode.Success:
                return(BehaviorTree.ResultCode.Failure);

            case BehaviorTree.ResultCode.Failure:
                return(BehaviorTree.ResultCode.Success);
            }
        }
コード例 #7
0
ファイル: Actor.cs プロジェクト: Ralph-sa/UnityBehaviorTrees
 public void Execute( string behavior )
 {
     Behavior = BehaviorCache.GetBehavior( behavior );
     Result = BehaviorTree.ResultCode.Running;
 }
コード例 #8
0
 public void Execute(string behavior)
 {
     Behavior = BehaviorCache.GetBehavior(behavior);
     Result   = BehaviorTree.ResultCode.Running;
 }