SHARE
TWEET

Untitled

a guest Jul 24th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MatchMaker : Photon.PunBehaviour
  2. {
  3.     [SerializeField]
  4.     private PhotonLogLevel LogLevel = PhotonLogLevel.Informational;
  5.     [SerializeField]
  6.     private byte MaxPlayersPerRoom = 4;
  7.  
  8.     private const string gameVersion = "1.0";
  9.     private bool isConnecting;
  10.  
  11.     private void Awake()
  12.     {
  13.         PhotonNetwork.logLevel = LogLevel;
  14.         PhotonNetwork.automaticallySyncScene = true;
  15.     }
  16.  
  17.     private void Start()
  18.     {
  19.         Connect();
  20.     }
  21.  
  22.     public void Connect()
  23.     {
  24.         isConnecting = true;
  25.         PhotonNetwork.ConnectUsingSettings(gameVersion);
  26.     }
  27.  
  28.     #region Photon.PunBehaviour Callbacks
  29.     public override void OnConnectedToMaster()
  30.     {
  31.         Debug.Log($"{nameof(MatchMaker)}.OnConnectedToMaster() was called by PUN");
  32.  
  33.         if (isConnecting)
  34.         {
  35.             PhotonNetwork.JoinOrCreateRoom("MyRoom", new RoomOptions() { MaxPlayers = MaxPlayersPerRoom }, null);
  36.         }
  37.     }
  38.        
  39.     public override void OnLeftRoom()
  40.     {
  41.         isConnecting = false;
  42.     }
  43.  
  44.     public override void OnConnectionFail(DisconnectCause cause)
  45.     {
  46.         Debug.Log($"Connection failed: {cause}");
  47.         isConnecting = false;
  48.     }
  49.  
  50.     public override void OnConnectedToPhoton()
  51.     {
  52.         Debug.Log("Connected to Photon");
  53.     }
  54.  
  55.     public override void OnDisconnectedFromPhoton()
  56.     {
  57.         Debug.Log($"{nameof(MatchMaker)}.OnDisconnectedFromPhoton() was called by PUN");
  58.     }
  59.  
  60.     public override void OnJoinedRoom()
  61.     {
  62.         Debug.Log($"{nameof(MatchMaker)}.OnJoinedRoom() was called by PUN");
  63.     }
  64.     #endregion
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top