Пример #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);
            }
        }
 private void UpdateShotsText()
 {
     shotsTakenText.text = $"{_gameSessionService.GetShotsTaken()}";
 }
 private void UpdateUIFromGameSessionData()
 {
     totalShotsTakenText.text = $"{_gameSessionService.GetShotsTaken()}";
     totalTimeText.text       = $"{_gameSessionService.GetTimePlayed()} s";
 }
 private void OnEnable() // When this GUI is enabled, it's game over for sure end nothing else. Do all the game over game logic here.
 {
     totalShotsTakenText.text = _gameSessionService.GetShotsTaken().ToString();
     totalTimeText.text = $"{_gameSessionService.GetTimePlayed()} s";
     _gameSessionService.SaveGameSessionData(Constants.DIRECTORY_PATH_SAVES, Constants.FILE_NAME_LAST_SESSION);
 }