Ejemplo n.º 1
0
    //=====================================================

    public void OnHit(eDamageType damage)
    {
        if (_currentState != eShieldState.ENABLED)
        {
            return;
        }

        _health = Mathf.Clamp(_health - Convert.ToInt32(SettingsManager.GetSettingsItem("DAMAGE", (int)damage)), 0, 999999);

        //Debug.Log( "Shield health: " + _health );

        if (_health > 0.0f)
        {
            if (ShieldDamagedEvent != null)
            {
                ShieldDamagedEvent();
            }

            CurrentState = eShieldState.DAMAGED;
        }
        else
        {
            CurrentState = eShieldState.DESTROYED;
        }
    }
Ejemplo n.º 2
0
    //=====================================================

    public void OnActivate()
    {
        if (_currentState != eShieldState.DISABLED)
        {
            return;
        }

        CurrentState = eShieldState.ENABLED;
    }
Ejemplo n.º 3
0
    //=====================================================

    #region Private Methods

    #region Unity Calls

    void Awake()
    {
        _thisTransform = this.transform;
        _animator      = _thisTransform.GetComponent <Animator>();
        _collider      = _thisTransform.GetComponent <Collider>();
        //_psDamagedFx = _thisTransform.FindChild( "psDeathFx" ).gameObject;
        //_psExplodeFx = _thisTransform.FindChild( "psExplodeFx" ).gameObject;
        //_debugStateRenderer = _thisTransform.FindChild( "DebugState" ).GetComponent<Renderer>();

        _currentJobs = new List <Job>();

        // Set defaults
        CurrentState = eShieldState.INIT;
    }
Ejemplo n.º 4
0
    //=====================================================

    private void ExitState(eShieldState shieldStateExited)
    {
        if (_currentJobs == null || _currentJobs.Count <= 0)
        {
            return;
        }

        foreach (var job in _currentJobs)
        {
            if (job != null)
            {
                job.Kill();
            }
        }

        // Clear jobs list
        _currentJobs.Clear();
    }
Ejemplo n.º 5
0
    //=====================================================

    #region State Controllers

    private void EnterState(eShieldState shieldStateEntered)
    {
        switch (shieldStateEntered)
        {
        case eShieldState.INIT:
            SetShieldColour();
            CurrentState = eShieldState.DISABLED;
            break;

        case eShieldState.DISABLED:
            // ToDo: DEBUG - REMOVE THIS
            //_debugStateRenderer.material.color = Color.white;

            _collider.enabled = false;

            SetHealth();

            // Play animation
            if (_previousState == eShieldState.DESTROYED)
            {
                _animator.SetTrigger(HashIDs.Disable);
            }
            break;

        case eShieldState.ENABLED:
            // ToDo: DEBUG - REMOVE THIS
            //_debugStateRenderer.material.color = Color.blue;

            _collider.enabled = true;

            SetShieldColour();

            // Play animation
            if (_previousState != eShieldState.DAMAGED)
            {
                _animator.SetTrigger(HashIDs.Enable);
            }
            break;

        case eShieldState.DAMAGED:
            // ToDo: DEBUG - REMOVE THIS
            //_debugStateRenderer.material.color = Color.yellow;

            SetShieldColour();

            // Assign jobs
            _takingDamage = new Job(TakingDamage(() =>
            {
                //Debug.Log( "Damaged Shield Activating!" );
                CurrentState = eShieldState.ENABLED;
            }),
                                    true);
            // Update jobs list
            _currentJobs.Add(_takingDamage);
            break;

        case eShieldState.DESTROYED:
            // ToDo: DEBUG - REMOVE THIS
            //_debugStateRenderer.material.color = Color.red;

            SetShieldColour();

            // Assign jobs
            _disabling = new Job(Disabling(() =>
            {
                //Debug.Log( "Shield Destroyed - Disabling!" );
                CurrentState = eShieldState.DISABLED;
            }),
                                 true);
            // Update jobs list
            _currentJobs.Add(_disabling);

            if (ShieldDestroyedEvent != null)
            {
                ShieldDestroyedEvent();
            }
            break;
        }
    }