Version: 2018.1
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"; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961