Пример #1
0
    //private uint mCurTargetId = uint.MaxValue;

    public CommonAI(BattleUnit battleUnit, bool flowIdle = false) : base(battleUnit)
    {
        mStateIdle   = new AIStateIdle(this);
        mStateGoHome = new AIStateGoHome(this);
        mStateCombat = new AIStateCombat(this);

        mFlowIdle     = flowIdle;
        mStateCurrent = null;
    }
Пример #2
0
    void Start()
    {
        State state = new AIStateIdle();
        state.ID = (int)eState.E_IDLE;
        _dicStates.Add(state.ID, state);

        state = new AIStateWalk();
        state.ID = (int)eState.E_WALK;
        _dicStates.Add(state.ID, state);
        //Set Default State
        SetStateIdle();
    }
Пример #3
0
    void Start()
    {
        State state = new AIStateIdle();

        state.ID = (int)eState.E_IDLE;
        _dicStates.Add(state.ID, state);

        state    = new AIStateWalk();
        state.ID = (int)eState.E_WALK;
        _dicStates.Add(state.ID, state);
        //Set Default State
        SetStateIdle();
    }
Пример #4
0
    private void Start()
    {
        // Getting cache variables
        _navMeshAgent     = GetComponent <NavMeshAgent>();
        _animator         = GetComponent <Animator>();
        _mouthAudioSource = GetComponent <AudioSource>();
        _targetTrigger    = GetComponentInChildren <TargetTrigger>();
        AIDecapitation[] parts = GetComponentsInChildren <AIDecapitation>();
        foreach (AIDecapitation part in parts)
        {
            _parts.Add(part);
        }

        HandleAnimatorController();

        // Getting the skinned mesh renderers for the metamorphosis
        if (_metamorphosisMaterial != null)
        {
            SkinnedMeshRenderer[] skinnedMeshRenderers = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (SkinnedMeshRenderer meshRenderer in skinnedMeshRenderers)
            {
                _skinnedMeshRenderers.Add(meshRenderer);
            }
        }

        // We always have the rotation of the navmesh deactivated!
        // In fact, we either rotate with the root motion rotation of the turn around animation
        // Or we rotate it manually through code.
        // In sum, the navmesh is only useful for calculating the path: steertingTarget :)
        if (_navMeshAgent != null)
        {
            _navMeshAgent.updateRotation = false;
        }

        if (_targetTrigger != null)
        {
            _targetTrigger.RegisterTargetTrigger(this);
        }

        // Storing states
        AIStateIdle stateIdle = GetComponent <AIStateIdle>();

        if (stateIdle != null)
        {
            _statesDictionary.Add(AIStateType.Idle, stateIdle);
            _statesDictionary[AIStateType.Idle].RegisterState(this);
        }

        AIStatePatrol statePatrol = GetComponent <AIStatePatrol>();

        if (statePatrol != null)
        {
            _statesDictionary.Add(AIStateType.Patrol, statePatrol);
            _statesDictionary[AIStateType.Patrol].RegisterState(this);
        }

        AIStatePursuit statePursuit = GetComponent <AIStatePursuit>();

        if (statePursuit != null)
        {
            _statesDictionary.Add(AIStateType.Pursuit, statePursuit);
            _statesDictionary[AIStateType.Pursuit].RegisterState(this);
        }

        AIStateAttack stateAttack = GetComponent <AIStateAttack>();

        if (stateAttack != null)
        {
            _statesDictionary.Add(AIStateType.Attacking, stateAttack);
            _statesDictionary[AIStateType.Attacking].RegisterState(this);
        }

        AIStateAlert stateAlert = GetComponent <AIStateAlert>();

        if (stateAlert != null)
        {
            _statesDictionary.Add(AIStateType.Alert, stateAlert);
            _statesDictionary[AIStateType.Alert].RegisterState(this);
        }

        if (_statesDictionary.ContainsKey(AIStateType.Idle) && _statesDictionary[AIStateType.Idle] != null)
        {
            ChangeState(AIStateType.Idle);
        }

        // Get all body parts snapshot
        Transform[] bodyParts = transform.GetComponentsInChildren <Transform>();
        foreach (Transform bodyPart in bodyParts)
        {
            BodyPartSnapShot bodyPartSnapshot = new BodyPartSnapShot();
            bodyPartSnapshot.transform = bodyPart;
            _bodyPartsSnapshots.Add(bodyPartSnapshot);
        }

        // At the beginning, we should always be able to scream
        _screamTimer = _screamDelay;

        // Getting the navmesh agent initial speed for damageBehavior (in case we aren't using root rotation)
        if (_navMeshAgent != null)
        {
            _initialSpeed = _navMeshAgent.speed;
        }

        _initialVehicleStoppingDistance = _vehicleStoppingDistance;
    }