Important: UNet is a deprecated solution, and a new Multiplayer and Networking Solution (Netcode for GameObjects) is under development. For more information and next steps see the information on the Unity Netcode for GameObjects website. |
Network Discovery 组件允许 Unity 应用程序使用网络系统在局域网 (LAN) 上发现彼此。此组件不能用于互联网游戏发现。应使用 Multiplayer 服务(以及 MatchMaker 和 Relay 服务)进行连接。
Network Discovery 组件不需要与 Unity 服务的任何集成,旨在作为一种完全独立解决方案,用于在局域网上查找要连接的其他游戏。
Inspector 窗口中的 Network Discovery 组件
属性 | 功能 |
---|---|
Broadcast Port | 用于发送广播和进行监听的网络端口。 |
Broadcast Key | 要广播的密钥。这应该是唯一值,表示您的发现与其他 Network Discovery 实例的兼容性。唯一广播密钥避免了当不同类型的游戏在同一个局域网上运行时尝试彼此连接。 |
Broadcast Version | 要包含在广播中的主要版本。将此属性与 Broadcast SubVersion 一起使用可指示版本兼容性。 |
Broadcast SubVersion | 要包含在广播中的次要版本。将此属性与 Broadcast Version 一起使用可指示版本兼容性。 |
Broadcast Interval | 指定 Unity 应广播发现信息的频率(以秒为单位)。 |
Use NetworkManager | 启用此属性可以使用 Network Manager 设置进行广播,然后自动加入找到的游戏。 |
Broadcast Data | 输入要包含在广播中的自定义数据。如果已启用 Use NetworkManager,则 Network Manager 会重写此属性。 |
Show GUI | 启用此属性可在播放模式下显示默认广播 GUI。此 GUI 仅用于开发人员测试。 |
Offset X | 广播 GUI 的 x 轴偏移。仅当启用了 Show GUI 时,此设置才可见。 |
Offset Y | 广播 GUI 的 y 轴偏移。仅当启用了 Show GUI 时,此设置才可见。 |
在播放模式下运行时,检视面板中也会显示以下信息:
属性 | 功能 |
---|---|
hostId | 用于广播的主机 ID。 |
running | 如果正在广播,则为 true。 |
isServer | 如果作为服务器广播,则为 true。 |
isClient | 如果作为客户端监听广播,则为 true。 |
broadcastsReceived | 收到的广播消息的列表。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.