//VARIABLE TRACKERS //THIS IS FOR NETWORKED VARIABLES. //Updates everything on the client //Probably quite the lag machine. (uses a lot of bandwidth D: ) public void SendAllVars(Photon.Realtime.Player client) { foreach (string variable in variables.Keys) { photonView.RPC("RPCAddVar", client, variable, variables[variable]); } }
void Update() { bool showInfo = !this.DisableOnOwnObjects || this.photonView.IsMine; if (textGo != null) { textGo.SetActive(showInfo); } if (!showInfo) { return; } Photon.Realtime.Player owner = this.photonView.Owner; if (owner != null) { // tm.text = (string.IsNullOrEmpty(owner.NickName)) ? "player"+owner.UserId : owner.NickName; displayName.text = (string.IsNullOrEmpty(owner.NickName)) ? "player" + owner.UserId : owner.NickName; } else if (this.photonView.IsSceneView) { // tm.text = "scn"; displayName.text = "scn"; } else { // tm.text = "n/a"; displayName.text = "n/a"; } }
/// <summary> /// Called when a remote player left the room. /// See the official Photon docs for more details. /// </summary> public override void OnPlayerLeftRoom(Photon.Realtime.Player player) { //only let the master client handle this connection if (!PhotonNetwork.IsMasterClient) { return; } //get player-controlled game object from disconnected player GameObject targetPlayer = GetPlayerGameObject(player); //process any collectibles assigned to that player if (targetPlayer != null) { Collectible[] collectibles = targetPlayer.GetComponentsInChildren <Collectible>(true); for (int i = 0; i < collectibles.Length; i++) { //let the player drop the Collectible PhotonNetwork.RemoveRPCs(collectibles[i].spawner.photonView); collectibles[i].spawner.photonView.RPC("Drop", RpcTarget.AllBuffered, targetPlayer.transform.position); } } //clean up instances after processing leaving player PhotonNetwork.DestroyPlayerObjects(player); //decrease the team fill for the team of the leaving player and update room properties PhotonNetwork.CurrentRoom.AddSize(player.GetTeam(), -1); }
void RPC_BroadcastDeath(Photon.Realtime.Player player1, Photon.Realtime.Player player2) { GameObject go = Instantiate(playerUI.killFeedListItem, playerUI.killFeedPanel.transform); go.GetComponent <TMP_Text>().text = player1.NickName + " killed " + player2.NickName; Destroy(go, 3f); }
public override void OnPlayerPropertiesUpdate(Photon.Realtime.Player target, ExitGames.Client.Photon.Hashtable changedProps) { foreach (var change in changedProps) { Debug.Log("Property " + change.Key + " of player " + target.UserId + " changed to " + change.Value); } }
public override void OnPlayerLeftRoom(Photon.Realtime.Player otherPlayer) { if (PhotonNetwork.CurrentRoom.PlayerCount == 1) { PhotonNetwork.Disconnect(); } }
public override void OnPlayerLeftRoom(Photon.Realtime.Player otherPlayer) { if (PhotonNetwork.IsMasterClient) { NotificationManager.instance.NewNotification("<color=red>" + otherPlayer.NickName + "</color> has left the hub."); } }
public override void OnPlayerLeftRoom(Photon.Realtime.Player otherPlayer) { base.OnPlayerLeftRoom(otherPlayer); playersInRoom--; //Debug.Log(otherPlayer.NickName + " has left the game"); if (!isGameStarted) { PhotonNetwork.CurrentRoom.IsOpen = true; roomStatusText.text = "<style=\"C1\">" + otherPlayer.NickName + " has left the room [" + playersInRoom + "/" + Consts.GAME_SIZE + "]</style>"; ClearPlayerListings(); ListPlayers(); startButton.SetActive(PhotonNetwork.IsMasterClient && Consts.GAME_SIZE > 2); if (playersInRoom == 1) { SetRoomDefaults(); } } else { // TODO Show message in game if (playersInRoom == 1) { lobbyStatusText.text = "<style=\"C2\">Not enought players to continue the game.</style>"; //Disconnect(); PhotonNetwork.LeaveRoom(); } } }
void OnPhotonPlayerDisconnected(Photon.Realtime.Player player) { if (SceneManager.GetActiveScene().name.Contains("_GameScene_")) { Networking.instance.photonView.RPC("RPCConnectionLossScreen", RpcTarget.All, "Player " + player.NickName + " lost connection or ragequitted. You win :( We are very sorry for that!"); } }
private void AddClientItem(Photon.Realtime.Player player) { ClientItem newClientItem = Instantiate(clientItemPrefab, transform).GetComponent <ClientItem>(); players.Add(player); clientItems.Add(player, newClientItem); }
public override void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer) { base.OnPlayerEnteredRoom(newPlayer); //Debug.Log("A new player has joined the room"); ClearPlayerListings(); ListPlayers(); photonPlayers = PhotonNetwork.PlayerList; playersInRoom++; //Debug.Log("Displayer player in room out of max players possible (" + playersInRoom + "/" + Consts.GAME_SIZE + ")"); roomStatusText.text = "<style=\"C1\">A new player has joined the room [" + playersInRoom + "/" + Consts.GAME_SIZE + "]</style>"; if (playersInRoom == Consts.GAME_SIZE) { SetStartingTimer(true); if (!PhotonNetwork.IsMasterClient) { return; } PhotonNetwork.CurrentRoom.IsOpen = false; } }
public override void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer) { if (PhotonNetwork.CurrentRoom.PlayerCount == 2) { SceneManager.LoadScene("Battle"); } }
public override void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer) { if (activeBounty != null) { photonView.RPC("SyncActiveBounty", RpcTarget.All, activeBounty.bountyName, activeBounty.progress); } }
// IInRoomCallbacks methods public override void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer) { base.OnPlayerEnteredRoom(newPlayer); // Instatiate a player Player.RefreshInstance(ref localPlayer, playerPrefab); }
/// <summary> /// Room callbacks /// </summary> /// <param name="newPlayer"></param> public void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer) { foreach (var cb in iConnectionEvents) { cb.OnServerConnect(newPlayer, newPlayer.ActorNumber); } foreach (var cb in iOnServerConnect) { cb.OnServerConnect(newPlayer, newPlayer.ActorNumber); } if (onServerConnectCallback != null) { onServerConnectCallback.Invoke(newPlayer, newPlayer.ActorNumber); } foreach (var cb in iConnectionEvents) { cb.OnClientConnect(newPlayer, newPlayer.ActorNumber); } foreach (var cb in iOnClientConnect) { cb.OnClientConnect(newPlayer, newPlayer.ActorNumber); } if (onClientConnectCallback != null) { onClientConnectCallback.Invoke(newPlayer, newPlayer.ActorNumber); } }
public override void OnPlayerLeftRoom(Photon.Realtime.Player otherPlayer) { Destroy(playerListEntries[otherPlayer.ActorNumber].gameObject); playerListEntries.Remove(otherPlayer.ActorNumber); StartGameButton.gameObject.SetActive(CheckPlayersReady()); }
public void OnPlayerLeftRoom(Photon.Realtime.Player otherPlayer) { foreach (var cb in iConnectionEvents) { cb.OnServerDisconnect(otherPlayer, otherPlayer.ActorNumber); } foreach (var cb in iOnServerDisconnect) { cb.OnServerDisconnect(otherPlayer, otherPlayer.ActorNumber); } if (onServerDisconnectCallback != null) { onServerDisconnectCallback.Invoke(otherPlayer, otherPlayer.ActorNumber); } foreach (var cb in iConnectionEvents) { cb.OnClientDisconnect(otherPlayer, otherPlayer.ActorNumber); } foreach (var cb in iOnClientDisconnect) { cb.OnClientDisconnect(otherPlayer, otherPlayer.ActorNumber); } if (onClientDisconnectCallback != null) { onClientDisconnectCallback.Invoke(otherPlayer, otherPlayer.ActorNumber); } }
public override void OnMasterClientSwitched(Photon.Realtime.Player newMasterClient) { if (PhotonNetwork.LocalPlayer.ActorNumber == newMasterClient.ActorNumber) { StartGameButton.gameObject.SetActive(CheckPlayersReady()); } }
public override void OnPlayerPropertiesUpdate(Photon.Realtime.Player targetPlayer, Hashtable changedProps) { if (changedProps.ContainsKey("score")) { CheckEndOfGame(); } }
public override void OnPlayerLeftRoom(Photon.Realtime.Player otherPlayer) { base.OnPlayerLeftRoom(otherPlayer); instructionText.text = ""; kickObject.SetActive(true); StartCoroutine(KickPlayer()); }
void Die(Photon.Realtime.Player player) { IncreaseKillsOrDeathsPlayerCustomProps(player, "kills"); IncreaseKillsOrDeathsPlayerCustomProps(PhotonNetwork.LocalPlayer, "deaths"); PV.RPC("RPC_BroadcastDeath", RpcTarget.All, player, PhotonNetwork.LocalPlayer); playerManager.Respawn(); }
public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps) { if (changedProps != null && changedProps.ContainsKey(PlayerNumbering.RoomPlayerIndexedProp)) { this.RefreshData(); } }
public void OnOwnershipTransfered(PhotonView targetView, Photon.Realtime.Player previousOwner) { Debug.Log("Is this mine? " + targetView.IsMine); Debug.Log("Current item = " + currentHeldItem); if (!targetView.IsMine) { return; } // this does the same logic as the pickup function however it is only called when the player is picking up an object that the player was not an owner of if (currentHeldItem != null) { if (currentHeldItem.tag == "Gun") { currentHeldItem.transform.GetChild(17).GetChild(0).gameObject.SetActive(true); GetComponent <IkBehaviour>().ikActive = true; GetComponent <IkBehaviour>().handObj = currentHeldItem.transform.GetChild(18); } else if (currentHeldItem.tag == "Rock") { GetComponent <IkBehaviour>().ikActive = true; GetComponent <IkBehaviour>().handObj = currentHeldItem.transform.GetChild(0).transform.GetChild(2); actualCamera.transform.GetChild(0).gameObject.SetActive(true); } } else { return; } photonView.RPC("PickUpRPC", RpcTarget.Others, currentHeldItem.transform.GetComponent <PhotonView>().ViewID); photonView.RPC("PickUpRPCLocal", PhotonNetwork.LocalPlayer, currentHeldItem.transform.GetComponent <PhotonView>().ViewID); }
/// <summary> /// Sets the player number. /// It's not recommanded to manually interfere with the playerNumbering, but possible. /// </summary> /// <param name="player">Player.</param> /// <param name="playerNumber">Player number.</param> public static void SetPlayerNumber(this Player player, int playerNumber) { if (player == null) { return; } if (PhotonNetwork.OfflineMode) { return; } if (playerNumber < 0) { Debug.LogWarning("Setting invalid playerNumber: " + playerNumber + " for: " + player.ToStringFull()); } if (!PhotonNetwork.IsConnectedAndReady) { Debug.LogWarning("SetPlayerNumber was called in state: " + PhotonNetwork.NetworkClientState + ". Not IsConnectedAndReady."); return; } int current = player.GetPlayerNumber(); if (current != playerNumber) { Debug.Log("PlayerNumbering: Set number " + playerNumber); player.SetCustomProperties(new Hashtable() { { PlayerNumbering.RoomPlayerIndexedProp, (byte)playerNumber } }); } }
/// <summary> /// Each player has number as ID <1,4> /// if pPhotonPlayer is null it will be determined in SetType /// </summary> public void Init(int pPlayerNumber, EPlayerType pPlayerType, PhotonPlayer pPhotonPlayer) { PreInit(); gameObject.SetActive(true); brainiacs.GameInitInfo.AddPlayer(Info); Info.PhotonPlayer = pPhotonPlayer; Info.Number = pPlayerNumber; AssignColor((EPlayerColor)pPlayerNumber); SetName("player " + pPlayerNumber); SetType(pPlayerType); //if photon player is set then element is being //initialized at client bool elementCreated = pPhotonPlayer == null; //OnElementChanged(elementCreated); if (DebugData.TestHero != EHero.None) { heroSwapper.SetValue((int)DebugData.TestHero); } }
public override void OnPlayerEnteredRoom(Photon.Realtime.Player otherPlayer) { if (PhotonNetwork.IsMasterClient) { //LoadArena(); } }
internal void OnRemotePlayerLoadedScene(PhotonPlayer pPlayer) { Debug.Log("OnRemotePlayerLoadedScene" + pPlayer); loadedPlayers.Add(pPlayer); foreach (var player in brainiacs.GameInitInfo.Players) { var foundPlayer = loadedPlayers.Find(a => a.ActorNumber == player.PhotonPlayer.ActorNumber); if (foundPlayer == null) { Debug.Log("Not all players loaded yet"); return; } } Debug.Log("All players loaded"); //map has to be activated first //player objects spawn only on master if (isMultiplayer && !PhotonNetwork.IsMasterClient) { Debug.Log("Not MasterClient => dont spawn"); return; } game.Map.SetOnActivated(() => SpawnPlayers(brainiacs.GameInitInfo.Players)); }
public virtual void RemovePlayer(Photon.Realtime.Player player) { if (data.Find(x => x.userId == player.UserId) != null) { data.Remove(data.Find(x => x.userId == player.UserId)); } }
/// <summary> /// Finds the remotely controlled Player game object of a specific player, /// by iterating over all Player components and searching for the matching creator. /// </summary> public GameObject GetPlayerGameObject(Photon.Realtime.Player player) { GameObject[] rootObjs = SceneManager.GetActiveScene().GetRootGameObjects(); List <Player> playerList = new List <Player>(); //get all Player components from root objects for (int i = 0; i < rootObjs.Length; i++) { Player p = rootObjs[i].GetComponentInChildren <Player>(true); if (p != null) { playerList.Add(p); } } //find the game object where the creator matches this specific player ID for (int i = 0; i < playerList.Count; i++) { if (playerList[i].photonView.CreatorActorNr == player.ActorNumber) { return(playerList[i].gameObject); } } return(null); }
private void Start() { OriginalOwner = photonView.Owner; lineRenderer = GetComponent <LineRenderer>(); stringBuilder = new StringBuilder(); }