Exemplo n.º 1
0
        public void StartGame(string gameId)
        {
            gameData = GetGameDataByID(gameId);
            if (!IsCanStartReplayGame())
            {
                Debug.Log("++IsCanStartReplayGame: "); Core.Instance.GetService <StatesManager>().SwitchState(StatesEnum.GAME_ASYNC); return;
            }

            if (!_safePlayerPrefs.IsRecord(gameId) && _safePlayerPrefs.IsReplayDone(gameId) && _safePlayerPrefs.IsReplay(gameId))
            {
                _header.canvaseGroup.interactable = false;
                //Debug.Log("CHOOSE_TRACK");
                _chooseTrackWindow.IsChooseTrack = gameId;
                _mainScreenStateManager.SwitchState(MainScreenStatesEnum.CHOOSE_TRACK);
                return;
            }
            // --------------------------------------------------------------------------------------------------
            //
            if (gameData != null)
            {
                // -----------------------------------------------
                if (IsCanStartReplayGame())
                {
                    //Debug.LogError("LoadReplay " + gameId);
                    _networkManager.LoadReplay(gameId,
                                               () => { Debug.Log("StartGame ok"); Core.Instance.GetService <StatesManager>().SwitchState(StatesEnum.GAME_ASYNC); },
                                               (err) => { Debug.LogError("Can't load replay: " + gameId);
                                                          if (err == "timeout")
                                                          {
                                                              Debug.Log("StartGame err");
                                                              _uiManager.ShowWindow(UIWindowEnum.SPLASH, false);
                                                              _enternetWindow.ShowErrorEnternet();
                                                          }
                                                          else
                                                          {
                                                              Debug.LogError("StartGame err");
                                                          } }
                                               );
                }
                else
                {
                    Core.Instance.GetService <StatesManager>().SwitchState(StatesEnum.GAME_ASYNC);
                }
                // -----------------------------------------------
            }
            // --------------------------------------------------------------------------------------------------
            //
            else
            {
                Debug.LogError("GAME DATA IS NULL!");
                _mainScreenStateManager.SwitchState(MainScreenStatesEnum.MAIN_MULTIPLAYER);
            }
            // --------------------------------------------------------------------------------------------------
        }
Exemplo n.º 2
0
        void OnPlayGame(string gameId)
        {
            _multiplayerWindow.OnPlay -= OnPlayGame;
            _uiManager.ShowWindow(UIWindowEnum.SPLASH, true);

            Core.Instance.GetService <NetworkManager>().Join_Play(gameId, _playerManager.selectedCar, () =>
            {
                if (!_sPlayerP.IsGameId(gameId))
                {
                    Debug.Log("NEW GAME");
                    _sPlayerP.SafeDataOnPlayClick(_gameManager.GetGameDataByID(gameId));
                    _gameManager.StartGame(gameId);
                }
                else if (_sPlayerP.IsRecord(gameId))
                {
                    Debug.Log("RECORD GAME");
                    _gameManager.ApplyTrack(_sPlayerP.GetTrack(gameId), gameId);
                    _sPlayerP.FillReplayStatistic(gameId);
                    _sPlayerP.FillUserStatistic(gameId);
                }
                else
                {
                    Debug.Log("REPLAY GAME");
                    _gameManager.StartGame(gameId);
                }
            }, (err) =>
            {
                if (err == "timeout")
                {
                    _uiManager.ShowWindow(UIWindowEnum.SPLASH, false);
                    _enternetWindow.ShowErrorEnternet();
                    _multiplayerWindow.OnPlay += OnPlayGame;
                }
                else
                {
                    Debug.LogError("OnPlayGame err");
                }
            });
        }