コード例 #1
0
 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);
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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() + "游戏已开始。");
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public void ValidateGameMode(GameModeModel gameMode)
 {
     onGameModeValidate.Invoke(gameMode.GameSessionPrefab != null);
 }