Network.OnSerializeNetworkView(BitStream,NetworkMessageInfo)

Switch to Manual

Description

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

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

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public int currentHealth; void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) { int health = 0; if (stream.isWriting) { health = currentHealth; stream.Serialize(ref health); } else { stream.Serialize(ref health); currentHealth = health; } } }