Advertisement
Guest User

SaveInfo.cs

a guest
Oct 28th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SaveInfo : MonoBehaviour {
  5.  
  6.     public GameObject serverInfoContent;
  7.     public GameObject serverInfoPanelPrefab;
  8.  
  9.     public GameObject roomInformation;
  10.  
  11.     public GameObject serverInfoPanel;
  12.     public ServerInfoPanel serverInfoPanelScript;
  13.  
  14.     void Start () {
  15.    
  16.     }
  17.    
  18.  
  19.     void Update () {
  20.    
  21.     }
  22.  
  23.     private void OnReceivedRoomListUpdate () {
  24.         PopulateServerList ();
  25.     }
  26.  
  27.     public void PopulateServerList () {
  28.  
  29.         if (serverInfoContent.GetComponentInChildren<ServerInfoPanel>()) {
  30.            
  31.             foreach (ServerInfoPanel destroy in serverInfoContent.GetComponentsInChildren<ServerInfoPanel>()) {
  32.                
  33.                 Destroy(destroy.gameObject);
  34.  
  35.             }
  36.         }
  37.  
  38.         foreach (var room in PhotonNetwork.GetRoomList ()) {
  39.             roomInformation = Instantiate (serverInfoPanelPrefab);
  40.             serverInfoPanel = roomInformation;
  41.             serverInfoPanelScript = serverInfoPanel.GetComponent <ServerInfoPanel> ();
  42.             roomInformation.transform.SetParent (serverInfoContent.transform, false);
  43.             ServerInfoPanel panel = roomInformation.GetComponent<ServerInfoPanel>();
  44.             serverInfoPanelScript.serverName.text = room.name;
  45.             serverInfoPanelScript.serverPlayers.text = string.Format("{0}/{1}", room.playerCount, room.maxPlayers);
  46.             serverInfoPanelScript.joinButton.onClick.AddListener (() => PhotonNetwork.JoinRoom(room.name));
  47.         }
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement