简体   繁体   English

Unity网络独立客户端

[英]Unity networking separate clients

I can't wrap my head around how to separate or distinct connected clients. 我无法确定如何分离或区分已连接的客户端。 I have done one of the many networking tutorials out there that get you to move blocks in another window through the unity MasterServer . 我已经完成了许多网络教程之一,使您可以通过统一的MasterServer在另一个窗口中移动块。 I currently have my own implementation which is a Lobby that lists the servers created, players can connect to these servers and once full a new scene loads for all the players connected. 我目前有一个自己的实现,它是一个大厅,其中列出了创建的服务器,玩家可以连接到这些服务器,一旦充满所有连接的玩家的新场景。

Now I need them to act in turn (turn based) spawning objects in there "own" color. 现在,我需要它们按“自己”的颜色依次(基于回合)生成对象。 Something like a check for a player ID, but then I need a complete list of all connected ID's as well to check against. 就像检查玩家ID一样,但是随后我还需要所有已连接ID的完整列表进行检查。

What you probably want is 您可能想要的是

MasterServer.RequestHostList
MasterServer.PollHostList
HostData.connectedPlayers

The MasterServer.RequestHostList requests for a host list on the MasterServer. MasterServer.RequestHostList请求在MasterServer上的主机列表。 You can then access this list through MasterServer.PollHostList. 然后,您可以通过MasterServer.PollHostList访问此列表。

MasterServer.PollHostList returns an array of HostData. MasterServer.PollHostList返回一个HostData数组。 You can use this array to query for the players connected to each Host. 您可以使用此数组查询连接到每个主机的播放器。

Links below to the respective docs on Unity API reference. 下面的链接指向有关Unity API参考的相应文档。 Each link has a great example on usage. 每个链接都有一个很好的用法示例。

MasterServer.RequestHostList MasterServer.RequestHostList
MasterServer.PollHostList MasterServer.PollHostList

HostData.connectedPlayers HostData.connectedPlayers

Your server should have, for each of your connected clients, one copy of the GameObject that is Network.Instantiated by the clients and that the clients use to send information to the server. 对于每个连接的客户端,服务器应具有GameObject的一个副本,该副本是Network.Client实例化的,并且客户端用于将信息发送到服务器。

The owner of the NetworkView in each of these objects is the client that instantiated them, and you can find it in "newtorkView.owner". 每个对象中NetworkView的所有者是实例化它们的客户端,您可以在“ newtorkView.owner”中找到它。

But you already have the separate GameObjects and that might be enough for your needs; 但是您已经有了单独的GameObject,这可能足以满足您的需求; each of them has a different instance of the script your clients use so they can be made to pick a spot in the turn queue and a different color each. 他们每个人都有客户使用的脚本的不同实例,因此可以使他们在转弯队列中选择一个地点,每个人使用不同的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM