我正在尝试设置NetworkServer< - > Unity中的NetworkClient 我不想使用NetworkManager,因为它需要设置在线/离线场景。我希望玩家能够留在同一个场景中并处理NetworkManager为了学习目的所做的大部分工作。
我的问题是我无法找到服务器启动的时间。 现在,NetworkBehaviour类有一个虚拟的空OnStartServer,在文档中它说NetworkServer.Listen()'可以'触发它。
有关何时触发此功能的任何信息? Network.InitializeServer()和NetworkServer.Listen()之间的区别是Network.InitializeServer()来自Unity的旧服务器吗?
当前代码:
public class MyCustomNetworkManager : NetworkBehaviour
{
public void StartServer()
{
NetworkServer.Listen("127.0.0.1", 1234);
NetworkServer.RegisterHandler(MsgType.Connect, OnClientConnect);
//This in relation with OnServerInitialized Message from Unity works but can't connect with this connection.
//Network.InitializeServer(4, 1234, false);
}
public override void OnStartServer()
{
//This does not get called what so ever.
}
public void OnClientConnect(NetworkMessage message)
{
Debug.Log("A player connected");
}
void OnServerInitialized()
{
//This works but NetworkClient cannot connect with this server.
}
}