public int GetFlag(Flag preferredFlag) { ExitGames.Client.Photon.Hashtable roomProperties = thisRoom.CustomProperties; string flagCountKey = "RedCount"; string flagIdKey = "RedIds"; string idStr = "123"; int returnId = -1; switch (preferredFlag) { case Flag.Red: flagCountKey = "RedCount"; flagIdKey = "RedIds"; idStr = "123"; break; case Flag.Blue: flagCountKey = "BlueCount"; flagIdKey = "BlueIds"; idStr = "567"; break; default:; break; } if (!roomProperties.ContainsKey(flagCountKey)) { roomProperties.Add(flagCountKey, 1); roomProperties.Add(flagIdKey, idStr); returnId = (preferredFlag == Flag.Red) ? 0 : 4; } else if ((int)roomProperties["RedCount"] == maxPlayerOneSide) { return(-1); } else { roomProperties[flagCountKey] = (int)roomProperties[flagCountKey] + 1; returnId = ((string)roomProperties[flagIdKey])[0] - '0'; roomProperties[flagIdKey] = ((string)roomProperties[flagIdKey]).Substring(1); } return(returnId); }
private Client client; // Socket void Start() { this.client = GameObject.Find("Manager").GetComponent<ClientManager>().Client; user = User.Instance; if (user.is_connected) { PhotonNetwork.playerName = user.username; PhotonPeer.RegisterType(typeof(Team), (byte)'T', ObjectToByteArray, ByteToTeam); PhotonPeer.RegisterType(typeof(Composition), (byte)'C', ObjectToByteArray, ByteToComposition); PhotonPeer.RegisterType(typeof(Player), (byte)'P', ObjectToByteArray, ByteToPlayer); PhotonPeer.RegisterType(typeof(User), (byte)'U', ObjectToByteArray, ByteToUser); PhotonPeer.RegisterType(typeof(List<string>), (byte)'L', ObjectToByteArray, ByteToLS); PhotonHastable props = new PhotonHastable(); props.Add("Team", Settings.Instance.Selected_Team); props.Add("User", user); PhotonNetwork.player.SetCustomProperties(props); PhotonNetwork.ConnectUsingSettings(game_version_); this.room_name = user.username + "-" + rand.Next(1000); } }
public override void Serialize(ExitGames.Client.Photon.Hashtable h) { base.Serialize(h); h.Add('o', orders.Select(o => o.index).ToArray()); h.Add('s', score); }
/// <summary> /// Call to send an action. Optionally finish the turn, too. /// The move object can be anything. Try to optimize though and only send the strict minimum set of information to define the turn move. /// </summary> /// <param name="move"></param> /// <param name="finished"></param> public void SendMove(object move, bool finished) { //if (IsFinishedByMe) //{ // UnityEngine.Debug.LogWarning("Can't SendMove. Turn is finished by this player."); // return; //} // along with the actual move, we have to send which turn this move belongs to Hashtable moveHt = new Hashtable(); moveHt.Add("turn", Turn); moveHt.Add("move", move); byte evCode = (finished) ? EvFinalMove : EvMove; PhotonNetwork.RaiseEvent(evCode, moveHt, new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache }, SendOptions.SendReliable); if (finished) { PhotonNetwork.LocalPlayer.SetFinishedTurn(Turn); } // the server won't send the event back to the origin (by default). to get the event, call it locally // (note: the order of events might be mixed up as we do this locally) ProcessOnEvent(evCode, moveHt, PhotonNetwork.LocalPlayer.ActorNumber); }
public void CheckForWinner() { Hashtable updateStats = new Hashtable(); if (LostGame) { this.LosePanel.SetActive(true); updateStats.Add("PlayerLosses", pi.losts++); PhotonNetwork.LocalPlayer.SetCustomProperties(updateStats); } else { this.WinPanel.SetActive(true); this.stradded = Random.Range(0, (int)PhotonNetwork.LocalPlayer.GetNext().CustomProperties["PlayerSlimeAttack"]); this.defadded = Random.Range(0, (int)PhotonNetwork.LocalPlayer.GetNext().CustomProperties["PlayerSlimeDefense"]); this.spdadded = Random.Range(0, (int)PhotonNetwork.LocalPlayer.GetNext().CustomProperties["PlayerSlimeSpeed"]); updateStats.Add("PlayerWins", pi.wins++); updateStats.Add("PlayerSlimeAttack", pi.mySlime.getAtk() + stradded); updateStats.Add("PlayerSlimeDefense", pi.mySlime.getDef() + defadded); updateStats.Add("PlayerSlimeSpeed", pi.mySlime.getSpd() + spdadded); PhotonNetwork.LocalPlayer.SetCustomProperties(updateStats); this.WinPanel.GetComponent <WinPanel>().wintext.text += "\n Strength +" + stradded + "\n Defense +" + defadded + "\n Speed +" + spdadded; } }
public override void OnJoinedRoom() { SwitchPanels(lobbyPanel); playerList = PhotonNetwork.PlayerList; // Set custom player properties ExitGames.Client.Photon.Hashtable hash = new ExitGames.Client.Photon.Hashtable(); hash.Add("Bankrupt", false); hash.Add("OwnedProperties", new bool[40]); PhotonNetwork.LocalPlayer.SetCustomProperties(hash); if (PhotonNetwork.IsMasterClient) { pieces = new List <int>(); //pieces.Add(0); // Comment out since master client will take this piece pieces.Add(1); pieces.Add(2); pieces.Add(3); pieces.Add(4); pieces.Add(5); pieces.Add(6); ExitGames.Client.Photon.Hashtable hash2 = new ExitGames.Client.Photon.Hashtable(); hash2.Add("Gamepiece", 0); PhotonNetwork.LocalPlayer.SetCustomProperties(hash2); } UpdateTexts(); }
void CreateRoomOnJoinFaield(string type) { Debug.Log("creating a " + type + " game room..."); RoomOptions roomOptions = new RoomOptions(); string[] ops = { "type" }; roomOptions.CustomRoomPropertiesForLobby = ops; string[] props = { type }; //https://doc.photonengine.com/en-us/pun/current/lobby-and-matchmaking/matchmaking-and-lobby#matchmaking_checklist Hashtable customProps = new Hashtable(); customProps.Add("type", type); customProps.Add("round", 1); roomOptions.CustomRoomProperties = customProps; //roomOptions.CustomRoomProperties = new Hashtable { { "type",type } }; roomOptions.MaxPlayers = 2; roomOptions.IsOpen = true; roomOptions.IsVisible = true; roomController.roomType = type; PhotonNetwork.CreateRoom(null, roomOptions); //PhotonNetwork.CreateRoom(PhotonNetwork.AuthValues.UserId + "'s" + type + " Room", roomOptions); }
public void UpdatePlayerProperties(string key, object value) { ht.Clear(); ht.Add(key, value); PhotonNetwork.LocalPlayer.SetCustomProperties(ht); }
// special case function for easy/med/hard/impossible difficulty public void UpdateSliderValueDifficulty() { int sliderValue = (int)sliderDiff.value; ExitGames.Client.Photon.Hashtable prop = new ExitGames.Client.Photon.Hashtable(); if (sliderValue == 0) { //text.text = "Easy"; prop.Add("sliderValueDiff", "Easy"); } else if (sliderValue == 1) { //text.text = "Medium"; prop.Add("sliderValueDiff", "Medium"); } else if (sliderValue == 2) { //text.text = "Hard"; prop.Add("sliderValueDiff", "Hard"); } else if (sliderValue == 3) { //text.text = "Impossible"; prop.Add("sliderValueDiff", "Impossible"); } if (PhotonNetwork.NetworkClientState != Photon.Realtime.ClientState.Leaving) { PhotonNetwork.CurrentRoom.SetCustomProperties(prop); } }
/// <summary> /// Callback used when the player successfully joins a room. /// </summary> public void OnJoinedRoom() { playersInRoom = new List <PhotonPlayer>(PhotonNetwork.playerList); myTeam = (TeamTypes)((playersInRoom.Count + 1) % 2); ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable(); properties.Add("Team", myTeam.GetHashCode()); properties.Add("Character", myCharacter.GetHashCode()); properties.Add("PlayFabID", PlayFabManager.instance.GetMyPlayerID()); bool containsOwner = false; for (int i = 0; i < PhotonNetwork.otherPlayers.Length; i++) { object ownerName; if (PhotonNetwork.otherPlayers[i].customProperties.TryGetValue("Owner", out ownerName)) { containsOwner = true; break; } } if (!containsOwner) { properties.Add("Owner", PhotonNetwork.player.name); } PhotonNetwork.player.SetCustomProperties(properties); myRoomInfo = PhotonNetwork.room; OnJoinedRoomCallback(PhotonNetwork.room); }
public async Task <bool> UpdateRoomProperties(string key, object value) { if (updateKey != null) { Debug.Log("Was UpdateRoomProperties"); return(false); } updateKey = key; ht.Clear(); ht.Add(key, value); orght.Clear(); if (PhotonNetwork.CurrentRoom.CustomProperties.TryGetValue(key, out object rVal)) { orght.Add(key, rVal); } else { orght.Add(key, null); } if (!PhotonNetwork.CurrentRoom.SetCustomProperties(ht, orght)) { updateKey = null; return(false); } updateVal = value; roomPropUpdateResult = new TaskCompletionSource <bool>(); return(await roomPropUpdateResult.Task); }
public override void Serialize(ExitGames.Client.Photon.Hashtable h) { base.Serialize(h); h.Add('p', transform.position); h.Add('r', transform.rotation); }
public void Start() { // this.LoadState(); degreeText.text = ((int)(initValue * 360f)).ToString() + "°"; mainSlider.value = initValue; liveMode = false; sphere.SetActive(liveMode); // consoleText = resetButton.GetComponentInChildren<Text>(); //Adds a listener to the main slider and invokes a method when the value changes. mainSlider.onValueChanged.AddListener(delegate { ValueChangeCheck(); }); resetButton.onClick.AddListener(delegate { this.SendSyncRequest(); }); toggle.onValueChanged.AddListener(delegate { this.InitiateLiveMode(); }); // Network stuff hash.Add("Rotation", initValue); hash.Add("LaserPosition", Vector3.zero); hash.Add("LiveMode", false); // localPlayer.SetCustomProperties(hash); // Create a deactive sphere to activate when live mode is turned on // sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); // sphere.material = // sphere.transform.position = new Vector3(0, 1.5f, 0); }
// 封装复用方法,给自己分配一个序号 // RoomInfo 里的公共变量string "1234567" 来保存序号 public void GetFlag() { ExitGames.Client.Photon.Hashtable roomProperties = thisRoom.CustomProperties; if (!roomProperties.ContainsKey("RedCount")) { roomProperties.Add("RedCount", 1); flag = 0; roomProperties.Add("RedIds", "123"); playerId = 0; } else if ((int)roomProperties["RedCount"] == maxPlayerOneSide) { if (!roomProperties.ContainsKey("BlueCount")) { roomProperties.Add("BlueCount", 1); flag = Flag.Blue; roomProperties.Add("BlueIds", "567"); playerId = 4; } else { roomProperties["BlueCount"] = (int)roomProperties["BlueCount"] + 1; flag = Flag.Red; playerId = ((string)roomProperties["BlueIds"])[0] - '0'; roomProperties["BlueIds"] = ((string)roomProperties["BlueIds"]).Substring(1); } } else { roomProperties["RedCount"] = (int)roomProperties["RedCount"] + 1; playerId = ((string)roomProperties["RedIds"])[0] - '0'; roomProperties["RedIds"] = ((string)roomProperties["RedIds"]).Substring(1); } thisRoom.SetCustomProperties(roomProperties); }
public void CreatePhotonRoom() { if (!PhotonNetwork.IsConnected) { return; } if (roomName.text == "") { roomName.text = "Room" + UnityEngine.Random.Range(1, 1000); } maxPlayers.minValue = 0; curr = starttime; RoomOptions ro = new RoomOptions(); ro.IsOpen = true; ro.IsVisible = true; ro.MaxPlayers = (byte)maxPlayers.value; Hashtable RoomCustomProps = new Hashtable(); RoomCustomProps.Add("RANG", (int)rangPlayers.value); RoomCustomProps.Add("MAXP", (int)maxPlayers.value); RoomCustomProps.Add("Kick1", 0); RoomCustomProps.Add("Kick2", 0); ro.CustomRoomProperties = RoomCustomProps; PhotonNetwork.JoinOrCreateRoom(roomName.text, ro, TypedLobby.Default); }
void Start() { //var locationCheck = Input.location; ExitGames.Client.Photon.PhotonPeer.RegisterType(typeof(FireSpawn), 255, FireSpawn.Serialize, FireSpawn.Deserialize); ExitGames.Client.Photon.Hashtable customProps = new ExitGames.Client.Photon.Hashtable(); customProps.Add("Hero", 0); customProps.Add("PowerLevel", 0); PhotonNetwork.LocalPlayer.SetCustomProperties(customProps); }
private void UserDataUpdate(object sender, EventArgs e) { ExitGames.Client.Photon.Hashtable playerCustomProperties = new ExitGames.Client.Photon.Hashtable(); playerCustomProperties.Add(ActorNumberString, PhotonNetwork.LocalPlayer.ActorNumber); playerCustomProperties.Add(GenderKey, m_webInterface.UserInfo.gender); playerCustomProperties.Add(UserIdKey, m_webInterface.UserInfo._id); PhotonNetwork.LocalPlayer.SetCustomProperties(playerCustomProperties); PhotonNetwork.NickName = m_webInterface.UserInfo.name; }
/// <summary> /// Ensures the free players is populated by the first player to enter /// the room /// </summary> void EnsureRoomPropertiesExist() { if (!PhotonNetwork.CurrentRoom.CustomProperties.ContainsKey(FREE_PLAYERS_PROPERTY_KEY)) { var outData = new Hashtable(); outData.Add(FREE_PLAYERS_PROPERTY_KEY, freePlayers.ToArray()); outData.Add(PLAYER_OWNERS_PROPERTIES_KEY, new Dictionary <int, int>()); PhotonNetwork.CurrentRoom.SetCustomProperties(outData); } }
public playerDetails() { ExitGames.Client.Photon.Hashtable tbl = new ExitGames.Client.Photon.Hashtable(); tbl.Add("kills", 0); tbl.Add("deaths", 0); PhotonNetwork.LocalPlayer.SetCustomProperties(tbl); this.username = (string)PhotonNetwork.LocalPlayer.NickName; this.PlayerID = (string)PhotonNetwork.LocalPlayer.UserId; this.kills = 0; this.deaths = 0; }
public void SaveSettings() { ExitGames.Client.Photon.Hashtable hashTable = new ExitGames.Client.Photon.Hashtable(); hashTable.Add("PlayerColorRed", PlayerPrefs.GetFloat("RED")); hashTable.Add("PlayerColorGreen", PlayerPrefs.GetFloat("GREEN")); hashTable.Add("PlayerColorBlue", PlayerPrefs.GetFloat("BLUE")); hashTable.Add("PlayerColorHardMix", PlayerPrefs.GetInt("HardMix")); PhotonNetwork.SetPlayerCustomProperties(hashTable); }
/* PUN Callbacks */ public override void OnConnectedToMaster() { PhotonNetwork.NickName = "Player" + Random.Range(1, 10000).ToString(); var playerProps = new ExitGames.Client.Photon.Hashtable(); playerProps.Add("DoctorsIndex", "0"); playerProps.Add("PatientIndex", "0"); PhotonNetwork.LocalPlayer.SetCustomProperties(playerProps); PhotonNetwork.JoinLobby(); }
public void PlayerSchema(Player player) { Hashtable schema = new Hashtable(); schema.Add("Ready", false); schema.Add("Health", 100f); schema.Add("Fuel", 100f); schema.Add("NextBullet", 0); player.SetCustomProperties(schema); }
void UpdateAllStats() { // endOfGameSBThrownP2 = snowballsSpawned - maxSnowballs; Hashtable hash = new Hashtable(); hash.Add("MovementP2", localMovement); hash.Add("endOfGameSBThrownP2", endOfGameSBThrownP2); hash.Add("numberOfTeleportsP2", numberOfTeleports); PhotonNetwork.MasterClient.SetCustomProperties(hash); }
/// <summary> /// Local player property to send to the target player (often Player2) /// </summary> public void SendPlayerProperty(string propName, object value) { if (playerData.ContainsKey(propName)) { playerData[propName] = value; } else { playerData.Add(propName, value); } }
public override void OnCreatedRoom() { Hashtable roominfo = new Hashtable(); roominfo.Add("MasterName", PhotonNetwork.CurrentRoom.GetPlayer(1).NickName); roominfo.Add("RoomName", PhotonNetwork.CurrentRoom.Name); roominfo.Add("Privacy", recentRoomPrivacy); roominfo.Add("Password", PhotonNetwork.CurrentRoom.Name.Substring(0, 5)); roominfo.Add("InProgress", false); PhotonNetwork.CurrentRoom.SetCustomProperties(roominfo); }
void FirstLoad() { // Ensures the free players is populated by the first player to enter // the room if (!PhotonNetwork.CurrentRoom.CustomProperties.ContainsKey(FREE_PLAYERS_PROPERTY_KEY)) { var outData = new Hashtable(); outData.Add(FREE_PLAYERS_PROPERTY_KEY, freePlayers.ToArray()); outData.Add(PLAYER_OWNERS_PROPERTIES_KEY, new Dictionary <int, int>()); PhotonNetwork.CurrentRoom.SetCustomProperties(outData); } }
//-------------------------------------------------------------- /// Starts the round from the singleplayer or multiplayer menu. (Starts countdown first) //-------------------------------------------------------------- public void startRound() { Debug.Log("startRound"); if (!Maze.spawnRandomMap) { maze.RPCBuildMaze(Maze.stringToLoad); } objectManager.resetFloorToGameplay(); timerManager.startTimer("WAITING_COUNTDOWN", 5.0f); PLAYERS = PhotonNetwork.room.playerCount; PhotonPlayer[] players = PhotonNetwork.otherPlayers; int myID = 1; for (int i = 0; i < players.Length; i++) { if (players[i].ID < PhotonNetwork.player.ID) { myID++; } } PLAYER_ID = myID; ExitGames.Client.Photon.Hashtable ht = new ExitGames.Client.Photon.Hashtable(); ht.Add("CheeseCount", "0"); ht.Add("PlayerID", myID.ToString()); PhotonNetwork.player.SetCustomProperties(ht); objectManager.spawnCharacter(); if (PhotonNetwork.offlineMode) { objectManager.spawnBots(); } if (PhotonNetwork.isMasterClient) { PhotonNetwork.room.maxPlayers = PhotonNetwork.room.playerCount; } GameObject MyCharacter = GameObject.Find("My Character"); if (MyCharacter != null) { MyCharacter.GetComponentInChildren <TextMesh>().text = "YOU"; } gameStateManager.goToState(GameStateManager.GameState.WAITING); audioManager.stopAllClips("MAIN_MENU_MUSIC"); audioManager.fadeClipOut("MAIN_MENU_MUSIC"); }
public void SaveBoardToProperties() { Hashtable boardProps = board.GetBoardAsCustomProperties(); boardProps.Add("pt", this.PlayerIdToMakeThisTurn); // "pt" is for "player turn" and contains the ID/actorNumber of the player who's turn it is boardProps.Add("t#", this.TurnNumber); //boardProps.Add(GetPlayerPointsPropKey(this.LocalPlayer.ID), this.MyPoints); // we always only save "our" points. this will not affect the opponent's score. //Debug.Log(string.Format("saved board to room-props {0}", SupportClass.DictionaryToString(boardProps))); PhotonNetwork.room.SetCustomProperties(boardProps); }
// this is called on button press, sets the properties of the room to go back to default (the values on room creation) public void SetSettingsToDefault() { ExitGames.Client.Photon.Hashtable props = new ExitGames.Client.Photon.Hashtable(); props.Add("sliderValue", 200f); props.Add("sliderValueDiff", "Hard"); slider.value = 200; sliderDiff.value = 2; PhotonNetwork.CurrentRoom.SetCustomProperties(props); }
public void AddCharacterToRoom() { Hashtable hash = PhotonNetwork.room.customProperties; Player play = k_player.GetComponent <Player> (); hash.Add((string)play.PlayerName, (int)play.Characters.Length); for (int i = 0; i < play.Characters.Length; i++) { hash.Add((string)play.PlayerName + i, play.Characters [i].MakeSimpleString()); } PhotonNetwork.room.SetCustomProperties(hash); }
IEnumerator rejoinLobby() { Hashtable StatChanged = new Hashtable(); StatChanged.Add("PlayerSlimeAttack", pi.mySlime.getAtk()); StatChanged.Add("PlayerSlimeDefense", pi.mySlime.getDef()); StatChanged.Add("PlayerSlimeSpeed", pi.mySlime.getSpd()); PhotonNetwork.LocalPlayer.SetCustomProperties(StatChanged); yield return(new WaitForSeconds(1)); PhotonNetwork.JoinLobby(); }
/// <summary> /// change the state and sync for other players /// </summary> public void Ready() { isReady = !isReady; PhotonNetwork.player.SendReady(isReady); Hashtable e = new Hashtable(); e.Add("PName",LocalName); e.Add("Ready",isReady); PhotonNetwork.RaiseEvent(EventID.PlayerJoinPre, e, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All}); }
/// <summary> /// Starts game. /// </summary> public void StartGame() { ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable(); properties.Add("Ready", false); PhotonNetwork.player.SetCustomProperties(properties); networkLayer.ActivateLevel(); //networkLayer.AllocateViewIDAndCallInstantiate(myCharacter, myTeam); }
void ReceiveInitialSpawnInfo(int id, PhotonPlayer player, Vector3 pos, Quaternion rot, string playerTypeName, int teamNumber, PhotonMessageInfo info) { if ((info.sender != PhotonNetwork.masterClient) && (info.sender != PhotonNetwork.player)) return; // initialize the newborn player with the mandatory 'on-join-stats' ExitGames.Client.Photon.Hashtable stats = new ExitGames.Client.Photon.Hashtable(); stats.Add("Type", playerTypeName); stats.Add("Team", teamNumber); stats.Add("Position", pos); stats.Add("Rotation", rot); // announce arrival of new player if (player.ID > PhotonNetwork.player.ID) vp_MPDebug.Log("Player " + player.name + " joined" + ((vp_MPTeamManager.Exists && (teamNumber > 0)) ? " team : " + vp_MPTeamManager.GetTeamName(teamNumber).ToUpper() : "") ); else if (player.ID == PhotonNetwork.player.ID) { vp_Timer.In(0.1f, delegate() { //Debug.Log("teamNumber: " + teamNumber); try { vp_MPDebug.Log( "Welcome to '" + PhotonNetwork.room.name + "' with " + PhotonNetwork.room.playerCount.ToString() + ((PhotonNetwork.room.playerCount == 1) ? " player (you)" : " players") + "." ); //vp_MPDebug.Log("Max players for room: " + PhotonNetwork.room.maxPlayers + "."); //vp_MPDebug.Log("Total players using app: " + PhotonNetwork.countOfPlayers); if (vp_MPTeamManager.Exists && (teamNumber > 0)) vp_MPDebug.Log("Your team is: " + vp_MPTeamManager.GetTeamName(teamNumber).ToUpper()); } catch { if (PhotonNetwork.room == null) Debug.Log("PhotonNetwork.room = null"); else if (PhotonNetwork.room.name == null) Debug.Log("PhotonNetwork.room.name = null"); if (vp_MPTeamManager.Instance == null) Debug.Log("vp_MPTeamManager.Instance = null"); else if (vp_MPTeamManager.GetTeamName(teamNumber) == null) Debug.Log("vp_MPMaster.GetTeamName(teamNumber) = null"); } }); } InstantiatePlayerPrefab(player, stats); }
/// <summary> /// Method to be called when the user wants to create a new room. /// </summary> public void CreateNewRoom(int numberOfPlayers,ProjectDelegates.RoomInfoCallback RoomCreatedCallback, int level) { OnJoinedRoomCallback = RoomCreatedCallback; ExitGames.Client.Photon.Hashtable customParams = new ExitGames.Client.Photon.Hashtable(); customParams.Add("C0", level); RoomOptions options = new RoomOptions(); options.maxPlayers = numberOfPlayers; TypedLobby typedLobby = new TypedLobby("GameLobby",LobbyType.Default); //PhotonNetwork.CreateRoom ("",options,typedLobby); //PhotonNetwork.CreateRoom ("", true, true, numberOfPlayers); // testing this to git rid of the build warning PhotonNetwork.CreateRoom("", options, typedLobby); }
/// <summary> /// Load and sync level /// Only masterclient can call this function /// </summary> public void LoadSyncLevel() { //Start game only when all are ready if (PhotonNetwork.playerList.AllPlayersReady()) { Hashtable e = new Hashtable(); e.Add("Level", PhotonNetwork.room.RoomScene()); PhotonNetwork.RaiseEvent(EventID.LoadSyncLevel, e, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All }); } else { Debug.Log("Some players are not ready, wait for hes"); } }
// We have two options here: we either joined(by title, list or random) or created a room. public override void OnJoinedRoom() { Debug.Log("OnJoinedRoom"); Hashtable e = new Hashtable(); e.Add("PName", LocalName); bool master = (PhotonNetwork.player.isMasterClient) ? true : false; e.Add("Ready", master); PhotonNetwork.player.SendReady(master); PhotonNetwork.RaiseEvent(EventID.PlayerJoinPre, e, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All }); }
/// <summary> /// Callback used when the player successfully joins a room. /// </summary> public void OnJoinedRoom() { playersInRoom = new List<PhotonPlayer>(PhotonNetwork.playerList); myTeam = (TeamTypes)((playersInRoom.Count + 1) % 2); ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable(); properties.Add("Team", myTeam.GetHashCode()); properties.Add("Character", myCharacter.GetHashCode()); properties.Add("PlayFabID", PlayFabManager.instance.GetMyPlayerID()); bool containsOwner = false; for (int i = 0; i < PhotonNetwork.otherPlayers.Length; i++) { object ownerName; if (PhotonNetwork.otherPlayers[i].customProperties.TryGetValue("Owner", out ownerName)) { containsOwner = true; break; } } if (!containsOwner) { properties.Add("Owner", PhotonNetwork.player.name); } PhotonNetwork.player.SetCustomProperties(properties); myRoomInfo = PhotonNetwork.room; OnJoinedRoomCallback(PhotonNetwork.room); }
/// <summary> /// Rotates player between teams. /// </summary> public void ChangeTeam(TeamTypes newTeam, bool syncNetwork) { myTeam = newTeam; ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable(); properties.Add("Team", myTeam.GetHashCode()); PhotonNetwork.player.SetCustomProperties(properties); if (syncNetwork) { networkLayer.OnPropertiesChanged(); } }
/// <summary> /// Changes player avatar, to the one the player has chosen. /// </summary> /// <param name="myType">New character.</param> /// <param name="syncNetwork">If will send data to the network.</param> public void ChangePlayerAvatar(CharacterTypes myType, bool syncNetwork) { if (myCharacter != myType) { myCharacter = myType; ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable(); properties.Add("Character", myCharacter.GetHashCode()); PhotonNetwork.player.SetCustomProperties(properties); if (syncNetwork) { networkLayer.OnPropertiesChanged(); } } }
/// <summary> /// Updates player status to ready. /// </summary> public void SetReady() { ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable(); properties.Add("Ready", true); PhotonNetwork.player.SetCustomProperties(properties); networkLayer.OnPropertiesChanged(); }