Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

MessageBase

class in UnityEngine.Networking

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual

Descripción

Network message classes should be derived from this class. These message classes can then be sent using the various Send functions of NetworkConnection, NetworkClient and NetworkServer.

Public data fields of classes derived from MessageBase will be automatically serialized with the class. The virtual methods Serialize and Deserialize may be implemented by developers for precise control, but if they are not implemented, then implementations will be generated for them.

In the example below, the methods have implementations, but if those methods were not implemented, the message would still be usable.

#pragma strict
class SpawnMessage extends MessageBase {
	public var netId;
	public var assetId;
	public var position;
	public var payload;
	// This method would be generated
	public override function Deserialize(reader) {
		netId = reader.ReadPackedUInt32();
		assetId = reader.ReadNetworkHash128();
		position = reader.ReadVector3();
		payload = reader.ReadBytesAndSize();
	}
	// This method would be generated
	public override function Serialize(writer) {
		writer.WritePackedUInt32(netId);
		writer.Write(assetId);
		writer.Write(position);
		writer.WriteBytesFull(payload);
	}
}
class SpawnMessage : MessageBase
{
	public uint netId;
	public NetworkHash128 assetId;
	public Vector3 position;
	public byte[] payload;

// This method would be generated public override void Deserialize(NetworkReader reader) { netId = reader.ReadPackedUInt32(); assetId = reader.ReadNetworkHash128(); position = reader.ReadVector3(); payload = reader.ReadBytesAndSize(); }

// This method would be generated public override void Serialize(NetworkWriter writer) { writer.WritePackedUInt32(netId); writer.Write(assetId); writer.Write(position); writer.WriteBytesFull(payload); } }

Funciones Públicas

DeserializeThis method is used to populate a message object from a NetworkReader stream.
SerializeThe method is used to populate a NetworkWriter stream from a message object.