Esempio n. 1
0
        private void Awake()
        {
            Debug.Assert(!PhotonNetwork.connected, "Multiplay manager must be used in online environment.");

            // Modify PhotonNetwork settings according to in-game mode.
            PhotonNetwork.BackgroundTimeout   = 1000f;
            PhotonNetwork.sendRate            = 10;
            PhotonNetwork.sendRateOnSerialize = 10;

            //Set the singleton
            Debug.Assert(instance != null, "Multiple instantiation of the room Manager.");
            instance = this;

            mapDataManager = MapDataManager.Instance;
            uiManager      = UIManager.Instance;

            Hashtable roomCp = PhotonNetwork.room.CustomProperties;

            //Get the number of NPCs(only in test version).
            int tempNPCNum;

            if (int.TryParse(roomCp[Constants.NPCNumKey].ToString(), out tempNPCNum))
            {
                NPCNum = tempNPCNum;
            }

            //Get the number of thief players.
            if (!int.TryParse(roomCp["Thieves Number"].ToString(), out thievesNum))
            {
                Debug.LogError("Thieves number(in custom property) is not set properly.");
                return;
            }

            PhotonExtends.SetLocalPlayerProp(pauseKey, false);

            if (PhotonNetwork.isMasterClient)
            {
                //Randomly switch the master client. It prevents that the player who made room always be picked as a thief.
                int[] randomPlayerSelector = new int[PhotonNetwork.playerList.Length];
                for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
                {
                    randomPlayerSelector[i] = PhotonNetwork.playerList[i].ID;
                }

                GlobalFunctions.RandomizeArray <int>(randomPlayerSelector);

                if (randomPlayerSelector[0] == PhotonNetwork.player.ID)
                {
                    SetTeamOfPlayers();
                }
                else
                {
                    Debug.Log("Change the master client.");

                    for (int i = 0; i < randomPlayerSelector.Length; i++)
                    {
                        PhotonPlayer newMaster = PhotonPlayer.Find(randomPlayerSelector[i]);
                        if (newMaster != null &&
                            newMaster.CustomProperties[pauseKey] != null && !(bool)newMaster.CustomProperties[pauseKey])
                        {
                            PhotonNetwork.SetMasterClient(newMaster);
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public override void OnLeftRoom()
 {
     instance = null;
 }