Ejemplo n.º 1
0
        protected virtual void OnEnable()
        {
            Debug.Assert(BaseState >= 0, this.name + " did not have a base state ID. CRASH LOUDLY");

            _currentState = _availiableStates.Count >= 1 ? _availiableStates[BaseState] : _availiableStates[_availiableStates.Keys.First()];
            _currentState.OnEnter();
        }
 private void Awake()
 {
     patrolWaypoints = GameObject.Find("Patrol_Waypoints");
     for (int i = 0; i < wayPoints.Length; i++)
     {
         wayPoints[i] = patrolWaypoints.transform.GetChild(i).transform;
     }
     animationController = this.GetComponent <AnimController>();
     CanShoot            = true;
     states = new Dictionary <EnemyState, AIStateBase>();
     states.Add(EnemyState.Patrol, new PatrolState(this));
     states.Add(EnemyState.Alert, new AlertState(this));
     states.Add(EnemyState.Chase, new ChaseState(this));
     states.Add(EnemyState.Shooting, new ShootingState(this));
     Weapon              = this.gameObject.GetComponent <Gun>();
     currentState        = states[EnemyState.Patrol];
     FireRate            = 10;
     cooldownTime        = 0.5f;
     animationController = this.GetComponent <AnimController>();
     if (bulletPool == null)
     {
         bulletPool = BulletPool._instance;
     }
     rb    = this.GetComponent <Rigidbody>();
     agent = this.GetComponent <NavMeshAgent>();
 }
Ejemplo n.º 3
0
 protected virtual void Start()
 {
     if (m_currentRunningState != null)
     {
         m_currentRunningState = Instantiate(m_currentRunningState);
         m_currentRunningState.Init(m_actor);
     }
 }
Ejemplo n.º 4
0
 public void MoveToState(EAIState pendingState)
 {
     if (_availiableStates[pendingState] != null)
     {
         _currentState.OnLeave();
         _currentState = _availiableStates[pendingState];
         _currentState.OnEnter();
     }
 }
Ejemplo n.º 5
0
        private void ChangeToNextState()
        {
            m_currentRunningState.OnExit();

            ScriptableObject _waitForDestroy = m_currentRunningState;

            m_currentRunningState = Instantiate(m_currentRunningState.NextState);
            Destroy(_waitForDestroy);
            m_currentRunningState.Init(m_actor);
        }
 private void Awake()
 {
     states = new Dictionary <Estados, AIStateBase>();
     states.Add(Estados.Patrol, new PatrolState(this));
     states.Add(Estados.Alert, new AlertState(this));
     states.Add(Estados.Chase, new ChaseState(this));
     states.Add(Estados.Idle, new IdleState(this));
     currentState = states[Estados.Idle];
     currentState.EjecutarEstado();
 }
Ejemplo n.º 7
0
        private void InitStates()
        {
            PatrolState patrol = new PatrolState(this, _path, _direction, _waypointArriveDistance);

            _states.Add(patrol);

            FollowTargetState followTarget = new FollowTargetState(this);

            _states.Add(followTarget);

            // Initiating the ShootState and adding it to the state system.
            ShootState shoot = new ShootState(this);

            _states.Add(shoot);

            CurrentState = patrol;
            CurrentState.StateActivated();
        }
    private static void AssignNextStatesToState(long stateNodeId, AIStateBase state)
    {
        List <TransitionNode> _transitionNodes = ((StateNode)AIBehaviourEditor.GetNode(stateNodeId)).transitions_out;

        NextAIState[] _nextAIStates = new NextAIState[_transitionNodes.Count];
        for (int _transitionNodeIndex = 0; _transitionNodeIndex < _transitionNodes.Count; _transitionNodeIndex++)
        {
            _nextAIStates[_transitionNodeIndex] = new NextAIState
            {
                conditions = new List <AIConditionBase>()
            };

            long _transitonNodeID = _transitionNodes[_transitionNodeIndex].ID;

            AssignConditionToNextState(_transitonNodeID, ref _nextAIStates[_transitionNodeIndex]);
            AssignStateToNextState(_transitonNodeID, ref _nextAIStates[_transitionNodeIndex]);
        }
        state.SetNextAIStates(_nextAIStates);
    }
        public bool PerformTransition(AIStateType targetState)
        {
            if (!CurrentState.CheckTransition(targetState))
            {
                return(false);
            }

            bool        result = false;
            AIStateBase state  = GetStateByType(targetState);

            if (state != null)
            {
                CurrentState.StateDeactivating();
                CurrentState = state;
                CurrentState.StateActivated();
                result = true;
            }
            return(result);
        }
Ejemplo n.º 10
0
    public AIStateBase GetStateInstance(Enemy.AIState state)
    {
        AIStateBase res = null;

        switch (state)
        {
        case Enemy.AIState.Idle:
            res = InstanceManager.Instance.GetInstance <AIStateBase>(typeof(Idle));
            break;

        case Enemy.AIState.Walk:
            res = InstanceManager.Instance.GetInstance <AIStateBase>(typeof(Walk));
            break;

        case Enemy.AIState.Attack:
            res = InstanceManager.Instance.GetInstance <AIStateBase>(typeof(Attack));
            break;

        case Enemy.AIState.BeAttack:
            res = InstanceManager.Instance.GetInstance <AIStateBase>(typeof(BeAttack));
            break;

        case Enemy.AIState.BeAttackTransform:
            res = InstanceManager.Instance.GetInstance <AIStateBase>(typeof(BeAttackTransform));
            break;

        case Enemy.AIState.ToFloor:
            res = InstanceManager.Instance.GetInstance <AIStateBase>(typeof(ToFloor));
            break;

        case Enemy.AIState.BeAttackUp:
            res = InstanceManager.Instance.GetInstance <AIStateBase>(typeof(BeAttackUp));
            break;

        case Enemy.AIState.Die:
            res = InstanceManager.Instance.GetInstance <AIStateBase>(typeof(Die));
            break;
        }

        return(res);
    }
Ejemplo n.º 11
0
        /// <summary>
        /// Changes the AI state.
        /// </summary>
        /// <param name="targetState">AI state type</param>
        /// <returns></returns>
        public bool PerformTransition(AIStateType targetState)
        {
            if (!CurrentState.CheckTransition(targetState))
            {
                Debug.Log("State change failed");
                return(false);
            }

            bool result = false;

            AIStateBase state = GetStateByType(targetState);

            if (state != null)
            {
                CurrentState.StartDeactivating();
                CurrentState = state;
                CurrentState.Activate();
                result = true;
                //Debug.Log("Changed state to " + state);
            }

            return(result);
        }
 //Changes the state machine between diferent states.
 public void MakeTransition(EnemyState state)
 {
     currentState = states[state];
     currentState.StartState();
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 回池子
 /// </summary>
 /// <param name="state"></param>
 public void Revert(AIStateBase state)
 {
     InstanceManager.Instance.Revert(state.GetType(), state);
 }
 public void MakeTransition(Estados state, float time)
 {
     currentState = states[state];
     currentState.IniciarEstado(time);
 }
 public void MakeTransition(Estados state, GameObject obj)
 {
     currentState = states[state];
     currentState.IniciarEstado(obj);
 }
 public void MakeTransition(Estados state)
 {
     currentState = states[state];
     //currentState.IniciarEstado();
 }