using System; using Unity.Multiplayer.Samples.Utilities; using UnityEngine; using UnityEngine.SceneManagement; //离线状态,默认初始状态 public class OfflineState : ConnectionState { public override void Enter() { //关闭连接 m_ConnectionManager.NetworkManager.Shutdown(); } public override void Exit() { } //启动客户端,切换到ClientConnectingState状态。playerName为客户端名称(建议SystemInfo.deviceName设备名称) public override void StartClientIP(string ipaddress, int port) { //设置客户端账号,IP、端口 Debug.Log("OfflineState StartClientIP"); //设置IP m_ConnectionManager.ConnectionMethod.SetIPData(ipaddress, (ushort)port); //设置信息 m_ConnectionManager.m_ClientReconnecting.Configure(); m_ConnectionManager.m_ClientConnecting.Configure(); //切换到连接状态 m_ConnectionManager.ChangeState(m_ConnectionManager.m_ClientConnecting); } //启动服务端,切换到StartingHostState状态 public override void StartHostIP(string ipaddress, int port) { Debug.Log("OfflineState StartHostIP"); m_ConnectionManager.ConnectionMethod.SetIPData(ipaddress, (ushort)port); m_ConnectionManager.m_StartingHost.Configure(); m_ConnectionManager.ChangeState(m_ConnectionManager.m_StartingHost); } }