统一:本地(LAN)匹配错误

Unity: Local (LAN) MatchMaking error

我正在尝试创建一个简单的多人游戏。我已经设置了一个配对系统,当设备连接到互联网时它工作正常,即成功创建了一个在线大厅。但是当我尝试在没有互联网访问权限的本地网络上创建大厅时,没有任何反应。

这是我用来托管游戏的代码:

void Start()
{
    netManager = NetworkManager.singleton;
    if(netManager.matchMaker == null)
    {
        netManager.StartMatchMaker();
    }

    roomName = "MyGameRoom";
    roomSize = 12;
}

public void CreateRoom()
{
    if (roomName != "" && roomName != null)
    {
        Debug.Log("Creating Room:" + roomName);
        netManager.matchMaker.CreateMatch(roomName, roomSize, true, "", "", "", 0, 0, netManager.OnMatchCreate);
    }
}

现在如果设备已连接到互联网,则游戏已成功托管。但是,如果设备连接到没有互联网服务的 wifi,则调用 CreateRoom 方法时不会发生任何事情。

CreateRoom() 方法与按钮的 onClick 事件链接。

我是统一网络的新手,希望有人能指出我做错了什么。 谢谢

基本 MatchMaking 服务基于连接到统一 MatchMaker 服务器 (https://mm.unet.unity3d.com) and this server is located on the internet, which means you can't connect to It if you are not connected to the internet. The solution is to use the NetworkDiscovery which let your server send broadcast messages over the network so clients can "hear" the broadcast and then connect to the sender. If you want a sample check this thread