Method group is Obsolete

NetworkLobbyManager.OnLobbyStartServer

切换到手册
Obsolete public void OnLobbyStartServer ();

描述

在服务器启动后(包括主机启动后)在服务器上调用此方法。

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"; } } }