首页 > 技术文章 > Unity学习——Network Transform和 Network Transform Child组件

qing2019 2020-05-15 18:14 原文

Network Transfrom

Network Transform组件同步网络上的 GameObjects的移动和旋转。注意 Network Transform组件只能同步生成的联网 GameObjects。

属性 功能
Network Sent Rate(seconds) 设置网络每秒更新的数量。你可以设置为0,这样 GameObject在被创建后就不再会更新,就像玩家产生的无交互效果一样。比如说:玩家无法与身后的烟雾互动。
Transform Sync Mode 发生在 此GameObject上的同步类型。
-- Sync None 无同步
-- Sync Transform 使用 GameObject的 Transform来同步。使用场景:物理系统不控制此 GameObject。默认是此模式。
-- Sync Rigidbody 2D 使用 Rigidbody2D组件来同步。使用场景: 2D物理系统控制此 GameObject。
-- Sync Rigidbody 3D 使用 Rigidbody组件来同步。使用场景:3D物理系统控制此 GameObject。
-- Sync Character Controller 使用 Character Controller组件来同步。使用场景:你在使用 Character Controller。
Movement:
Movement Threshold 设置 GameObject在没有发送移动同步更新时 能够移动的距离。
Snap Threshold 在某个地方设置一个阈值,如果一个移动更新将 GameObject放置到比当前位置更远的地方,那么 GameObject会快速移动到此位置而不是平滑移动。
Interpolate Movement Factor 使用它来启动和控制同步移动的插入。数字越大,GameObject插入到目标位置的速度就越快。如果设置为0,GameObject会直接到新的位置。
Rotation:
Rotation Axis 定义那个旋转轴应该同步。默认是 XYZ (full 3D)。
Interpolate Rotation Factor 使用它来启动和控制同步旋转的插入。数字越大,GameObject插入到目标旋转的速度就越快。设置为0,GameObject会直接到新的旋转。
Compress Rotation 如果你压缩旋转数据,则发送的数据量会更少,旋转同步的精度也会更低。
-- None 无压缩(默认)。
-- Low 将少量压缩应用于旋转同步。它能减少旋转数据的发送信息量。
-- High 将高压缩量应用于旋转同步。这个选项发送最少旋转数据的信息量。
-- Sync Angular Velocity 选中它来同步附加 Rigidbody组件的角速度。

这个组件考虑了权限,因此本地玩家 GameObject(有本地权限)能将它们的位置从 client同步server上。然后再同步到其他 clients。其他 GameObjects(有server权限的)从 server同步位置到 clietns。
一个有 Network Transform组件的 GameObject必须也有 Network Identity组件。当你为 GameObject添加 Network Transform组件时,如果此 GameObect没有 Network Identity组件的话,它也会自动创建。
注:Network Transform Visualizer组件可用于调试 Network Transform组件。

Network Transform Child

Network Transform Child组件同步 有 Network Transform组件的 GameObject的 子GameObject 的位置和旋转。在需要同步一个 联网GameObject的独立移动的子对象时,可以使用此组件。
要使用 Network Transform,把它关联到同一个 parent GameObject下,作为 Network Transform,并使用 Target域来定义哪个 子GameObject要应用此组件设计。你也可以有多个 Network Transform Child组件。

属性 功能
Network Send Rate (seconds) 设置每秒网络更新的数量。设置为0时,GameObject在被创建后不会再更新,就像玩家产生的无交互效果。
Target 要同步的 子 transform。(注意,此组件在 parent上,而不是 child - 因此你可以使用这个域来指定 child。
Movement Threshold 设置 GameObject在不发送移动同步更新时可以移动的距离。
Interpolate Movement Factor 同 Network Transform
Interpolate Rotation Factor 同 Network Transform
Rotation Axis 同 Network Transform
Compress Rotation 同 Network Transform
-- None 同 Network Transform
-- Low 同 Network Transform
-- High 同 Network Transform

这个组件不使用物理;它同步 子GameObject的位置和旋转,并向更新值插入。使用 Interpolate Movement Factor和 Interpolate Rotation Rotation Factor来自定义插入的速率。
有 Network Transform Child组件的 GameObject必须也有 Network Identity组件。当你为 GameObject添加 Network Transform Child组件时,如果此 GameObect没有 Network Identity组件的话,它也会自动创建。

推荐阅读