Version: 2020.1

MonoBehaviour.OnSerializeNetworkView(BitStream,NetworkMessageInfo)

切换到手册

描述

用于在网络视图监视的脚本中自定义变量同步。

自动确定是否应该发送或接收被序列化的变量, 请参阅下面的示例来获得更好的理解。这取决于谁拥有该对象, 即所有者发送,其他各方接收。

// This objects health information

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { public int currentHealth = 0;

void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) { if (stream.isWriting) { int healthC = currentHealth; stream.Serialize(ref healthC); } else { int healthZ = 0; stream.Serialize(ref healthZ); currentHealth = healthZ; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961