diff options
Diffstat (limited to 'GameCode/NetworkData.cs')
-rw-r--r-- | GameCode/NetworkData.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/GameCode/NetworkData.cs b/GameCode/NetworkData.cs new file mode 100644 index 0000000..293da46 --- /dev/null +++ b/GameCode/NetworkData.cs @@ -0,0 +1,58 @@ +using Photon.Pun; +using UnityEngine; + +public class NetworkData : MonoBehaviour +{ + private PhotonView photonView; + + private bool inited; + + private void Start() + { + photonView = GetComponent<PhotonView>(); + } + + private void Init() + { + if (!inited) + { + inited = true; + if (PhotonNetwork.IsMasterClient) + { + Debug.Log("Why am i the master?"); + } + } + } + + private void Update() + { + if (PhotonNetwork.InRoom) + { + Init(); + } + } + + private void RequestJoin() + { + photonView.RPC("RequestJoinMaster", RpcTarget.MasterClient); + Debug.Log("Request join"); + } + + [PunRPC] + public void RequestJoinMaster() + { + string text = JsonUtility.ToJson(new InitPackage + { + currentMapID = MapManager.instance.currentLevelID + }); + photonView.RPC("RequestJoinResponse", RpcTarget.Others, text); + } + + [PunRPC] + public void RequestJoinResponse(string jsonResponse) + { + InitPackage initPackage = (InitPackage)JsonUtility.FromJson(jsonResponse, typeof(InitPackage)); + MapManager.instance.LoadLevelFromID(initPackage.currentMapID, onlyMaster: false, callInImidetly: true); + Debug.Log("Got response"); + } +} |