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;
        }
Exemplo n.º 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.Failure;

            while ( result == BehaviorTree.ResultCode.Failure && executing < Children.Count )
            {
                result = Children[ executing ].Act( actor );

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

            return result;
        }
Exemplo n.º 3
0
 protected override void OnEnter( Actor actor, Blackboard local )
 {
     if ( m_subtree == null )
     {
         m_subtree = BehaviorCache.GetBehavior( m_id );
     }
 }
Exemplo n.º 4
0
        protected override BehaviorTree.ResultCode OnAct( Actor actor, Blackboard local )
        {
            if ( m_success )
            {
                return BehaviorTree.ResultCode.Success;
            }

            return BehaviorTree.ResultCode.Failure;
        }
Exemplo n.º 5
0
        public ResultCode Act( Actor actor )
        {
            if ( m_rootNode != null )
            {
                return m_rootNode.Act( actor );
            }

            return ResultCode.Error;
        }
Exemplo n.º 6
0
        protected override BehaviorTree.ResultCode OnAct( Actor actor, Blackboard local )
        {
            if ( m_subtree == null )
            {
                return BehaviorTree.ResultCode.Failure;
            }

            return m_subtree.Act( actor );
        }
Exemplo n.º 7
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 );
        }
Exemplo n.º 8
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;
            }
        }
Exemplo n.º 9
0
        protected override BehaviorTree.ResultCode OnAct( Actor actor, Blackboard local )
        {
            float t = 0.0f; 
            
            if ( !local.GetValue< float >( START_TIME_FIELD_NAME, out t ) )
            {
                return BehaviorTree.ResultCode.Error;
            }

            if ( m_useRealtime && ( Time.realtimeSinceStartup - t ) < m_duration )
            {
                return BehaviorTree.ResultCode.Running;
            }

            if ( !m_useRealtime && ( Time.time - t ) < m_duration )
            {
                return BehaviorTree.ResultCode.Running;
            }

            return BehaviorTree.ResultCode.Success;
        }
Exemplo n.º 10
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:
                    return BehaviorTree.ResultCode.Failure;

                case BehaviorTree.ResultCode.Failure:
                    return BehaviorTree.ResultCode.Success;
            }
        }
Exemplo n.º 11
0
 protected override void OnExit( Actor actor, Blackboard local )
 {            
 }
Exemplo n.º 12
0
 protected abstract void                     OnExit( Actor actor, Blackboard local );
Exemplo n.º 13
0
 protected abstract BehaviorTree.ResultCode  OnAct( Actor actor, Blackboard local );
Exemplo n.º 14
0
 protected override void OnEnter( Actor actor, Blackboard local )
 {
     local.SetValue< int >( COUNTER_FIELD_NAME, 0 );
 }
Exemplo n.º 15
0
 protected override BehaviorTree.ResultCode OnAct( Actor actor, Blackboard local )
 {
     Debug.Log( m_message );
     return BehaviorTree.ResultCode.Success;
 }
Exemplo n.º 16
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 );
 }