init
This commit is contained in:
60
Assets/Scripts/MultiplayerManager.cs
Normal file
60
Assets/Scripts/MultiplayerManager.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Photon.Pun;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class MultiplayerManager : MonoBehaviourPunCallbacks
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
private static string _uid = "";
|
||||
|
||||
public static MultiplayerManager instance;
|
||||
|
||||
public bool isVR = false;
|
||||
|
||||
public static string uid { get {
|
||||
if(_uid == "")
|
||||
{
|
||||
char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray();
|
||||
|
||||
while(_uid.Length < 6)
|
||||
{
|
||||
_uid += chars[Random.Range(0, chars.Length)];
|
||||
}
|
||||
Debug.Log("New uid: " + _uid);
|
||||
}
|
||||
return _uid; } }
|
||||
void Awake()
|
||||
{
|
||||
if(instance != null) { Destroy(gameObject); return; }
|
||||
instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
PhotonNetwork.ConnectUsingSettings();
|
||||
|
||||
}
|
||||
|
||||
public override void OnConnectedToMaster()
|
||||
{
|
||||
base.OnConnectedToMaster();
|
||||
|
||||
Debug.Log("Connected to photon");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
public void ConnectToAdmin()
|
||||
{
|
||||
PhotonNetwork.CreateRoom(uid);
|
||||
}
|
||||
|
||||
public override void OnCreatedRoom()
|
||||
{
|
||||
base.OnCreatedRoom();
|
||||
Debug.Log("New room created : " + uid);
|
||||
MPChat.isAdmin = false;
|
||||
PhotonNetwork.LoadLevel(isVR ? "ADMIN_MP_VR" : "ADMIN_MP");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user