为什么在大厅中找不到光子房间的属性?
玩家可以创建一个具有某些属性的房间,这些属性曾经创建,我将其设置为大厅,以便我可以在大厅中显示它们。
创建房间的功能:
public void OnCreateRoomButtonClicked()
{
RoomOptions roomOptions = new RoomOptions();
roomOptions.IsOpen = true;
roomOptions.IsVisible = true;
string roomName;
string gameMap;
if (gameMode.Equals("CarMeeting"))
{
gameMap = carMeetingModeMaps[mapIndex].sceneName;
roomName = roomNameCarMeetingModeInputField.text;
roomOptions.MaxPlayers = 4;
}
else
{
gameMap = racingModeMaps[mapIndex].sceneName;
roomName = roomNameRacingModeInputField.text;
roomOptions.MaxPlayers = 2;
}
if (!CheckIfRoomAlreadyExists(roomName))
{
StartCoroutine(EShowWarning());
}
else
{
roomOptions.CustomRoomProperties = new Hashtable();
roomOptions.CustomRoomProperties.Add("GameMap", gameMap);
roomOptions.CustomRoomProperties.Add("GameMode", gameMode);
roomOptions.CustomRoomProperties.Add("RaceMode", raceMode);
roomOptions.CustomRoomProperties.Add("InRace", false);
string[] customLobbyProperties = new string[4];
customLobbyProperties[0] = "GameMap";
customLobbyProperties[1] = "GameMode";
customLobbyProperties[2] = "RaceMode";
customLobbyProperties[3] = "InRace";
roomOptions.CustomRoomPropertiesForLobby = customLobbyProperties;
PhotonNetwork.CreateRoom(roomName, roomOptions, null, null);
}
}
功能在大厅中显示房间:
public override void OnRoomListUpdate(List<RoomInfo> roomInfo)
{
Debug.Log("Rooms found " + roomInfo.Count);
bool roomFound = false;
foreach (RoomInfo room in roomInfo)
{
if (room.RemovedFromList)
{
int index = roomUIs.FindIndex(x => x.roomNameString.Equals(room.Name));
if (index != -1)
{
Destroy(roomUIs[index].gameObject);
roomUIs.RemoveAt(index);
}
}
else
{
CMRoomUI cacheRoomUI = roomUIs.Find(x => x.roomNameString.Equals(room.Name));
if (cacheRoomUI != null)
{
if (room.CustomProperties["GameMode"].ToString().Equals("CarMeeting"))
cacheRoomUI.Check(room.Name, (room.PlayerCount + "/" + room.MaxPlayers).ToString(), room.CustomProperties["GameMap"].ToString(), room.CustomProperties["GameMode"].ToString());
else
cacheRoomUI.Check(room.Name, (room.PlayerCount + "/" + room.MaxPlayers).ToString(), room.CustomProperties["GameMap"].ToString(), room.CustomProperties["GameMode"].ToString()
, room.CustomProperties["RacingMode"].ToString());
}
else
{
if (room.IsOpen)
{
CMRoomUI roomUI = Instantiate(roomUIPrefab.gameObject, roomUIParent).GetComponent<CMRoomUI>();
roomUIs.Add(roomUI);
if (room.CustomProperties["GameMode"].ToString().Equals("CarMeeting"))
roomUI.Check(room.Name, (room.PlayerCount + "/" + room.MaxPlayers).ToString(), room.CustomProperties["GameMap"].ToString(), room.CustomProperties["GameMode"].ToString());
else
cacheRoomUI.Check(room.Name, (room.PlayerCount + "/" + room.MaxPlayers).ToString(), room.CustomProperties["GameMap"].ToString(), room.CustomProperties["GameMode"].ToString()
, room.CustomProperties["RaceMode"].ToString());
}
}
}
}
if (roomUIs.Count > 0) roomFound = true;
noRoomTextObj.SetActive(!roomFound);
}
如果另一个玩家连接到斜板,我创建一个房间后,我会显示与这些属性可见的摄像机,但是属性“ racemode”不存在。
The player can create a room with certain properties that once created I set them and for lobby so that I can then display them in the lobby.
Function to create room:
public void OnCreateRoomButtonClicked()
{
RoomOptions roomOptions = new RoomOptions();
roomOptions.IsOpen = true;
roomOptions.IsVisible = true;
string roomName;
string gameMap;
if (gameMode.Equals("CarMeeting"))
{
gameMap = carMeetingModeMaps[mapIndex].sceneName;
roomName = roomNameCarMeetingModeInputField.text;
roomOptions.MaxPlayers = 4;
}
else
{
gameMap = racingModeMaps[mapIndex].sceneName;
roomName = roomNameRacingModeInputField.text;
roomOptions.MaxPlayers = 2;
}
if (!CheckIfRoomAlreadyExists(roomName))
{
StartCoroutine(EShowWarning());
}
else
{
roomOptions.CustomRoomProperties = new Hashtable();
roomOptions.CustomRoomProperties.Add("GameMap", gameMap);
roomOptions.CustomRoomProperties.Add("GameMode", gameMode);
roomOptions.CustomRoomProperties.Add("RaceMode", raceMode);
roomOptions.CustomRoomProperties.Add("InRace", false);
string[] customLobbyProperties = new string[4];
customLobbyProperties[0] = "GameMap";
customLobbyProperties[1] = "GameMode";
customLobbyProperties[2] = "RaceMode";
customLobbyProperties[3] = "InRace";
roomOptions.CustomRoomPropertiesForLobby = customLobbyProperties;
PhotonNetwork.CreateRoom(roomName, roomOptions, null, null);
}
}
Function display rooms in lobby:
public override void OnRoomListUpdate(List<RoomInfo> roomInfo)
{
Debug.Log("Rooms found " + roomInfo.Count);
bool roomFound = false;
foreach (RoomInfo room in roomInfo)
{
if (room.RemovedFromList)
{
int index = roomUIs.FindIndex(x => x.roomNameString.Equals(room.Name));
if (index != -1)
{
Destroy(roomUIs[index].gameObject);
roomUIs.RemoveAt(index);
}
}
else
{
CMRoomUI cacheRoomUI = roomUIs.Find(x => x.roomNameString.Equals(room.Name));
if (cacheRoomUI != null)
{
if (room.CustomProperties["GameMode"].ToString().Equals("CarMeeting"))
cacheRoomUI.Check(room.Name, (room.PlayerCount + "/" + room.MaxPlayers).ToString(), room.CustomProperties["GameMap"].ToString(), room.CustomProperties["GameMode"].ToString());
else
cacheRoomUI.Check(room.Name, (room.PlayerCount + "/" + room.MaxPlayers).ToString(), room.CustomProperties["GameMap"].ToString(), room.CustomProperties["GameMode"].ToString()
, room.CustomProperties["RacingMode"].ToString());
}
else
{
if (room.IsOpen)
{
CMRoomUI roomUI = Instantiate(roomUIPrefab.gameObject, roomUIParent).GetComponent<CMRoomUI>();
roomUIs.Add(roomUI);
if (room.CustomProperties["GameMode"].ToString().Equals("CarMeeting"))
roomUI.Check(room.Name, (room.PlayerCount + "/" + room.MaxPlayers).ToString(), room.CustomProperties["GameMap"].ToString(), room.CustomProperties["GameMode"].ToString());
else
cacheRoomUI.Check(room.Name, (room.PlayerCount + "/" + room.MaxPlayers).ToString(), room.CustomProperties["GameMap"].ToString(), room.CustomProperties["GameMode"].ToString()
, room.CustomProperties["RaceMode"].ToString());
}
}
}
}
if (roomUIs.Count > 0) roomFound = true;
noRoomTextObj.SetActive(!roomFound);
}
After I create a room if another player connects to the looby, I display the cameras visible with those properties, but the property "RaceMode" does not exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论