Ejemplo n.º 1
0
        public bool Reload()
        {
            if (!IsReloadPossible())
            {
                return(false);
            }

            int currentAmmo = _activeAmmo;

            _onReload.UiResponce?.Invoke();
            _onReload.CodeResponce?.Invoke();

            _state = Data.WeaponState.Reload;
            _stateInfo.Remember((int)_state, _ammo.Data[currentAmmo].ReloadTime);

            _progressCoroutine =
                StartCoroutine(UpdateProgress(0, _stateInfo.TimeRemaining));

            _stateResultAciton = () =>
            {
                _ammo.Handler.Reload(_ammo.Data[currentAmmo]); // Was _activeAmmo
                UpdateUI(UIUpdateMode.MagazineAmount | UIUpdateMode.OverallAmount);

                _actionCoroutine = null;

                _state = Data.WeaponState.Idle;
                _stateInfo.Forget();
            };

            _actionCoroutine = RunLaterValued(_stateResultAciton,
                                              _stateInfo.TimeRemaining);


            return(true);
        }
Ejemplo n.º 2
0
        protected void OnEnable()
        {
            if ((_stateInfo.IsEmpty) ||
                (_stateInfo.TimeRemaining == 0.0f))
            {
                return;
            }

            _state = (Data.WeaponState)_stateInfo.Id;

            _progressCoroutine =
                StartCoroutine(UpdateProgress(0.0f, _stateInfo.TimeRemaining));

            _actionCoroutine = RunLaterValued(_stateResultAciton,
                                              _stateInfo.TimeRemaining);
        }
Ejemplo n.º 3
0
        public bool Shoot()
        {
            if (!IsShotPossible())
            {
                return(false);
            }

            int currentSMode = _activeShooting;

            _shooting.Data[currentSMode].Perform(this);

            _onShot.UiResponce?.Invoke();
            _onShot.CodeResponce?.Invoke();


            _state = Data.WeaponState.Shooting;
            _stateInfo.Remember((int)_state, _shooting.Data[currentSMode].TimeBetweenShot);

            _progressCoroutine =
                StartCoroutine(UpdateProgress(0, _stateInfo.TimeRemaining));

            UpdateUI(UIUpdateMode.MagazineAmount | UIUpdateMode.OverallAmount);

            _stateResultAciton = () =>
            {
                _actionCoroutine = null;

                _state = Data.WeaponState.Idle;
                _stateInfo.Forget();
            };

            _actionCoroutine = RunLaterValued(_stateResultAciton,
                                              _stateInfo.TimeRemaining);


            return(true);
        }