-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoomManagement Unity Proton
More file actions
69 lines (59 loc) · 1.75 KB
/
RoomManagement Unity Proton
File metadata and controls
69 lines (59 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
public class RoomManagement : MonoBehaviourPunCallbacks
{
public TMP_InputField CreateServerName;
public TMP_InputField JoinServerName;
public TextMeshProUGUI MSGText;
public TextMeshProUGUI CreateServerFailed;
public TextMeshProUGUI JoinServerFailed;
public void CreateRoom()
{
if (CreateServerName.text != null && CreateServerName.text != "Room Name")
/*This allows the game to create a new room, the user inputs a name to*/
{
RoomOptions rOption = new RoomOptions();
rOption.MaxPlayers = 2;
PhotonNetwork.CreateRoom(CreateServerName.text, rOption);
Debug.Log(CreateServerName.text);
}
else
{
MSGText.text = "Please input a valid Server Name!";
}
}
public void JoinRoom()
{
if (JoinServerName.text != null && JoinServerName.text != "Room Name")
/*Checks against the server list, finds the name in the array and then joins or throws an error.*/
{
PhotonNetwork.JoinRoom(JoinServerName.text);
Debug.Log("Joining Room...");
}
else
{
MSGText.text = "Please input a valid Server Name!";
}
}
public override void OnJoinedRoom()
{
PhotonNetwork.LoadLevel(2);
base.OnJoinedRoom();
}
public override void OnCreateRoomFailed(short returnCode, string message)
{
message = CreateServerFailed.text;
CreateServerFailed.text = "Creation of room has failed. Please try again.";
base.OnCreateRoomFailed(returnCode, message);
Debug.Log(message);
}
public override void OnJoinRoomFailed(short returnCode, string message)
{
message = JoinServerFailed.text;
JoinServerFailed.text = "Room either doesnt exist or there are interruptions. Please try again.";
base.OnCreateRoomFailed(returnCode, message);
Debug.Log(message);
}
}