âïļDemoAsteroids-LobbyScene
MainPanel
public void OnLoginButtonClicked()
PhotonNetwork.LocalPlayer.NickName = playerName; PhotonNetwork.ConnectUsingSettings();
public override void OnConnectedToMaster()
this.SetActivePanel(SelectionPanel.name);
ui SetActive ėīë ęēë íëëŊ?
private void SetActivePanel(string activePanel)
{
LoginPanel.SetActive(activePanel.Equals(LoginPanel.name));
SelectionPanel.SetActive(activePanel.Equals(SelectionPanel.name));
CreateRoomPanel.SetActive(activePanel.Equals(CreateRoomPanel.name));
JoinRandomRoomPanel.SetActive(activePanel.Equals(JoinRandomRoomPanel.name));
RoomListPanel.SetActive(activePanel.Equals(RoomListPanel.name)); // UI should call OnRoomListButtonClicked() to activate this
InsideRoomPanel.SetActive(activePanel.Equals(InsideRoomPanel.name));
}
create room
public void OnCreateRoomButtonClicked()
{
string roomName = RoomNameInputField.text;
roomName = (roomName.Equals(string.Empty)) ? "Room " + Random.Range(1000, 10000) : roomName;
byte maxPlayers;
byte.TryParse(MaxPlayersInputField.text, out maxPlayers);
maxPlayers = (byte) Mathf.Clamp(maxPlayers, 2, 8);
RoomOptions options = new RoomOptions {MaxPlayers = maxPlayers, PlayerTtl = 10000 };
PhotonNetwork.CreateRoom(roomName, options, null);
}
public override void OnJoinedRoom()
{
// joining (or entering) a room invalidates any cached lobby room list (even if LeaveLobby was not called due to just joining a room)
cachedRoomList.Clear();
SetActivePanel(InsideRoomPanel.name);
if (playerListEntries == null)
{
playerListEntries = new Dictionary<int, GameObject>();
}
foreach (Player p in PhotonNetwork.PlayerList)
{
GameObject entry = Instantiate(PlayerListEntryPrefab);
entry.transform.SetParent(InsideRoomPanel.transform);
entry.transform.localScale = Vector3.one;
entry.GetComponent<PlayerListEntry>().Initialize(p.ActorNumber, p.NickName);
object isPlayerReady;
if (p.CustomProperties.TryGetValue(AsteroidsGame.PLAYER_READY, out isPlayerReady))
{
entry.GetComponent<PlayerListEntry>().SetPlayerReady((bool) isPlayerReady);
}
playerListEntries.Add(p.ActorNumber, entry);
}
StartGameButton.gameObject.SetActive(CheckPlayersReady());
Hashtable props = new Hashtable
{
{AsteroidsGame.PLAYER_LOADED_LEVEL, false}
};
PhotonNetwork.LocalPlayer.SetCustomProperties(props);
}
public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
{
if (playerListEntries == null)
{
playerListEntries = new Dictionary<int, GameObject>();
}
GameObject entry;
if (playerListEntries.TryGetValue(targetPlayer.ActorNumber, out entry))
{
object isPlayerReady;
if (changedProps.TryGetValue(AsteroidsGame.PLAYER_READY, out isPlayerReady))
{
entry.GetComponent<PlayerListEntry>().SetPlayerReady((bool) isPlayerReady);
}
}
StartGameButton.gameObject.SetActive(CheckPlayersReady());
}
Last updated