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);
        }
Example #2
0
        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);
        }
Example #3
0
        protected override void OnEnter(Actor actor, Blackboard local)
        {
            if (m_random)
            {
                // Shuffle children
                Children.Sort((a, b) => { return(Random.Range(-1, 3)); });
            }

            local.SetValue <int>(INDEX_FIELD_NAME, 0);
        }
Example #4
0
 protected override BehaviorTree.ResultCode OnAct(Actor actor, Blackboard local)
 {
     if (m_DoorOB != null)
     {
         Blackboard treeBlackboard = actor.Blackboards.GetBlackboard(actor.Behavior);
         treeBlackboard.SetValue("DoorOB", m_DoorOB);
         return(BehaviorTree.ResultCode.Success);
     }
     else
     {
         return(BehaviorTree.ResultCode.Failure);
     }
 }
Example #5
0
        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);
            }
        }
Example #6
0
 protected override void OnEnter(Actor actor, Blackboard local)
 {
     local.SetValue <int>(INDEX_FIELD_NAME, 0);
 }
Example #7
0
        protected override void OnEnter(Actor actor, Blackboard local)
        {
            float t = m_useRealtime ? Time.realtimeSinceStartup : Time.time;

            local.SetValue <float>(START_TIME_FIELD_NAME, t);
        }