lobbyClient | The connection for the lobby. |
これは、クライアントが入場したとき、クライアント上で呼び出されます。
using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI;
public class Example : NetworkLobbyManager { //Add this script to your GameObject. Make sure there isn't another NetworkManager in the Scene. //Create 2 Buttons (Create>UI>Buttons) and either: //1. assign them in the Inspector of the GameObject this script is attached to or //2. remove this part and the listeners and alter the OnClick section on each Button to match up with each function //Create a Text GameObject (Create>UI>Text) and attach it to the Status Text field in the Inspector.
public Button m_ClientButton, m_ServerButton; bool m_ServerStarted, m_ClientStarted;
void Start() { showLobbyGUI = true; //Call these functions when each Button is clicked m_ServerButton.onClick.AddListener(ServerButton); m_ClientButton.onClick.AddListener(ClientButton); }
//Output a message when your client enters the lobby public override void OnLobbyClientEnter() { m_ClientStarted = true; base.OnLobbyClientEnter(); Debug.Log("Your client has entered the lobby!"); }
public override void OnLobbyStopClient() { Debug.Log("Client stopped"); base.OnLobbyStopClient(); }
public override void OnLobbyStartServer() { m_ServerStarted = true; base.OnLobbyStartServer(); Debug.Log("Server Started!"); }
public override void OnStopServer() { m_ServerStarted = false; base.OnStopServer(); Debug.Log("Server Stopped!"); }
//Start the Client when this Button is pressed public void ClientButton() { if (m_ClientStarted == false) { StartClient(); m_ClientButton.GetComponentInChildren<Text>().text = "Stop Client"; } else { StopClient(); m_ClientButton.GetComponentInChildren<Text>().text = "Start Client"; } }
//Start the Server when this Button is pressed public void ServerButton() { Debug.Log("Server : " + m_ServerStarted); if (m_ServerStarted == false) { StartServer(); m_ServerButton.GetComponentInChildren<Text>().text = "Stop Server"; } else { StopServer(); ServerReturnToLobby(); m_ServerButton.GetComponentInChildren<Text>().text = "Start Server"; } } }