75 lines
1.8 KiB
C#
75 lines
1.8 KiB
C#
using Photon.Pun;
|
|
using Photon.Realtime;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AdminLobby : MonoBehaviourPunCallbacks, ILobbyCallbacks
|
|
{
|
|
|
|
public GameObject listItemPrefab;
|
|
public Transform parent;
|
|
|
|
public static AdminLobby instance;
|
|
|
|
void Awake()
|
|
{
|
|
if(instance != null) { Destroy(gameObject); return; }
|
|
|
|
instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
PhotonNetwork.Disconnect();
|
|
PhotonNetwork.ConnectUsingSettings();
|
|
}
|
|
|
|
public override void OnConnectedToMaster()
|
|
{
|
|
base.OnConnectedToMaster();
|
|
Debug.Log("Connected to photon");
|
|
PhotonNetwork.JoinLobby();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public override void OnRoomListUpdate(List<RoomInfo> roomList)
|
|
{
|
|
base.OnRoomListUpdate(roomList);
|
|
|
|
//PURGE
|
|
foreach(Transform child in parent.GetComponentsInChildren<Transform>())
|
|
{
|
|
if(child == parent) { continue; }
|
|
|
|
Destroy(child.gameObject);
|
|
}
|
|
RoomInfo _room;
|
|
foreach(RoomInfo room in roomList)
|
|
{
|
|
GameObject newItem = Instantiate(listItemPrefab, parent);
|
|
_room = room;
|
|
newItem.GetComponentInChildren<Text>().text = room.Name;
|
|
newItem.GetComponentInChildren<Button>().onClick.AddListener(() => JoinRoom(_room.Name));
|
|
}
|
|
}
|
|
|
|
|
|
void JoinRoom(string roomName)
|
|
{
|
|
PhotonNetwork.JoinRoom(roomName);
|
|
PhotonNetwork.LoadLevel("ADMIN_CHAT");
|
|
|
|
//PhotonNetwork.Instantiate("Communicator", Vector3.zero, Quaternion.identity);
|
|
}
|
|
|
|
public override void OnJoinedRoom()
|
|
{
|
|
base.OnJoinedRoom();
|
|
Debug.Log("Joined success");
|
|
}
|
|
}
|