Photonnetwork

Posted on  by 



Jun 1st, 2019
Never
Photonnetwork
Not a member of Pastebin yet?Sign Up, it unlocks many cool features!

Become any tier member on my Patreon below for the source files!Would you like to help me grow? There are a variety of ways you can support me here: http://f. How to make a Multiplayer Video Games in Unity using the Photon 2 pluginPhoton Documentaiton: https://doc.photonengine.com/en-us/pun/v2/getting-started/pun-i. PhotonNetwork.autoJoinLobby = false; // #Critical // this makes sure we can use PhotonNetwork.LoadLevel on the master client and all clients in the same room sync their level automatically PhotonNetwork.automaticallySyncScene = true; /// /// MonoBehaviour method called on GameObject by Unity during initialization phase. PhotonNetwork.playerName = MainMenu.nickName; We want to display the name of other players in the game above their tanks, so to do this I’ve added a canvas and UIText object to the player prefab to act as a name label.

Get the Photon Friend List package from Lovatto Studio and speed up your game development process. Find this & other Network options on the Unity Asset Store.

  1. using Photon.Realtime;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerListingsMenu : MonoBehaviourPunCallbacks, IConnectionCallbacks
  5. [SerializeField]
  6. private PlayerListing _playerListing;
  7. [SerializeField]
  8. private List<PlayerListing> _Listings = new List<PlayerListing>();
  9. private bool _ready = false;
  10. public void FirstInitialize(RoomsCanvases canvases)
  11. _roomsCanvases = canvases;
  12. {
  13. }
  14. private void SetReadyUp(bool state)
  15. _ready = state;
  16. {
  17. }
  18. {
  19. }
  20. }
  21. public override void OnLeftRoom()
  22. _content.DestroyChildren();
  23. {
  24. {
  25. }
  26. if (PhotonNetwork.CurrentRoom null || PhotonNetwork.CurrentRoom.Players null)
  27. return;
  28. foreach (KeyValuePair<int, Player> playerInfo in PhotonNetwork.CurrentRoom.Players)
  29. AddPlayerListing(playerInfo.Value);
  30. }
  31. private void AddPlayerListing(Player player)
  32. {
  33. if (child.gameObject.GetComponent<PlayerListing>()._text.text.Equals(player.NickName))
  34. return;
  35. }
  36. PlayerListing listing = Instantiate(_playerListing, _content);
  37. if (listing != null)
  38. listing.SetPlayerInfo(player);
  39. _Listings.Add(listing);
  40. }
  41. ReorderPlayers();
  42. public override void OnMasterClientSwitched(Player newMasterClient)
  43. _roomsCanvases.CurrentRoomCanvas.LeaveRoomMenu.OnClick_LeaveRoom();
  44. public override void OnPlayerEnteredRoom(Player newPlayer)
  45. AddPlayerListing(newPlayer);
  46. public override void OnPlayerLeftRoom(Player otherPlayer)
  47. int index = _Listings.FindIndex(x => x.Player otherPlayer);
  48. {
  49. _Listings.RemoveAt(index);
  50. }
  51. private void ReorderPlayers()
  52. List<Transform> _ToReorder = new List<Transform>();
  53. foreach (Transform child in _content)
  54. _ToReorder.Add(child);
  55. List<Transform> _ToReorder2 =_ToReorder.OrderBy(o=>o.gameObject.gameObject.GetComponent<PlayerListing>()._text.text).ToList();
  56. int I = 0;
  57. foreach (Transform transformInList in _ToReorder2)
  58. transformInList.SetSiblingIndex(I);
  59. }
  60. }
  61. public void OnClick_StartGame()
  62. if (PhotonNetwork.IsMasterClient)
  63. for (int i = 0; i < _Listings.Count; i++)
  64. if (_Listings[i].Player != PhotonNetwork.LocalPlayer)
  65. if (!_Listings[i].Ready)
  66. return;
  67. }
  68. PhotonNetwork.CurrentRoom.IsVisible = false;
  69. }
  70. public void OnClick_ReadyUp()
  71. if (!PhotonNetwork.IsMasterClient)
  72. SetReadyUp(!_ready);
  73. base.photonView.RPC('RPC_ChangeReadyState',RpcTarget.MasterClient, PhotonNetwork.LocalPlayer, _ready);
  74. //base.photonView.RpcSecure('RPC_ChangeReadyState',RpcTarget.MasterClient, true, PhotonNetwork.LocalPlayer, _ready);
  75. }
  76. [PunRPC]
  77. private void RPC_ChangeReadyState(Player player, bool ready)
  78. int index = _Listings.FindIndex(x => x.Player player);
  79. {
  80. }
  81. }
RAW Paste Data

Photon Pun2





Coments are closed