gpt4 book ai didi

photon OnRoomListUpdate(Photon OnRoomListUp更新)

转载 作者:bug小助手 更新时间:2023-10-26 20:05:01 30 4
gpt4 key购买 nike



I am making room List system in photon, but

我正在制作PHOTON的房间列表系统,但是


public override void OnRoomListUpdate(List<RoomInfo> roomList)

This command doesn't work well. How can I fix it?

这个命令不太好用。我该怎么补救?


<PhotonManager.cs>


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;
using TMPro;

public class PhotonManager : MonoBehaviourPunCallbacks
{
private readonly string gameVersion = "v1.0";
private string userID = "igw";

public TMP_InputField userIDText;
public TMP_InputField roomNameText;

private Dictionary<string,GameObject> roomDict=new Dictionary<string, GameObject>();

public GameObject roomPrefab;
public Transform scrollContent;

public Text PhotonMessage;

public LobbyManager LobbyManager;

private void Awake()
{
PhotonNetwork.AutomaticallySyncScene = true;
PhotonNetwork.SendRate = 60;
PhotonNetwork.SerializationRate = 30;
PhotonNetwork.GameVersion=gameVersion;
PhotonNetwork.ConnectUsingSettings();
}

private void Start()
{
userID = PlayerPrefs.GetString("USER_ID", $"USER_{Random.Range(0, 100):00}");
userIDText.text = userID;
PhotonNetwork.NickName=userID;
}
public override void OnConnectedToMaster()
{
PhotonMessage.color = Color.white;
PhotonMessage.text = "Connected Server";
PhotonNetwork.JoinLobby();
}

public override void OnJoinedLobby()
{
PhotonMessage.color = Color.white;
PhotonMessage.text = "Joined Lobby";
}

public override void OnJoinRandomFailed(short returnCode, string message)
{
PhotonMessage.color = Color.red;
PhotonMessage.text = "Failed to Join";

RoomOptions ro=new RoomOptions();
ro.IsOpen = true;
ro.IsVisible = true;
ro.MaxPlayers = LobbyManager.MaxPlayerNum;

roomNameText.text = $"Room_{Random.Range(1, 100):000}";

PhotonNetwork.CreateRoom("room_1", ro);
}

public override void OnCreatedRoom()
{
PhotonMessage.color = Color.white;
PhotonMessage.text = "Created Room";
}

public override void OnJoinedRoom()
{
PhotonMessage.color = Color.white;
PhotonMessage.text = "Joined Room";
//PhotonNetwork.LoadLevel(1);
}
public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
Debug.Log("Update!");
GameObject tempRoom = null;
foreach (var room in roomList)
{
if (room.RemovedFromList == true)
{
roomDict.TryGetValue(room.Name, out tempRoom);
Destroy(tempRoom);
roomDict.Remove(room.Name);
}
else
{
if (roomDict.ContainsKey(room.Name) == false)
{
GameObject _room = Instantiate(roomPrefab, scrollContent);
_room.GetComponent<RoomData>().RoomInfo = room;
roomDict.Add(room.Name, _room);
}
else
{
roomDict.TryGetValue(room.Name, out tempRoom);
tempRoom.GetComponent<RoomData>().RoomInfo = room;
}
}
}
}

#region UI_BUTTON_CALLBACK

public void OnRandomBtn()
{
if (string.IsNullOrEmpty(userIDText.text))
{
userID = $"USER_{Random.Range(0, 100):00}";
userIDText.text=userID;
}

PlayerPrefs.SetString("USER_ID",userIDText.text);
PhotonNetwork.NickName=userIDText.text;
PhotonNetwork.JoinRandomRoom();
}

public void onMakeRoomClick()
{
RoomOptions ro=new RoomOptions();
ro.IsOpen = true;
ro.IsVisible = true;
ro.MaxPlayers = LobbyManager.MaxPlayerNum;

if (string.IsNullOrEmpty(roomNameText.text))
{
roomNameText.text = $"ROOM_{Random.Range(1, 100):000}";
}
PhotonNetwork.CreateRoom(roomNameText.text,ro);
}

#endregion


}

<RoomData.cs>


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using System.Xml.Serialization;
using Photon.Pun.Demo.Cockpit;

public class RoomData : MonoBehaviour
{
public TMP_Text RoomInfoText;
private RoomInfo _roomInfo;

public TMP_InputField NicknameText;
public LobbyManager LobbyManager;

public RoomInfo RoomInfo
{
get
{
return _roomInfo;
}
set
{
_roomInfo = value;
RoomInfoText.text = $"{_roomInfo.Name} ({_roomInfo.PlayerCount}/{_roomInfo.MaxPlayers})";
GetComponent<UnityEngine.UI.Button>().onClick.AddListener(()=>OnEnterRoom(_roomInfo.Name));
}
}

private void Awake()
{
LobbyManager = GameObject.Find("LobbyManager").GetComponent<LobbyManager>();
NicknameText = GameObject.Find("NicmnameINP").GetComponent<TMP_InputField>();
}

public void OnEnterRoom(string roomName)
{
RoomOptions ro=new RoomOptions();
ro.IsOpen = true;
ro.IsVisible = true;
ro.MaxPlayers = LobbyManager.MaxPlayerNum;
PhotonNetwork.NickName=NicknameText.text;
PhotonNetwork.JoinOrCreateRoom(roomName, ro,TypedLobby.Default);
}
}

<LobbyManager.cs>


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LobbyManager : MonoBehaviour
{
public GameObject PopUp;
public int MaxPlayerNum;
public Text PlayerNumText;

private void Start()
{
PopUp.SetActive(false);
MaxPlayerNum = 2;
PlayerNumText.text = "2";
}

public void PlayerUpbtn()
{
if (MaxPlayerNum < 6)
{
MaxPlayerNum++;
PlayerNumText.text = MaxPlayerNum.ToString();
}
}
public void PlayerDownbtn()
{
if(MaxPlayerNum > 2)
{
MaxPlayerNum--;
PlayerNumText.text = MaxPlayerNum.ToString();
}
}
public void PopUpbtn()
{
PopUp.SetActive(true);
}
public void ClosePopUpbtn()
{
PopUp.SetActive(false);
}
}

public override void OnRoomListUpdate(List<RoomInfo> roomList)

this command worked Only when I first enter the lobby.

这个命令只有在我第一次进入大堂时才起作用。


when I create a room in development Build, this command not worked

当我在开发版本中创建文件室时,此命令不起作用


更多回答

+ PhotonNetwork.JoinRandomRoom(); is not working too. I think photon doesn't seem to recognize the room

+ PhotonNetwork.JoinRandomRoom();也不工作。我觉得光子好像不认识这个房间

优秀答案推荐
更多回答

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com