-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNetworkScript.cs
118 lines (105 loc) · 3.08 KB
/
NetworkScript.cs
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using TMPro;
using System;
public class NetworkScript : MonoBehaviourPunCallbacks
{
public TMP_InputField CreateCodeInput;
public TMP_InputField JoinCodeInput;
public TMP_InputField PlayerNameInput;
public TMP_InputField ChatInput;
public TMP_Text JoinCodeDisplay;
public GameObject MainMenuCanvas;
public GameObject GameCanvas;
public GameObject LoadingScreen;
public GameObject Screen0;
public GameObject PlayerPrefab;
public Transform StartPosition;
public static TMP_InputField CheckChatBox;
public static string playerName = " player ";
public static string message = "";
public static bool IsChatBubble = false;
public static bool IsInRoom = false;
string joinCode;
// Start is called before the first frame update
void Start()
{
CheckChatBox = ChatInput;
MainMenuCanvas.SetActive(true);
ChatInput.gameObject.SetActive(false);
GameCanvas.SetActive(false);
LoadingScreen.SetActive(true);
Screen0.SetActive(false);
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
LoadingScreen.SetActive(false);
Screen0.SetActive(true);
}
public void CreateRoom()
{
LoadingScreen.SetActive(true);
Screen0.SetActive(false);
joinCode = CreateCodeInput.text;
PhotonNetwork.CreateRoom(joinCode);
}
public void JoinRoom()
{
LoadingScreen.SetActive(true);
Screen0.SetActive(false);
joinCode = JoinCodeInput.text;
PhotonNetwork.JoinRoom(joinCode);
}
public override void OnJoinedRoom()
{
IsInRoom = true;
LoadingScreen.SetActive(false);
MainMenuCanvas.SetActive(false);
GameCanvas.SetActive(true);
JoinCodeDisplay.text = "Join Code: " + joinCode;
playerName = PlayerNameInput.text;
PhotonNetwork.Instantiate(PlayerPrefab.name, StartPosition.position, StartPosition.rotation);
}
public void getMessage()
{
message = ChatInput.text;
IsChatBubble = true;
ChatInput.text = "";
ChatInput.gameObject.SetActive(false);
}
public void LeaveRoom()
{
PhotonNetwork.LeaveRoom();
GameCanvas.SetActive(false);
MainMenuCanvas.SetActive(true);
LoadingScreen.SetActive(true);
}
public override void OnLeftRoom()
{
base.OnLeftRoom();
IsInRoom = false;
LoadingScreen.SetActive(false);
Screen0.SetActive(true);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Q) && IsInRoom)
{
ChatInput.gameObject.SetActive(true);
ChatInput.Select();
ChatInput.ActivateInputField();
}
if (Input.GetKeyDown(KeyCode.E) && !ChatInput.isFocused && IsInRoom)
{
LeaveRoom();
}
}
}