コード例 #1
0
        private void UpdateAwaitingInput()
        {
            DoTimerUpdate();

            // Track space keypress. When space is held, scale the to-be-applied force with the hit force tick setting.
            if (Input.GetKey(KeyCode.Space))
            {
                _eventService.TriggerEvent(Constants.GUI_REPLAY_POSSIBILITY_CHANGED, false);

                if (_lastHitForceScaleTime == -1)
                {
                    _lastHitForceScaleTime = Time.timeSinceLevelLoad;
                }

                else if (Time.timeSinceLevelLoad - _lastHitForceScaleTime >= forceTimerTick)
                {
                    _currentHitForceScale  = Mathf.Min(_currentHitForceScale + 1, maximumForceTicks);
                    _lastHitForceScaleTime = Time.timeSinceLevelLoad;
                    _eventService.TriggerEvent(Constants.CUE_BALL_HIT_FORCE_PERCENT_CHANGED, _currentHitForceScale / maximumForceTicks);
                    _eventService.TriggerEvent(Constants.CUE_BALL_HIT_FORCE_VALUE_CHANGED, CalculateHitForce());
                }
            }
            // when released, apply the final force
            if (Input.GetKeyUp(KeyCode.Space))
            {
                //_eventService.TriggerEvent(Constants.GUI_REPLAY_POSSIBILITY_CHANGED, true);

                //Set cached info for replay
                _cachedCueBallPosition          = cueBall.transform.position;
                _cachedYellowTargetBallPosition = yellowTargetBall.transform.position;
                _cachedRedTargetBallPosition    = redTargetBall.transform.position;
                _cachedHitForce = CalculateHitForce();

                _isAddForceQueued = true;

                _currentHitForceScale  = 0f;
                _lastHitForceScaleTime = -1;

                _gameSessionService.SetShotsTaken(_gameSessionService.GetShotsTaken() + 1);

                _eventService.TriggerEvent(Constants.SESSION_DATA_SHOTS_UPDATED);
                _eventService.TriggerEvent(Constants.CUE_BALL_HIT_FORCE_PERCENT_CHANGED, 0f);

                stateHolder.SetState((int)ControllerState.BallInMotion);
            }
        }