Unity NetworkManager组件,用于LAN的IP? [英] Unity NetworkManager component, IP for LAN?

查看:389
本文介绍了Unity NetworkManager组件,用于LAN的IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Unity的新网络中,我在同一WiFi网络上并排拥有两台计算机.

In Unity's new networking, I have two computers side by side on the same WiFi network.

使用NetworkManager,我正在尝试通过局域网将它们联网.

Using NetworkManager, I am trying to network them over the LAN.

TBC,与全球Internet网络完全无关,而不是在本地主机上.

TBC, absolutely nothing to do with global internet networking, and not on localhost.

左侧是 192.168.0.26 .

右侧是 192.168.0.120 .

假设我们希望剩下的一个成为服务器,即只需使用

Say we want the left one to be the server, i.e. simply using

    Debug.Log("I'm now a server");
    networkManager.StartServer();

说我们希望合适的人成为客户(所以StartClient())

Say we want the right one to be a client (So, StartClient() .)

TBC我只是在两台计算机上查看了ipConfig/etc,以获取当前的本地IP.

TBC I simply looked at ipConfig/etc on the two computers, to get the current local IP.

我绝对确保两台计算机都为Unity编辑器打开了防火墙(令人发指的gochya).

I absolutely ensured both machines have the firewall open for Unity editor (an infuriating gotchya).

实际上,您使用哪个"NetworkAddress"(参见图片)?在两台机器上?

In fact, which "NetworkAddress" (see image) do you use? On the two machines?

有四个排列.

我只是无法让他们通过LAN连接-网络地址应该是什么?

I just cannot get them to connect over LAN - what should the network address be?

脚注:对于在此处进行搜索的任何人,请注意有关Unet的重要提示 ... https://stackoverflow.com/a/51759299/294884

Footnote: For anyone googling here be aware of this critical tip about Unet ... https://stackoverflow.com/a/51759299/294884

推荐答案

在使用Unity提供的默认Network Manager之前,您必须确保网络地址"字段包含计算机的本地IP(由路由器提供)您想用作服务器.在您的情况下,该IP等于192.168.0.26,可以在计算机的网络配置中找到.
从现在开始,每个客户端/服务器实例都必须使用此IP地址,才能知道连接到哪里.

在创建服务器时,我个人建议使用networkManager.StartHost();而不是networkManager.StartServer();,因为您的服务器可能还需要一个客户端.如果不是这种情况,请忽略此声明.

最后,如果您能胜任该任务,则可以考虑制作自己的从Network Manager继承的Custom Networking Manager.这样一来,您就可以进一步控制应用程序的网络.

Wen using the default Network Manager provided by Unity, you have to make sure the Network Address field contains the local IP (provided by your router) of the machine you want to use as a server. In your case this IP is equal to 192.168.0.26 and can be found in the network configuration of the machine.
Every instance of client/server must use this IP address from now on in order to know where to connect to.

Something I personally recommend when creating the server is using the networkManager.StartHost(); instead of the networkManager.StartServer(); since your server perhaps also needs a client. If that's not the case please ignore this statement.

And lastly if you are up to the task, you can consider making your own Custom Networking Manager that inherits from the Network Manager. That way you could be in control of your app's networking even more.

这篇关于Unity NetworkManager组件,用于LAN的IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆