function OnSerializeNetworkView (stream : BitStream, info : NetworkMessageInfo) : void
Description描述
Used to customize synchronization of variables in a script watched by a network view.
用来在一个由网络视图监控的脚本中自定义变量同步。
It is automatically determined if the variables being serialized should be sent or received, see example below for a better description. This depends on who owns the object, i.e. the owner sends and all others receive.
它自动决定被序列化的变量是否应该发送或接收,看下面一个更好的说明例子。这取决于谁拥有该物体,即所有者发送,其他所有人接收。
using UnityEngine;
using System.Collections;
public class example : 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;
}
}
}
// This objects health information
//这个物体的生命信息
var currentHealth : int;
function OnSerializeNetworkView(stream : BitStream,
info : NetworkMessageInfo) {
var health : int = 0;
if (stream.isWriting) {
health = currentHealth;
stream.Serialize(health);
} else {
stream.Serialize(health);
currentHealth = health;
}
}