MonoBehaviour.OnSerializeNetworkView 当序列化网络视图

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 = 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;
		}
	}
}
// This objects health information
// 此物体的健康信息
var currentHealth : int = 0;

function OnSerializeNetworkView(stream : BitStream , info : NetworkMessageInfo ) {
	if (stream.isWriting) {
		var healthC : int = currentHealth;
		stream.Serialize(healthC);
	} else {
		var healthZ : int = 0;
		stream.Serialize(healthZ);
		currentHealth = healthZ;
	}    
}
Page last updated: 2011-1-2