我正在尝试创建一个房间 UI。我建立了一个副本来测试我是否能看到任何房间。但是,它没有收到任何房间。这是我的代码:
public class NetworkManager : Photon.MonoBehaviour
{
public GameObject ScrollViewContent;
public GameObject RoomListItem;
public Text RoomNameInputField;
void Start()
{
PhotonNetwork.ConnectUsingSettings("0.1");
}
void OnReceivedRoomListUpdate()
{
Debug.Log("OnReceivedRoomListUpdate");
}
void OnGUI()
{
Debug.Log("OnGUI");
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
if (ScrollViewContent != null)
{
Debug.Log("ScrollViewContent");
foreach (Transform child in ScrollViewContent.transform)
{
Debug.Log("Destroy");
Destroy(child.gameObject);
}
foreach (RoomInfo game in PhotonNetwork.GetRoomList())
{
Debug.Log("RoomInfo");
GameObject room = Instantiate(RoomListItem) as GameObject;
room.GetComponentInChildren<Text>().text = game.name;
room.transform.SetParent(ScrollViewContent.transform);
}
Debug.Log("ScrollViewContentEnd");
}
}
public void CreateRoom()
{
if (!string.IsNullOrEmpty(RoomNameInputField.text))
PhotonNetwork.CreateRoom(RoomNameInputField.text);
//PhotonNetwork.CreateRoom(RoomNameInputField.text, new RoomOptions() { maxPlayers = 2,isVisible=true }, null);
}
}
所有公共变量都是通过检查器设置的,控制台显示“ScrollViewContent”和“ScrollViewContentEnd”,这意味着它们之间应该没有异常。
我尝试了两种创建房间的方法(两种方法都可以成功创建房间)并将 OnGUI() 代码放在 OnReceivedRoomListUpdate() 中。但是,什么都没有出现,甚至控制台中的“RoomInfo”也没有。
代码中是否遗漏了什么?