mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkReader API cleanup: ReadInt16 => ReadShort etc.
This commit is contained in:
parent
46539ef816
commit
c4e37f670c
@ -162,7 +162,7 @@ async Task ReceiveRequestAsync(UdpClient udpClient)
|
|||||||
|
|
||||||
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(udpReceiveResult.Buffer))
|
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(udpReceiveResult.Buffer))
|
||||||
{
|
{
|
||||||
long handshake = networkReader.ReadInt64();
|
long handshake = networkReader.ReadLong();
|
||||||
if (handshake != secretHandshake)
|
if (handshake != secretHandshake)
|
||||||
{
|
{
|
||||||
// message is not for us
|
// message is not for us
|
||||||
@ -339,7 +339,7 @@ async Task ReceiveGameBroadcastAsync(UdpClient udpClient)
|
|||||||
|
|
||||||
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(udpReceiveResult.Buffer))
|
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(udpReceiveResult.Buffer))
|
||||||
{
|
{
|
||||||
if (networkReader.ReadInt64() != secretHandshake)
|
if (networkReader.ReadLong() != secretHandshake)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Response response = networkReader.Read<Response>();
|
Response response = networkReader.Read<Response>();
|
||||||
|
@ -342,7 +342,7 @@ void ReadParameters(NetworkReader reader)
|
|||||||
bool animatorEnabled = animator.enabled;
|
bool animatorEnabled = animator.enabled;
|
||||||
// need to read values from NetworkReader even if animator is disabled
|
// need to read values from NetworkReader even if animator is disabled
|
||||||
|
|
||||||
ulong dirtyBits = reader.ReadUInt64();
|
ulong dirtyBits = reader.ReadULong();
|
||||||
for (int i = 0; i < parameters.Length; i++)
|
for (int i = 0; i < parameters.Length; i++)
|
||||||
{
|
{
|
||||||
if ((dirtyBits & (1ul << i)) == 0)
|
if ((dirtyBits & (1ul << i)) == 0)
|
||||||
@ -351,19 +351,19 @@ void ReadParameters(NetworkReader reader)
|
|||||||
AnimatorControllerParameter par = parameters[i];
|
AnimatorControllerParameter par = parameters[i];
|
||||||
if (par.type == AnimatorControllerParameterType.Int)
|
if (par.type == AnimatorControllerParameterType.Int)
|
||||||
{
|
{
|
||||||
int newIntValue = reader.ReadInt32();
|
int newIntValue = reader.ReadInt();
|
||||||
if (animatorEnabled)
|
if (animatorEnabled)
|
||||||
animator.SetInteger(par.nameHash, newIntValue);
|
animator.SetInteger(par.nameHash, newIntValue);
|
||||||
}
|
}
|
||||||
else if (par.type == AnimatorControllerParameterType.Float)
|
else if (par.type == AnimatorControllerParameterType.Float)
|
||||||
{
|
{
|
||||||
float newFloatValue = reader.ReadSingle();
|
float newFloatValue = reader.ReadFloat();
|
||||||
if (animatorEnabled)
|
if (animatorEnabled)
|
||||||
animator.SetFloat(par.nameHash, newFloatValue);
|
animator.SetFloat(par.nameHash, newFloatValue);
|
||||||
}
|
}
|
||||||
else if (par.type == AnimatorControllerParameterType.Bool)
|
else if (par.type == AnimatorControllerParameterType.Bool)
|
||||||
{
|
{
|
||||||
bool newBoolValue = reader.ReadBoolean();
|
bool newBoolValue = reader.ReadBool();
|
||||||
if (animatorEnabled)
|
if (animatorEnabled)
|
||||||
animator.SetBool(par.nameHash, newBoolValue);
|
animator.SetBool(par.nameHash, newBoolValue);
|
||||||
}
|
}
|
||||||
@ -415,9 +415,9 @@ public override void OnDeserialize(NetworkReader reader, bool initialState)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < animator.layerCount; i++)
|
for (int i = 0; i < animator.layerCount; i++)
|
||||||
{
|
{
|
||||||
int stateHash = reader.ReadInt32();
|
int stateHash = reader.ReadInt();
|
||||||
float normalizedTime = reader.ReadSingle();
|
float normalizedTime = reader.ReadFloat();
|
||||||
animator.SetLayerWeight(i, reader.ReadSingle());
|
animator.SetLayerWeight(i, reader.ReadFloat());
|
||||||
animator.Play(stateHash, i, normalizedTime);
|
animator.Play(stateHash, i, normalizedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ void DeserializeFromReader(NetworkReader reader)
|
|||||||
// (rotation is optionally compressed)
|
// (rotation is optionally compressed)
|
||||||
localPosition = reader.ReadVector3(),
|
localPosition = reader.ReadVector3(),
|
||||||
localRotation = compressRotation
|
localRotation = compressRotation
|
||||||
? Compression.DecompressQuaternion(reader.ReadUInt32())
|
? Compression.DecompressQuaternion(reader.ReadUInt())
|
||||||
: reader.ReadQuaternion(),
|
: reader.ReadQuaternion(),
|
||||||
// use current target scale, so we can check boolean and reader later, to see if the data is actually sent.
|
// use current target scale, so we can check boolean and reader later, to see if the data is actually sent.
|
||||||
localScale = targetComponent.localScale,
|
localScale = targetComponent.localScale,
|
||||||
|
@ -19,7 +19,10 @@ internal static void Register(TypeReference dataType, MethodReference methodRefe
|
|||||||
{
|
{
|
||||||
if (readFuncs.ContainsKey(dataType))
|
if (readFuncs.ContainsKey(dataType))
|
||||||
{
|
{
|
||||||
Weaver.Warning($"Registering a Read method for {dataType.FullName} when one already exists", methodReference);
|
// TODO enable this again later.
|
||||||
|
// Reader has some obsolete functions that were renamed.
|
||||||
|
// Don't want weaver warnings for all of them.
|
||||||
|
//Weaver.Warning($"Registering a Read method for {dataType.FullName} when one already exists", methodReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to import type when we Initialize Readers so import here in case it is used anywhere else
|
// we need to import type when we Initialize Readers so import here in case it is used anywhere else
|
||||||
|
@ -49,7 +49,7 @@ public static bool Unpack(NetworkReader messageReader, out ushort msgType)
|
|||||||
// read message type (varint)
|
// read message type (varint)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
msgType = messageReader.ReadUInt16();
|
msgType = messageReader.ReadUShort();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (System.IO.EndOfStreamException)
|
catch (System.IO.EndOfStreamException)
|
||||||
|
@ -665,7 +665,7 @@ internal void DeSerializeObjectsAll(NetworkReader reader)
|
|||||||
|
|
||||||
internal void DeSerializeObjectsDelta(NetworkReader reader)
|
internal void DeSerializeObjectsDelta(NetworkReader reader)
|
||||||
{
|
{
|
||||||
ulong dirty = reader.ReadUInt64();
|
ulong dirty = reader.ReadULong();
|
||||||
for (int i = 0; i < syncObjects.Count; i++)
|
for (int i = 0; i < syncObjects.Count; i++)
|
||||||
{
|
{
|
||||||
SyncObject syncObject = syncObjects[i];
|
SyncObject syncObject = syncObjects[i];
|
||||||
|
@ -903,7 +903,7 @@ internal void OnSerializeAllSafely(bool initialState, NetworkWriter ownerWriter,
|
|||||||
void OnDeserializeSafely(NetworkBehaviour comp, NetworkReader reader, bool initialState)
|
void OnDeserializeSafely(NetworkBehaviour comp, NetworkReader reader, bool initialState)
|
||||||
{
|
{
|
||||||
// read header as 4 bytes and calculate this chunk's start+end
|
// read header as 4 bytes and calculate this chunk's start+end
|
||||||
int contentSize = reader.ReadInt32();
|
int contentSize = reader.ReadInt();
|
||||||
int chunkStart = reader.Position;
|
int chunkStart = reader.Position;
|
||||||
int chunkEnd = reader.Position + contentSize;
|
int chunkEnd = reader.Position + contentSize;
|
||||||
|
|
||||||
|
@ -111,18 +111,38 @@ public static class NetworkReaderExtensions
|
|||||||
|
|
||||||
public static byte ReadByte(this NetworkReader reader) => reader.ReadByte();
|
public static byte ReadByte(this NetworkReader reader) => reader.ReadByte();
|
||||||
public static sbyte ReadSByte(this NetworkReader reader) => (sbyte)reader.ReadByte();
|
public static sbyte ReadSByte(this NetworkReader reader) => (sbyte)reader.ReadByte();
|
||||||
public static char ReadChar(this NetworkReader reader) => (char)reader.ReadUInt16();
|
public static char ReadChar(this NetworkReader reader) => (char)reader.ReadUShort();
|
||||||
public static bool ReadBoolean(this NetworkReader reader) => reader.ReadByte() != 0;
|
|
||||||
public static short ReadInt16(this NetworkReader reader) => (short)reader.ReadUInt16();
|
// Deprecated 2021-05-18
|
||||||
public static ushort ReadUInt16(this NetworkReader reader)
|
[Obsolete("We've cleaned up the API. Use ReadBool instead.")]
|
||||||
|
public static bool ReadBoolean(this NetworkReader reader) => reader.ReadBool();
|
||||||
|
public static bool ReadBool(this NetworkReader reader) => reader.ReadByte() != 0;
|
||||||
|
|
||||||
|
// Deprecated 2021-05-18
|
||||||
|
[Obsolete("We've cleaned up the API. Use ReadShort instead.")]
|
||||||
|
public static short ReadInt16(this NetworkReader reader) => reader.ReadShort();
|
||||||
|
public static short ReadShort(this NetworkReader reader) => (short)reader.ReadUShort();
|
||||||
|
|
||||||
|
// Deprecated 2021-05-18
|
||||||
|
[Obsolete("We've cleaned up the API. Use ReadUShort instead.")]
|
||||||
|
public static ushort ReadUInt16(this NetworkReader reader) => reader.ReadUShort();
|
||||||
|
public static ushort ReadUShort(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
ushort value = 0;
|
ushort value = 0;
|
||||||
value |= reader.ReadByte();
|
value |= reader.ReadByte();
|
||||||
value |= (ushort)(reader.ReadByte() << 8);
|
value |= (ushort)(reader.ReadByte() << 8);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
public static int ReadInt32(this NetworkReader reader) => (int)reader.ReadUInt32();
|
|
||||||
public static uint ReadUInt32(this NetworkReader reader)
|
// Deprecated 2021-05-18
|
||||||
|
[Obsolete("We've cleaned up the API. Use ReadInt instead.")]
|
||||||
|
public static int ReadInt32(this NetworkReader reader) => reader.ReadInt();
|
||||||
|
public static int ReadInt(this NetworkReader reader) => (int)reader.ReadUInt();
|
||||||
|
|
||||||
|
// Deprecated 2021-05-18
|
||||||
|
[Obsolete("We've cleaned up the API. Use ReadUInt instead.")]
|
||||||
|
public static uint ReadUInt32(this NetworkReader reader) => reader.ReadUInt();
|
||||||
|
public static uint ReadUInt(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
uint value = 0;
|
uint value = 0;
|
||||||
value |= reader.ReadByte();
|
value |= reader.ReadByte();
|
||||||
@ -131,8 +151,16 @@ public static uint ReadUInt32(this NetworkReader reader)
|
|||||||
value |= (uint)(reader.ReadByte() << 24);
|
value |= (uint)(reader.ReadByte() << 24);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
public static long ReadInt64(this NetworkReader reader) => (long)reader.ReadUInt64();
|
|
||||||
public static ulong ReadUInt64(this NetworkReader reader)
|
// Deprecated 2021-05-18
|
||||||
|
[Obsolete("We've cleaned up the API. Use ReadLong instead.")]
|
||||||
|
public static long ReadInt64(this NetworkReader reader) => reader.ReadLong();
|
||||||
|
public static long ReadLong(this NetworkReader reader) => (long)reader.ReadULong();
|
||||||
|
|
||||||
|
// Deprecated 2021-05-18
|
||||||
|
[Obsolete("We've cleaned up the API. Use ReadULong instead.")]
|
||||||
|
public static ulong ReadUInt64(this NetworkReader reader) => reader.ReadULong();
|
||||||
|
public static ulong ReadULong(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
ulong value = 0;
|
ulong value = 0;
|
||||||
value |= reader.ReadByte();
|
value |= reader.ReadByte();
|
||||||
@ -145,23 +173,28 @@ public static ulong ReadUInt64(this NetworkReader reader)
|
|||||||
value |= ((ulong)reader.ReadByte()) << 56;
|
value |= ((ulong)reader.ReadByte()) << 56;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
public static float ReadSingle(this NetworkReader reader)
|
|
||||||
|
// Deprecated 2021-05-18
|
||||||
|
[Obsolete("We've cleaned up the API. Use ReadSingle instead.")]
|
||||||
|
public static float ReadSingle(this NetworkReader reader) => reader.ReadFloat();
|
||||||
|
public static float ReadFloat(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
UIntFloat converter = new UIntFloat();
|
UIntFloat converter = new UIntFloat();
|
||||||
converter.intValue = reader.ReadUInt32();
|
converter.intValue = reader.ReadUInt();
|
||||||
return converter.floatValue;
|
return converter.floatValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double ReadDouble(this NetworkReader reader)
|
public static double ReadDouble(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
UIntDouble converter = new UIntDouble();
|
UIntDouble converter = new UIntDouble();
|
||||||
converter.longValue = reader.ReadUInt64();
|
converter.longValue = reader.ReadULong();
|
||||||
return converter.doubleValue;
|
return converter.doubleValue;
|
||||||
}
|
}
|
||||||
public static decimal ReadDecimal(this NetworkReader reader)
|
public static decimal ReadDecimal(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
UIntDecimal converter = new UIntDecimal();
|
UIntDecimal converter = new UIntDecimal();
|
||||||
converter.longValue1 = reader.ReadUInt64();
|
converter.longValue1 = reader.ReadULong();
|
||||||
converter.longValue2 = reader.ReadUInt64();
|
converter.longValue2 = reader.ReadULong();
|
||||||
return converter.decimalValue;
|
return converter.decimalValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +202,7 @@ public static decimal ReadDecimal(this NetworkReader reader)
|
|||||||
public static string ReadString(this NetworkReader reader)
|
public static string ReadString(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
// read number of bytes
|
// read number of bytes
|
||||||
ushort size = reader.ReadUInt16();
|
ushort size = reader.ReadUShort();
|
||||||
|
|
||||||
// null support, see NetworkWriter
|
// null support, see NetworkWriter
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
@ -194,7 +227,7 @@ public static byte[] ReadBytesAndSize(this NetworkReader reader)
|
|||||||
{
|
{
|
||||||
// count = 0 means the array was null
|
// count = 0 means the array was null
|
||||||
// otherwise count -1 is the length of the array
|
// otherwise count -1 is the length of the array
|
||||||
uint count = reader.ReadUInt32();
|
uint count = reader.ReadUInt();
|
||||||
// Use checked() to force it to throw OverflowException if data is invalid
|
// Use checked() to force it to throw OverflowException if data is invalid
|
||||||
return count == 0 ? null : reader.ReadBytes(checked((int)(count - 1u)));
|
return count == 0 ? null : reader.ReadBytes(checked((int)(count - 1u)));
|
||||||
}
|
}
|
||||||
@ -204,42 +237,42 @@ public static ArraySegment<byte> ReadBytesAndSizeSegment(this NetworkReader read
|
|||||||
{
|
{
|
||||||
// count = 0 means the array was null
|
// count = 0 means the array was null
|
||||||
// otherwise count - 1 is the length of the array
|
// otherwise count - 1 is the length of the array
|
||||||
uint count = reader.ReadUInt32();
|
uint count = reader.ReadUInt();
|
||||||
// Use checked() to force it to throw OverflowException if data is invalid
|
// Use checked() to force it to throw OverflowException if data is invalid
|
||||||
return count == 0 ? default : reader.ReadBytesSegment(checked((int)(count - 1u)));
|
return count == 0 ? default : reader.ReadBytesSegment(checked((int)(count - 1u)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2 ReadVector2(this NetworkReader reader) => new Vector2(reader.ReadSingle(), reader.ReadSingle());
|
public static Vector2 ReadVector2(this NetworkReader reader) => new Vector2(reader.ReadFloat(), reader.ReadFloat());
|
||||||
public static Vector3 ReadVector3(this NetworkReader reader) => new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
public static Vector3 ReadVector3(this NetworkReader reader) => new Vector3(reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat());
|
||||||
public static Vector4 ReadVector4(this NetworkReader reader) => new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
public static Vector4 ReadVector4(this NetworkReader reader) => new Vector4(reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat());
|
||||||
public static Vector2Int ReadVector2Int(this NetworkReader reader) => new Vector2Int(reader.ReadInt32(), reader.ReadInt32());
|
public static Vector2Int ReadVector2Int(this NetworkReader reader) => new Vector2Int(reader.ReadInt(), reader.ReadInt());
|
||||||
public static Vector3Int ReadVector3Int(this NetworkReader reader) => new Vector3Int(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
|
public static Vector3Int ReadVector3Int(this NetworkReader reader) => new Vector3Int(reader.ReadInt(), reader.ReadInt(), reader.ReadInt());
|
||||||
public static Color ReadColor(this NetworkReader reader) => new Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
public static Color ReadColor(this NetworkReader reader) => new Color(reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat());
|
||||||
public static Color32 ReadColor32(this NetworkReader reader) => new Color32(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
|
public static Color32 ReadColor32(this NetworkReader reader) => new Color32(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
|
||||||
public static Quaternion ReadQuaternion(this NetworkReader reader) => new Quaternion(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
public static Quaternion ReadQuaternion(this NetworkReader reader) => new Quaternion(reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat());
|
||||||
public static Rect ReadRect(this NetworkReader reader) => new Rect(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
public static Rect ReadRect(this NetworkReader reader) => new Rect(reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat());
|
||||||
public static Plane ReadPlane(this NetworkReader reader) => new Plane(reader.ReadVector3(), reader.ReadSingle());
|
public static Plane ReadPlane(this NetworkReader reader) => new Plane(reader.ReadVector3(), reader.ReadFloat());
|
||||||
public static Ray ReadRay(this NetworkReader reader) => new Ray(reader.ReadVector3(), reader.ReadVector3());
|
public static Ray ReadRay(this NetworkReader reader) => new Ray(reader.ReadVector3(), reader.ReadVector3());
|
||||||
public static Matrix4x4 ReadMatrix4x4(this NetworkReader reader)
|
public static Matrix4x4 ReadMatrix4x4(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
return new Matrix4x4
|
return new Matrix4x4
|
||||||
{
|
{
|
||||||
m00 = reader.ReadSingle(),
|
m00 = reader.ReadFloat(),
|
||||||
m01 = reader.ReadSingle(),
|
m01 = reader.ReadFloat(),
|
||||||
m02 = reader.ReadSingle(),
|
m02 = reader.ReadFloat(),
|
||||||
m03 = reader.ReadSingle(),
|
m03 = reader.ReadFloat(),
|
||||||
m10 = reader.ReadSingle(),
|
m10 = reader.ReadFloat(),
|
||||||
m11 = reader.ReadSingle(),
|
m11 = reader.ReadFloat(),
|
||||||
m12 = reader.ReadSingle(),
|
m12 = reader.ReadFloat(),
|
||||||
m13 = reader.ReadSingle(),
|
m13 = reader.ReadFloat(),
|
||||||
m20 = reader.ReadSingle(),
|
m20 = reader.ReadFloat(),
|
||||||
m21 = reader.ReadSingle(),
|
m21 = reader.ReadFloat(),
|
||||||
m22 = reader.ReadSingle(),
|
m22 = reader.ReadFloat(),
|
||||||
m23 = reader.ReadSingle(),
|
m23 = reader.ReadFloat(),
|
||||||
m30 = reader.ReadSingle(),
|
m30 = reader.ReadFloat(),
|
||||||
m31 = reader.ReadSingle(),
|
m31 = reader.ReadFloat(),
|
||||||
m32 = reader.ReadSingle(),
|
m32 = reader.ReadFloat(),
|
||||||
m33 = reader.ReadSingle()
|
m33 = reader.ReadFloat()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static byte[] ReadBytes(this NetworkReader reader, int count)
|
public static byte[] ReadBytes(this NetworkReader reader, int count)
|
||||||
@ -266,7 +299,7 @@ public static GameObject ReadGameObject(this NetworkReader reader)
|
|||||||
|
|
||||||
public static NetworkIdentity ReadNetworkIdentity(this NetworkReader reader)
|
public static NetworkIdentity ReadNetworkIdentity(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
uint netId = reader.ReadUInt32();
|
uint netId = reader.ReadUInt();
|
||||||
if (netId == 0)
|
if (netId == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -284,7 +317,7 @@ public static NetworkIdentity ReadNetworkIdentity(this NetworkReader reader)
|
|||||||
|
|
||||||
public static NetworkBehaviour ReadNetworkBehaviour(this NetworkReader reader)
|
public static NetworkBehaviour ReadNetworkBehaviour(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
uint netId = reader.ReadUInt32();
|
uint netId = reader.ReadUInt();
|
||||||
if (netId == 0)
|
if (netId == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -310,7 +343,7 @@ public static T ReadNetworkBehaviour<T>(this NetworkReader reader) where T : Net
|
|||||||
|
|
||||||
public static NetworkBehaviour.NetworkBehaviourSyncVar ReadNetworkBehaviourSyncVar(this NetworkReader reader)
|
public static NetworkBehaviour.NetworkBehaviourSyncVar ReadNetworkBehaviourSyncVar(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
uint netId = reader.ReadUInt32();
|
uint netId = reader.ReadUInt();
|
||||||
byte componentIndex = default;
|
byte componentIndex = default;
|
||||||
|
|
||||||
// if netId is not 0, then index is also sent to read before returning
|
// if netId is not 0, then index is also sent to read before returning
|
||||||
@ -324,7 +357,7 @@ public static NetworkBehaviour.NetworkBehaviourSyncVar ReadNetworkBehaviourSyncV
|
|||||||
|
|
||||||
public static List<T> ReadList<T>(this NetworkReader reader)
|
public static List<T> ReadList<T>(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
int length = reader.ReadInt32();
|
int length = reader.ReadInt();
|
||||||
if (length < 0)
|
if (length < 0)
|
||||||
return null;
|
return null;
|
||||||
List<T> result = new List<T>(length);
|
List<T> result = new List<T>(length);
|
||||||
@ -337,7 +370,7 @@ public static List<T> ReadList<T>(this NetworkReader reader)
|
|||||||
|
|
||||||
public static T[] ReadArray<T>(this NetworkReader reader)
|
public static T[] ReadArray<T>(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
int length = reader.ReadInt32();
|
int length = reader.ReadInt();
|
||||||
|
|
||||||
// we write -1 for null
|
// we write -1 for null
|
||||||
if (length < 0)
|
if (length < 0)
|
||||||
|
@ -130,7 +130,7 @@ public void OnDeserializeAll(NetworkReader reader)
|
|||||||
IsReadOnly = true;
|
IsReadOnly = true;
|
||||||
|
|
||||||
// if init, write the full list content
|
// if init, write the full list content
|
||||||
int count = (int)reader.ReadUInt32();
|
int count = (int)reader.ReadUInt();
|
||||||
|
|
||||||
objects.Clear();
|
objects.Clear();
|
||||||
changes.Clear();
|
changes.Clear();
|
||||||
@ -145,7 +145,7 @@ public void OnDeserializeAll(NetworkReader reader)
|
|||||||
// We will need to skip all these changes
|
// We will need to skip all these changes
|
||||||
// the next time the list is synchronized
|
// the next time the list is synchronized
|
||||||
// because they have already been applied
|
// because they have already been applied
|
||||||
changesAhead = (int)reader.ReadUInt32();
|
changesAhead = (int)reader.ReadUInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDeserializeDelta(NetworkReader reader)
|
public void OnDeserializeDelta(NetworkReader reader)
|
||||||
@ -153,7 +153,7 @@ public void OnDeserializeDelta(NetworkReader reader)
|
|||||||
// This list can now only be modified by synchronization
|
// This list can now only be modified by synchronization
|
||||||
IsReadOnly = true;
|
IsReadOnly = true;
|
||||||
|
|
||||||
int changesCount = (int)reader.ReadUInt32();
|
int changesCount = (int)reader.ReadUInt();
|
||||||
|
|
||||||
for (int i = 0; i < changesCount; i++)
|
for (int i = 0; i < changesCount; i++)
|
||||||
{
|
{
|
||||||
|
@ -161,7 +161,7 @@ public void OnDeserializeAll(NetworkReader reader)
|
|||||||
IsReadOnly = true;
|
IsReadOnly = true;
|
||||||
|
|
||||||
// if init, write the full list content
|
// if init, write the full list content
|
||||||
int count = (int)reader.ReadUInt32();
|
int count = (int)reader.ReadUInt();
|
||||||
|
|
||||||
objects.Clear();
|
objects.Clear();
|
||||||
changes.Clear();
|
changes.Clear();
|
||||||
@ -175,7 +175,7 @@ public void OnDeserializeAll(NetworkReader reader)
|
|||||||
// We will need to skip all these changes
|
// We will need to skip all these changes
|
||||||
// the next time the list is synchronized
|
// the next time the list is synchronized
|
||||||
// because they have already been applied
|
// because they have already been applied
|
||||||
changesAhead = (int)reader.ReadUInt32();
|
changesAhead = (int)reader.ReadUInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDeserializeDelta(NetworkReader reader)
|
public void OnDeserializeDelta(NetworkReader reader)
|
||||||
@ -183,7 +183,7 @@ public void OnDeserializeDelta(NetworkReader reader)
|
|||||||
// This list can now only be modified by synchronization
|
// This list can now only be modified by synchronization
|
||||||
IsReadOnly = true;
|
IsReadOnly = true;
|
||||||
|
|
||||||
int changesCount = (int)reader.ReadUInt32();
|
int changesCount = (int)reader.ReadUInt();
|
||||||
|
|
||||||
for (int i = 0; i < changesCount; i++)
|
for (int i = 0; i < changesCount; i++)
|
||||||
{
|
{
|
||||||
@ -215,7 +215,7 @@ public void OnDeserializeDelta(NetworkReader reader)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Operation.OP_INSERT:
|
case Operation.OP_INSERT:
|
||||||
index = (int)reader.ReadUInt32();
|
index = (int)reader.ReadUInt();
|
||||||
newItem = reader.Read<T>();
|
newItem = reader.Read<T>();
|
||||||
if (apply)
|
if (apply)
|
||||||
{
|
{
|
||||||
@ -224,7 +224,7 @@ public void OnDeserializeDelta(NetworkReader reader)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Operation.OP_REMOVEAT:
|
case Operation.OP_REMOVEAT:
|
||||||
index = (int)reader.ReadUInt32();
|
index = (int)reader.ReadUInt();
|
||||||
if (apply)
|
if (apply)
|
||||||
{
|
{
|
||||||
oldItem = objects[index];
|
oldItem = objects[index];
|
||||||
@ -233,7 +233,7 @@ public void OnDeserializeDelta(NetworkReader reader)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Operation.OP_SET:
|
case Operation.OP_SET:
|
||||||
index = (int)reader.ReadUInt32();
|
index = (int)reader.ReadUInt();
|
||||||
newItem = reader.Read<T>();
|
newItem = reader.Read<T>();
|
||||||
if (apply)
|
if (apply)
|
||||||
{
|
{
|
||||||
|
@ -122,7 +122,7 @@ public void OnDeserializeAll(NetworkReader reader)
|
|||||||
IsReadOnly = true;
|
IsReadOnly = true;
|
||||||
|
|
||||||
// if init, write the full list content
|
// if init, write the full list content
|
||||||
int count = (int)reader.ReadUInt32();
|
int count = (int)reader.ReadUInt();
|
||||||
|
|
||||||
objects.Clear();
|
objects.Clear();
|
||||||
changes.Clear();
|
changes.Clear();
|
||||||
@ -136,7 +136,7 @@ public void OnDeserializeAll(NetworkReader reader)
|
|||||||
// We will need to skip all these changes
|
// We will need to skip all these changes
|
||||||
// the next time the list is synchronized
|
// the next time the list is synchronized
|
||||||
// because they have already been applied
|
// because they have already been applied
|
||||||
changesAhead = (int)reader.ReadUInt32();
|
changesAhead = (int)reader.ReadUInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDeserializeDelta(NetworkReader reader)
|
public void OnDeserializeDelta(NetworkReader reader)
|
||||||
@ -144,7 +144,7 @@ public void OnDeserializeDelta(NetworkReader reader)
|
|||||||
// This list can now only be modified by synchronization
|
// This list can now only be modified by synchronization
|
||||||
IsReadOnly = true;
|
IsReadOnly = true;
|
||||||
|
|
||||||
int changesCount = (int)reader.ReadUInt32();
|
int changesCount = (int)reader.ReadUInt();
|
||||||
|
|
||||||
for (int i = 0; i < changesCount; i++)
|
for (int i = 0; i < changesCount; i++)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@ public override void OnDeserialize(NetworkReader reader, bool initialState)
|
|||||||
{
|
{
|
||||||
base.OnDeserialize(reader, initialState);
|
base.OnDeserialize(reader, initialState);
|
||||||
|
|
||||||
value = reader.ReadInt32();
|
value = reader.ReadInt();
|
||||||
direction = reader.ReadVector3();
|
direction = reader.ReadVector3();
|
||||||
|
|
||||||
OnDeserializeCalled?.Invoke();
|
OnDeserializeCalled?.Invoke();
|
||||||
|
@ -25,7 +25,7 @@ public static void WriteQuest(this NetworkWriter writer, MockQuest quest)
|
|||||||
}
|
}
|
||||||
public static MockQuest WriteQuest(this NetworkReader reader)
|
public static MockQuest WriteQuest(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
return new MockQuest(reader.ReadInt32());
|
return new MockQuest(reader.ReadInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ public static void WriteMyCustomEnum(this NetworkWriter networkWriter, EnumReadW
|
|||||||
}
|
}
|
||||||
public static EnumReadWriteTests.MyCustomEnum ReadMyCustomEnum(this NetworkReader networkReader)
|
public static EnumReadWriteTests.MyCustomEnum ReadMyCustomEnum(this NetworkReader networkReader)
|
||||||
{
|
{
|
||||||
return (EnumReadWriteTests.MyCustomEnum)networkReader.ReadInt32();
|
return (EnumReadWriteTests.MyCustomEnum)networkReader.ReadInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class EnumReadWriteTests
|
public class EnumReadWriteTests
|
||||||
|
@ -26,7 +26,7 @@ public static T UnpackFromByteArray<T>(byte[] data)
|
|||||||
{
|
{
|
||||||
int msgType = MessagePacking.GetId<T>();
|
int msgType = MessagePacking.GetId<T>();
|
||||||
|
|
||||||
int id = networkReader.ReadUInt16();
|
int id = networkReader.ReadUShort();
|
||||||
if (id != msgType)
|
if (id != msgType)
|
||||||
throw new FormatException("Invalid message, could not unpack " + typeof(T).FullName);
|
throw new FormatException("Invalid message, could not unpack " + typeof(T).FullName);
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public override bool OnSerialize(NetworkWriter writer, bool initialState)
|
|||||||
}
|
}
|
||||||
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
||||||
{
|
{
|
||||||
customSerializeField = reader.ReadSingle();
|
customSerializeField = reader.ReadFloat();
|
||||||
base.OnDeserialize(reader, initialState);
|
base.OnDeserialize(reader, initialState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ public override bool OnSerialize(NetworkWriter writer, bool initialState)
|
|||||||
}
|
}
|
||||||
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
||||||
{
|
{
|
||||||
customSerializeField = reader.ReadSingle();
|
customSerializeField = reader.ReadFloat();
|
||||||
base.OnDeserialize(reader, initialState);
|
base.OnDeserialize(reader, initialState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ public override bool OnSerialize(NetworkWriter writer, bool initialState)
|
|||||||
}
|
}
|
||||||
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
||||||
{
|
{
|
||||||
customSerializeField = reader.ReadSingle();
|
customSerializeField = reader.ReadFloat();
|
||||||
base.OnDeserialize(reader, initialState);
|
base.OnDeserialize(reader, initialState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ public override bool OnSerialize(NetworkWriter writer, bool initialState)
|
|||||||
}
|
}
|
||||||
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
||||||
{
|
{
|
||||||
value = reader.ReadInt32();
|
value = reader.ReadInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ public override bool OnSerialize(NetworkWriter writer, bool initialState)
|
|||||||
}
|
}
|
||||||
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
public override void OnDeserialize(NetworkReader reader, bool initialState)
|
||||||
{
|
{
|
||||||
value = reader.ReadInt32();
|
value = reader.ReadInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public TestMessage(int i, string s, double d)
|
|||||||
|
|
||||||
public void Deserialize(NetworkReader reader)
|
public void Deserialize(NetworkReader reader)
|
||||||
{
|
{
|
||||||
IntValue = reader.ReadInt32();
|
IntValue = reader.ReadInt();
|
||||||
StringValue = reader.ReadString();
|
StringValue = reader.ReadString();
|
||||||
DoubleValue = reader.ReadDouble();
|
DoubleValue = reader.ReadDouble();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public TestMessage1(int i, string s, double d)
|
|||||||
|
|
||||||
public void Deserialize(NetworkReader reader)
|
public void Deserialize(NetworkReader reader)
|
||||||
{
|
{
|
||||||
IntValue = reader.ReadInt32();
|
IntValue = reader.ReadInt();
|
||||||
StringValue = reader.ReadString();
|
StringValue = reader.ReadString();
|
||||||
DoubleValue = reader.ReadDouble();
|
DoubleValue = reader.ReadDouble();
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public void SerializeIntoWriterTest()
|
|||||||
NetworkTransformBase.SerializeIntoWriter(writer, position, rotation, scale, true, true);
|
NetworkTransformBase.SerializeIntoWriter(writer, position, rotation, scale, true, true);
|
||||||
NetworkReader reader = new NetworkReader(writer.ToArray());
|
NetworkReader reader = new NetworkReader(writer.ToArray());
|
||||||
Assert.That(reader.ReadVector3(), Is.EqualTo(position));
|
Assert.That(reader.ReadVector3(), Is.EqualTo(position));
|
||||||
Assert.That(reader.ReadUInt32(), Is.EqualTo(Compression.CompressQuaternion(rotation)));
|
Assert.That(reader.ReadUInt(), Is.EqualTo(Compression.CompressQuaternion(rotation)));
|
||||||
Assert.That(reader.ReadVector3(), Is.EqualTo(scale));
|
Assert.That(reader.ReadVector3(), Is.EqualTo(scale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public void HasReadFunctionForInt()
|
|||||||
{
|
{
|
||||||
Assert.That(Reader<int>.read, Is.Not.Null, "int read function was not found");
|
Assert.That(Reader<int>.read, Is.Not.Null, "int read function was not found");
|
||||||
|
|
||||||
Func<NetworkReader, int> action = NetworkReaderExtensions.ReadInt32;
|
Func<NetworkReader, int> action = NetworkReaderExtensions.ReadInt;
|
||||||
Assert.That(Reader<int>.read, Is.EqualTo(action), "int read function was incorrect value");
|
Assert.That(Reader<int>.read, Is.EqualTo(action), "int read function was incorrect value");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,15 +157,15 @@ void EnsureThrows(Action<NetworkReader> read, byte[] data = null)
|
|||||||
EnsureThrows(r => r.ReadByte());
|
EnsureThrows(r => r.ReadByte());
|
||||||
EnsureThrows(r => r.ReadSByte());
|
EnsureThrows(r => r.ReadSByte());
|
||||||
EnsureThrows(r => r.ReadChar());
|
EnsureThrows(r => r.ReadChar());
|
||||||
EnsureThrows(r => r.ReadBoolean());
|
EnsureThrows(r => r.ReadBool());
|
||||||
EnsureThrows(r => r.ReadInt16());
|
EnsureThrows(r => r.ReadShort());
|
||||||
EnsureThrows(r => r.ReadUInt16());
|
EnsureThrows(r => r.ReadUShort());
|
||||||
EnsureThrows(r => r.ReadInt32());
|
EnsureThrows(r => r.ReadInt());
|
||||||
EnsureThrows(r => r.ReadUInt32());
|
EnsureThrows(r => r.ReadUInt());
|
||||||
EnsureThrows(r => r.ReadInt64());
|
EnsureThrows(r => r.ReadLong());
|
||||||
EnsureThrows(r => r.ReadUInt64());
|
EnsureThrows(r => r.ReadULong());
|
||||||
EnsureThrows(r => r.ReadDecimal());
|
EnsureThrows(r => r.ReadDecimal());
|
||||||
EnsureThrows(r => r.ReadSingle());
|
EnsureThrows(r => r.ReadFloat());
|
||||||
EnsureThrows(r => r.ReadDouble());
|
EnsureThrows(r => r.ReadDouble());
|
||||||
EnsureThrows(r => r.ReadString());
|
EnsureThrows(r => r.ReadString());
|
||||||
EnsureThrows(r => r.ReadBytes(1));
|
EnsureThrows(r => r.ReadBytes(1));
|
||||||
@ -618,7 +618,7 @@ public void TestFloats()
|
|||||||
NetworkWriter writer = new NetworkWriter();
|
NetworkWriter writer = new NetworkWriter();
|
||||||
writer.WriteFloat(weird);
|
writer.WriteFloat(weird);
|
||||||
NetworkReader reader = new NetworkReader(writer.ToArray());
|
NetworkReader reader = new NetworkReader(writer.ToArray());
|
||||||
float readFloat = reader.ReadSingle();
|
float readFloat = reader.ReadFloat();
|
||||||
Assert.That(readFloat, Is.EqualTo(weird));
|
Assert.That(readFloat, Is.EqualTo(weird));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -877,14 +877,14 @@ public void TestWritingAndReading()
|
|||||||
Assert.That(reader.ReadChar(), Is.EqualTo(1));
|
Assert.That(reader.ReadChar(), Is.EqualTo(1));
|
||||||
Assert.That(reader.ReadByte(), Is.EqualTo(2));
|
Assert.That(reader.ReadByte(), Is.EqualTo(2));
|
||||||
Assert.That(reader.ReadSByte(), Is.EqualTo(3));
|
Assert.That(reader.ReadSByte(), Is.EqualTo(3));
|
||||||
Assert.That(reader.ReadBoolean(), Is.True);
|
Assert.That(reader.ReadBool(), Is.True);
|
||||||
Assert.That(reader.ReadInt16(), Is.EqualTo(4));
|
Assert.That(reader.ReadShort(), Is.EqualTo(4));
|
||||||
Assert.That(reader.ReadUInt16(), Is.EqualTo(5));
|
Assert.That(reader.ReadUShort(), Is.EqualTo(5));
|
||||||
Assert.That(reader.ReadInt32(), Is.EqualTo(6));
|
Assert.That(reader.ReadInt(), Is.EqualTo(6));
|
||||||
Assert.That(reader.ReadUInt32(), Is.EqualTo(7));
|
Assert.That(reader.ReadUInt(), Is.EqualTo(7));
|
||||||
Assert.That(reader.ReadInt64(), Is.EqualTo(8));
|
Assert.That(reader.ReadLong(), Is.EqualTo(8));
|
||||||
Assert.That(reader.ReadUInt64(), Is.EqualTo(9));
|
Assert.That(reader.ReadULong(), Is.EqualTo(9));
|
||||||
Assert.That(reader.ReadSingle(), Is.EqualTo(10));
|
Assert.That(reader.ReadFloat(), Is.EqualTo(10));
|
||||||
Assert.That(reader.ReadDouble(), Is.EqualTo(11));
|
Assert.That(reader.ReadDouble(), Is.EqualTo(11));
|
||||||
Assert.That(reader.ReadDecimal(), Is.EqualTo(12));
|
Assert.That(reader.ReadDecimal(), Is.EqualTo(12));
|
||||||
// writing null string should write null in Mirror ("" in original HLAPI)
|
// writing null string should write null in Mirror ("" in original HLAPI)
|
||||||
|
@ -399,7 +399,7 @@ public static uint GetChangeCount(this SyncObject syncObject)
|
|||||||
|
|
||||||
using (PooledNetworkReader reader = NetworkReaderPool.GetReader(writer.ToArraySegment()))
|
using (PooledNetworkReader reader = NetworkReaderPool.GetReader(writer.ToArraySegment()))
|
||||||
{
|
{
|
||||||
return reader.ReadUInt32();
|
return reader.ReadUInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public static void WriteSomeData(this NetworkWriter writer, SomeDataWithWriter i
|
|||||||
}
|
}
|
||||||
public static SomeDataWithWriter ReadSomeData(this NetworkReader reader)
|
public static SomeDataWithWriter ReadSomeData(this NetworkReader reader)
|
||||||
{
|
{
|
||||||
return new SomeDataWithWriter { usefulNumber = reader.ReadInt32() };
|
return new SomeDataWithWriter { usefulNumber = reader.ReadInt() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user