public void SelectGameMode(int modeIndex) { if (!m_GameModeDatabase || m_GameModeDatabase.GameModeModels.Length <= modeIndex) { return; } m_CurrentGameMode = m_GameModeDatabase.GameModeModels[modeIndex]; ValidateGameMode(m_CurrentGameMode); UpdateCharacterList(m_CurrentGameMode); }
public void UpdateCharacterList(GameModeModel gameMode) { if (!m_CharacterDatabase) { return; } OrderedDictionary dictionary = new OrderedDictionary(); CharacterModel[] enabledCharacters = m_CharacterDatabase.CharacterModels.Where(c => !gameMode.DisabledCharacters.Contains(c.Id)).ToArray(); foreach (CharacterModel character in enabledCharacters) { dictionary.Add(character.Id.ToString(), character); } onCharacterListUpdate.Invoke(dictionary); }
public virtual void InitGameLogic(int[] allocatedPhotonViewIds, PhotonPlayer[] players, GameModeModel gameMode, Dictionary <int, int> characterSet) { for (int i = 0; i < m_RuntimePhotonViews.Length; i++) { if (m_RuntimePhotonViews[i]) { m_RuntimePhotonViews[i].viewID = allocatedPhotonViewIds[i]; } } m_Players = players; m_GameMode = gameMode; onGameModeDescriptionInit.Invoke(m_GameMode.Description); m_CharacterSet = characterSet; GenerateEmptyIdenities(); m_IsInitialized = true; InitGameLogic_Callback(); }
private void StartRemoteGameSession(int[] allocatedPhotonViewIds, PhotonPlayer[] players, int gameModeId, Dictionary <int, int> characterSet) { GameModeModel gameMode = null; foreach (GameModeModel gameModeModel in m_GameModeDatabase.GameModeModels) { if (gameModeModel.Id == gameModeId) { gameMode = gameModeModel; break; } } int[] otherPhotonViewIds = allocatedPhotonViewIds.Skip(1).ToArray(); bool hasStarted = GameSessionService.StartGameSession(allocatedPhotonViewIds[0], otherPhotonViewIds, players, gameMode, characterSet); if (PhotonNetwork.player.isMasterClient) { PhotonNetwork.room.open = !hasStarted; } GameSessionService.GameSession.transform.parent = this.transform; onStartRemoteGameSession.Invoke(); UpdateLog(Timestamp.ImprintLocalTime() + "游戏已开始。"); }
public static bool StartGameSession(int GameSessionPhotonViewId, int[] otherPhotonViewIds, PhotonPlayer[] players, GameModeModel gameMode, Dictionary <int, int> characterSet) { if (m_GameSession) { Debug.LogWarning("当前游戏进程不为空,请先结束当前进程。"); return(false); } m_GameSession = UnityEngine.Object.Instantiate(gameMode.GameSessionPrefab); PhotonView photonView = m_GameSession.GetComponent <PhotonView>(); photonView.viewID = GameSessionPhotonViewId; GameLogicBase gameLogic = m_GameSession.GetComponent <GameLogicBase>(); if (!gameLogic) { Debug.LogError("无法生成有效的游戏逻辑,游戏未能成功创建!"); EndGameSession(); return(false); } gameLogic.InitGameLogic(otherPhotonViewIds, players, gameMode, characterSet); return(true); }
public void ValidateGameMode(GameModeModel gameMode) { onGameModeValidate.Invoke(gameMode.GameSessionPrefab != null); }