2018-06-07 13:41:08 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
#if ENABLE_UNET
|
|
|
|
|
|
|
|
namespace UnityEngine.Networking
|
|
|
|
{
|
|
|
|
// This can't be an interface because users don't need to implement the
|
|
|
|
// serialization functions, we'll code generate it for them when they omit it.
|
|
|
|
public abstract class MessageBase
|
|
|
|
{
|
|
|
|
// De-serialize the contents of the reader into this message
|
|
|
|
public virtual void Deserialize(NetworkReader reader) {}
|
|
|
|
|
|
|
|
// Serialize the contents of this message into the writer
|
|
|
|
public virtual void Serialize(NetworkWriter writer) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace UnityEngine.Networking.NetworkSystem
|
|
|
|
{
|
|
|
|
// ---------- General Typed Messages -------------------
|
|
|
|
|
|
|
|
public class StringMessage : MessageBase
|
|
|
|
{
|
|
|
|
public string value;
|
|
|
|
|
|
|
|
public StringMessage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public StringMessage(string v)
|
|
|
|
{
|
|
|
|
value = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
value = reader.ReadString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class IntegerMessage : MessageBase
|
|
|
|
{
|
|
|
|
public int value;
|
|
|
|
|
|
|
|
public IntegerMessage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntegerMessage(int v)
|
|
|
|
{
|
|
|
|
value = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
value = (int)reader.ReadPackedUInt32();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.WritePackedUInt32((uint)value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EmptyMessage : MessageBase
|
|
|
|
{
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------- Public System Messages -------------------
|
|
|
|
|
|
|
|
public class ErrorMessage : MessageBase
|
|
|
|
{
|
2018-06-08 09:52:39 +00:00
|
|
|
public byte errorCode; // byte instead of int because NetworkServer uses byte anyway. saves bandwidth.
|
2018-06-07 13:41:08 +00:00
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
2018-06-08 09:52:39 +00:00
|
|
|
errorCode = reader.ReadByte();
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
2018-06-08 09:52:39 +00:00
|
|
|
writer.Write(errorCode);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ReadyMessage : EmptyMessage
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public class NotReadyMessage : EmptyMessage
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public class AddPlayerMessage : MessageBase
|
|
|
|
{
|
|
|
|
public short playerControllerId;
|
|
|
|
public byte[] msgData;
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
2018-06-11 08:37:19 +00:00
|
|
|
playerControllerId = reader.ReadInt16();
|
2018-06-07 13:41:08 +00:00
|
|
|
msgData = reader.ReadBytesAndSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
2018-06-11 08:37:19 +00:00
|
|
|
writer.Write(playerControllerId);
|
2018-06-14 08:49:13 +00:00
|
|
|
writer.WriteBytesAndSize(msgData);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class RemovePlayerMessage : MessageBase
|
|
|
|
{
|
|
|
|
public short playerControllerId;
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
2018-06-11 08:37:19 +00:00
|
|
|
playerControllerId = reader.ReadInt16();
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
2018-06-11 08:37:19 +00:00
|
|
|
writer.Write(playerControllerId);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------- System Messages requried for code gen path -------------------
|
|
|
|
/* These are not used directly but manually serialized, these are here for reference.
|
|
|
|
|
|
|
|
public struct CommandMessage
|
|
|
|
{
|
|
|
|
public int cmdHash;
|
|
|
|
public string cmdName;
|
|
|
|
public byte[] payload;
|
|
|
|
}
|
|
|
|
public struct RPCMessage
|
|
|
|
{
|
|
|
|
public NetworkId netId;
|
|
|
|
public int cmdHash;
|
|
|
|
public byte[] payload;
|
|
|
|
}
|
|
|
|
public struct SyncEventMessage
|
|
|
|
{
|
|
|
|
public NetworkId netId;
|
|
|
|
public int cmdHash;
|
|
|
|
public byte[] payload;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal class SyncListMessage<T> where T: struct
|
|
|
|
{
|
|
|
|
public NetworkId netId;
|
|
|
|
public int cmdHash;
|
|
|
|
public byte operation;
|
|
|
|
public int itemIndex;
|
|
|
|
public T item;
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ---------- Internal System Messages -------------------
|
|
|
|
|
|
|
|
class ObjectSpawnMessage : MessageBase
|
|
|
|
{
|
|
|
|
public NetworkInstanceId netId;
|
|
|
|
public NetworkHash128 assetId;
|
|
|
|
public Vector3 position;
|
|
|
|
public Quaternion rotation;
|
2018-06-11 08:37:19 +00:00
|
|
|
public byte[] payload;
|
2018-06-07 13:41:08 +00:00
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
netId = reader.ReadNetworkId();
|
|
|
|
assetId = reader.ReadNetworkHash128();
|
|
|
|
position = reader.ReadVector3();
|
2018-06-08 09:56:00 +00:00
|
|
|
rotation = reader.ReadQuaternion();
|
2018-06-07 13:41:08 +00:00
|
|
|
payload = reader.ReadBytesAndSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(netId);
|
|
|
|
writer.Write(assetId);
|
|
|
|
writer.Write(position);
|
|
|
|
writer.Write(rotation);
|
2018-06-14 08:49:13 +00:00
|
|
|
writer.WriteBytesAndSize(payload);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ObjectSpawnSceneMessage : MessageBase
|
|
|
|
{
|
|
|
|
public NetworkInstanceId netId;
|
|
|
|
public NetworkSceneId sceneId;
|
|
|
|
public Vector3 position;
|
|
|
|
public byte[] payload;
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
netId = reader.ReadNetworkId();
|
|
|
|
sceneId = reader.ReadSceneId();
|
|
|
|
position = reader.ReadVector3();
|
|
|
|
payload = reader.ReadBytesAndSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(netId);
|
|
|
|
writer.Write(sceneId);
|
|
|
|
writer.Write(position);
|
2018-06-14 08:49:13 +00:00
|
|
|
writer.WriteBytesAndSize(payload);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ObjectSpawnFinishedMessage : MessageBase
|
|
|
|
{
|
2018-06-08 10:03:22 +00:00
|
|
|
public byte state; // byte because it's always 0 or 1
|
2018-06-07 13:41:08 +00:00
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
2018-06-08 10:03:22 +00:00
|
|
|
state = reader.ReadByte();
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
2018-06-08 10:03:22 +00:00
|
|
|
writer.Write(state);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ObjectDestroyMessage : MessageBase
|
|
|
|
{
|
|
|
|
public NetworkInstanceId netId;
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
netId = reader.ReadNetworkId();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(netId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class OwnerMessage : MessageBase
|
|
|
|
{
|
|
|
|
public NetworkInstanceId netId;
|
|
|
|
public short playerControllerId;
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
netId = reader.ReadNetworkId();
|
|
|
|
playerControllerId = (short)reader.ReadPackedUInt32();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(netId);
|
|
|
|
writer.WritePackedUInt32((uint)playerControllerId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClientAuthorityMessage : MessageBase
|
|
|
|
{
|
|
|
|
public NetworkInstanceId netId;
|
|
|
|
public bool authority;
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
netId = reader.ReadNetworkId();
|
|
|
|
authority = reader.ReadBoolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(netId);
|
|
|
|
writer.Write(authority);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class OverrideTransformMessage : MessageBase
|
|
|
|
{
|
|
|
|
public NetworkInstanceId netId;
|
|
|
|
public byte[] payload;
|
|
|
|
public bool teleport;
|
|
|
|
public int time;
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
netId = reader.ReadNetworkId();
|
|
|
|
payload = reader.ReadBytesAndSize();
|
|
|
|
teleport = reader.ReadBoolean();
|
|
|
|
time = (int)reader.ReadPackedUInt32();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(netId);
|
2018-06-14 08:49:13 +00:00
|
|
|
writer.WriteBytesAndSize(payload);
|
2018-06-07 13:41:08 +00:00
|
|
|
writer.Write(teleport);
|
|
|
|
writer.WritePackedUInt32((uint)time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AnimationMessage : MessageBase
|
|
|
|
{
|
|
|
|
public NetworkInstanceId netId;
|
|
|
|
public int stateHash; // if non-zero, then Play() this animation, skipping transitions
|
|
|
|
public float normalizedTime;
|
|
|
|
public byte[] parameters;
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
netId = reader.ReadNetworkId();
|
|
|
|
stateHash = (int)reader.ReadPackedUInt32();
|
|
|
|
normalizedTime = reader.ReadSingle();
|
|
|
|
parameters = reader.ReadBytesAndSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(netId);
|
|
|
|
writer.WritePackedUInt32((uint)stateHash);
|
|
|
|
writer.Write(normalizedTime);
|
2018-06-14 08:49:13 +00:00
|
|
|
writer.WriteBytesAndSize(parameters);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AnimationParametersMessage : MessageBase
|
|
|
|
{
|
|
|
|
public NetworkInstanceId netId;
|
2018-06-11 08:37:19 +00:00
|
|
|
public byte[] parameters;
|
2018-06-07 13:41:08 +00:00
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
netId = reader.ReadNetworkId();
|
|
|
|
parameters = reader.ReadBytesAndSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(netId);
|
2018-06-14 08:49:13 +00:00
|
|
|
writer.WriteBytesAndSize(parameters);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AnimationTriggerMessage : MessageBase
|
|
|
|
{
|
|
|
|
public NetworkInstanceId netId;
|
2018-06-11 08:37:19 +00:00
|
|
|
public int hash;
|
2018-06-07 13:41:08 +00:00
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
netId = reader.ReadNetworkId();
|
|
|
|
hash = (int)reader.ReadPackedUInt32();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(netId);
|
|
|
|
writer.WritePackedUInt32((uint)hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LobbyReadyToBeginMessage : MessageBase
|
|
|
|
{
|
|
|
|
public byte slotId;
|
|
|
|
public bool readyState;
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
{
|
|
|
|
slotId = reader.ReadByte();
|
|
|
|
readyState = reader.ReadBoolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
{
|
|
|
|
writer.Write(slotId);
|
|
|
|
writer.Write(readyState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //ENABLE_UNET
|