Cleaned up SyncedVar system

This commit is contained in:
Albin Corén 2018-04-19 17:32:00 +02:00
parent afc45981f3
commit 438f4fa9c2
2 changed files with 150 additions and 525 deletions

View File

@ -1,4 +1,6 @@
using System;
using MLAPI.NetworkingManagerComponents.Binary;
using System;
using System.Reflection;
using UnityEngine;
namespace MLAPI.Data
@ -43,6 +45,137 @@ namespace MLAPI.Data
internal static class FieldTypeHelper
{
internal static void WriteFieldType(BitWriter writer, FieldInfo field, object fieldInstance, FieldType fieldType)
{
switch (fieldType)
{
case FieldType.Bool:
writer.WriteBool((bool)field.GetValue(fieldInstance));
break;
case FieldType.Byte:
writer.WriteByte((byte)field.GetValue(fieldInstance));
break;
case FieldType.Double:
writer.WriteDouble((double)field.GetValue(fieldInstance));
break;
case FieldType.Single:
writer.WriteFloat((float)field.GetValue(fieldInstance));
break;
case FieldType.Int:
writer.WriteInt((int)field.GetValue(fieldInstance));
break;
case FieldType.Long:
writer.WriteLong((long)field.GetValue(fieldInstance));
break;
case FieldType.SByte:
writer.WriteSByte((sbyte)field.GetValue(fieldInstance));
break;
case FieldType.Short:
writer.WriteShort((short)field.GetValue(fieldInstance));
break;
case FieldType.UInt:
writer.WriteUInt((uint)field.GetValue(fieldInstance));
break;
case FieldType.ULong:
writer.WriteULong((ulong)field.GetValue(fieldInstance));
break;
case FieldType.UShort:
writer.WriteUShort((ushort)field.GetValue(fieldInstance));
break;
case FieldType.String:
writer.WriteString((string)field.GetValue(fieldInstance));
break;
case FieldType.Vector3:
Vector3 vector3 = (Vector3)field.GetValue(fieldInstance);
writer.WriteFloat(vector3.x);
writer.WriteFloat(vector3.y);
writer.WriteFloat(vector3.z);
break;
case FieldType.Vector2:
Vector2 vector2 = (Vector2)field.GetValue(fieldInstance);
writer.WriteFloat(vector2.x);
writer.WriteFloat(vector2.y);
break;
case FieldType.Quaternion:
Vector3 euler = ((Quaternion)field.GetValue(fieldInstance)).eulerAngles;
writer.WriteFloat(euler.x);
writer.WriteFloat(euler.y);
writer.WriteFloat(euler.z);
break;
case FieldType.BoolArray:
bool[] bools = (bool[])field.GetValue(fieldInstance);
writer.WriteUShort((ushort)bools.Length);
for (int j = 0; j < bools.Length; j++)
writer.WriteBool(bools[j]);
break;
case FieldType.ByteArray:
writer.WriteByteArray((byte[])field.GetValue(fieldInstance));
break;
case FieldType.DoubleArray:
writer.WriteDoubleArray((double[])field.GetValue(fieldInstance));
break;
case FieldType.SingleArray:
writer.WriteFloatArray((float[])field.GetValue(fieldInstance));
break;
case FieldType.IntArray:
writer.WriteIntArray((int[])field.GetValue(fieldInstance));
break;
case FieldType.LongArray:
writer.WriteLongArray((long[])field.GetValue(fieldInstance));
break;
case FieldType.SByteArray:
writer.WriteSByteArray((sbyte[])field.GetValue(fieldInstance));
break;
case FieldType.ShortArray:
writer.WriteShortArray((short[])field.GetValue(fieldInstance));
break;
case FieldType.UIntArray:
writer.WriteUIntArray((uint[])field.GetValue(fieldInstance));
break;
case FieldType.ULongArray:
writer.WriteULongArray((ulong[])field.GetValue(fieldInstance));
break;
case FieldType.UShortArray:
writer.WriteUShortArray((ushort[])field.GetValue(fieldInstance));
break;
case FieldType.StringArray:
string[] strings = (string[])field.GetValue(fieldInstance);
writer.WriteUShort((ushort)strings.Length);
for (int j = 0; j < strings.Length; j++)
writer.WriteString(strings[j]);
break;
case FieldType.Vector3Array:
Vector3[] vector3s = (Vector3[])field.GetValue(fieldInstance);
writer.WriteUShort((ushort)vector3s.Length);
for (int j = 0; j < vector3s.Length; j++)
{
writer.WriteFloat(vector3s[j].x);
writer.WriteFloat(vector3s[j].y);
writer.WriteFloat(vector3s[j].z);
}
break;
case FieldType.Vector2Array:
Vector2[] vector2s = (Vector2[])field.GetValue(fieldInstance);
writer.WriteUShort((ushort)vector2s.Length);
for (int j = 0; j < vector2s.Length; j++)
{
writer.WriteFloat(vector2s[j].x);
writer.WriteFloat(vector2s[j].y);
}
break;
case FieldType.QuaternionArray:
Quaternion[] quaternions = (Quaternion[])field.GetValue(fieldInstance);
writer.WriteUShort((ushort)quaternions.Length);
for (int j = 0; j < quaternions.Length; j++)
{
writer.WriteFloat(quaternions[j].eulerAngles.x);
writer.WriteFloat(quaternions[j].eulerAngles.y);
writer.WriteFloat(quaternions[j].eulerAngles.z);
}
break;
}
}
internal static FieldType GetFieldType(Type type)
{
if (type == typeof(bool))

View File

@ -279,134 +279,7 @@ namespace MLAPI.MonoBehaviours.Core
if (syncedVarFields[i].Target && clientId != ownerClientId)
continue;
writer.WriteByte(i); //FieldIndex
switch (syncedVarFields[i].FieldType)
{
case FieldType.Bool:
writer.WriteBool((bool)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Byte:
writer.WriteByte((byte)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Double:
writer.WriteDouble((double)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Single:
writer.WriteFloat((float)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Int:
writer.WriteInt((int)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Long:
writer.WriteLong((long)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SByte:
writer.WriteSByte((sbyte)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Short:
writer.WriteShort((short)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UInt:
writer.WriteUInt((uint)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ULong:
writer.WriteULong((ulong)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UShort:
writer.WriteUShort((ushort)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.String:
writer.WriteString((string)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Vector3:
Vector3 vector3 = (Vector3)syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteFloat(vector3.x);
writer.WriteFloat(vector3.y);
writer.WriteFloat(vector3.z);
break;
case FieldType.Vector2:
Vector2 vector2 = (Vector2)syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteFloat(vector2.x);
writer.WriteFloat(vector2.y);
break;
case FieldType.Quaternion:
Vector3 euler = ((Quaternion)syncedVarFields[i].FieldInfo.GetValue(this)).eulerAngles;
writer.WriteFloat(euler.x);
writer.WriteFloat(euler.y);
writer.WriteFloat(euler.z);
break;
case FieldType.BoolArray:
bool[] bools = (bool[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)bools.Length);
for (int j = 0; j < bools.Length; j++)
writer.WriteBool(bools[j]);
break;
case FieldType.ByteArray:
writer.WriteByteArray((byte[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.DoubleArray:
writer.WriteDoubleArray((double[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SingleArray:
writer.WriteFloatArray((float[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.IntArray:
writer.WriteIntArray((int[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.LongArray:
writer.WriteLongArray((long[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SByteArray:
writer.WriteSByteArray((sbyte[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ShortArray:
writer.WriteShortArray((short[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UIntArray:
writer.WriteUIntArray((uint[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ULongArray:
writer.WriteULongArray((ulong[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UShortArray:
writer.WriteUShortArray((ushort[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.StringArray:
string[] strings = (string[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)strings.Length);
for (int j = 0; j < strings.Length; j++)
writer.WriteString(strings[j]);
break;
case FieldType.Vector3Array:
Vector3[] vector3s = (Vector3[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)vector3s.Length);
for (int j = 0; j < vector3s.Length; j++)
{
writer.WriteFloat(vector3s[j].x);
writer.WriteFloat(vector3s[j].y);
writer.WriteFloat(vector3s[j].z);
}
break;
case FieldType.Vector2Array:
Vector2[] vector2s = (Vector2[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)vector2s.Length);
for (int j = 0; j < vector2s.Length; j++)
{
writer.WriteFloat(vector2s[j].x);
writer.WriteFloat(vector2s[j].y);
}
break;
case FieldType.QuaternionArray:
Quaternion[] quaternions = (Quaternion[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)quaternions.Length);
for (int j = 0; j < quaternions.Length; j++)
{
writer.WriteFloat(quaternions[j].eulerAngles.x);
writer.WriteFloat(quaternions[j].eulerAngles.y);
writer.WriteFloat(quaternions[j].eulerAngles.z);
}
break;
}
FieldTypeHelper.WriteFieldType(writer, syncedVarFields[i].FieldInfo, this, syncedVarFields[i].FieldType);
}
InternalMessageHandler.Send(clientId, "MLAPI_SYNC_VAR_UPDATE", "MLAPI_INTERNAL", writer.Finalize());
}
@ -453,133 +326,7 @@ namespace MLAPI.MonoBehaviours.Core
if (syncedVarFields[i].Dirty == true)
{
writer.WriteByte(i); //FieldIndex
switch (syncedVarFields[i].FieldType)
{
case FieldType.Bool:
writer.WriteBool((bool)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Byte:
writer.WriteByte((byte)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Double:
writer.WriteDouble((double)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Single:
writer.WriteFloat((float)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Int:
writer.WriteInt((int)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Long:
writer.WriteLong((long)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SByte:
writer.WriteSByte((sbyte)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Short:
writer.WriteShort((short)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UInt:
writer.WriteUInt((uint)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ULong:
writer.WriteULong((ulong)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UShort:
writer.WriteUShort((ushort)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.String:
writer.WriteString((string)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Vector3:
Vector3 vector3 = (Vector3)syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteFloat(vector3.x);
writer.WriteFloat(vector3.y);
writer.WriteFloat(vector3.z);
break;
case FieldType.Vector2:
Vector2 vector2 = (Vector2)syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteFloat(vector2.x);
writer.WriteFloat(vector2.y);
break;
case FieldType.Quaternion:
Vector3 euler = ((Quaternion)syncedVarFields[i].FieldInfo.GetValue(this)).eulerAngles;
writer.WriteFloat(euler.x);
writer.WriteFloat(euler.y);
writer.WriteFloat(euler.z);
break;
case FieldType.BoolArray:
bool[] bools = (bool[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)bools.Length);
for (int j = 0; j < bools.Length; j++)
writer.WriteBool(bools[j]);
break;
case FieldType.ByteArray:
writer.WriteByteArray((byte[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.DoubleArray:
writer.WriteDoubleArray((double[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SingleArray:
writer.WriteFloatArray((float[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.IntArray:
writer.WriteIntArray((int[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.LongArray:
writer.WriteLongArray((long[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SByteArray:
writer.WriteSByteArray((sbyte[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ShortArray:
writer.WriteShortArray((short[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UIntArray:
writer.WriteUIntArray((uint[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ULongArray:
writer.WriteULongArray((ulong[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UShortArray:
writer.WriteUShortArray((ushort[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.StringArray:
string[] strings = (string[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)strings.Length);
for (int j = 0; j < strings.Length; j++)
writer.WriteString(strings[j]);
break;
case FieldType.Vector3Array:
Vector3[] vector3s = (Vector3[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)vector3s.Length);
for (int j = 0; j < vector3s.Length; j++)
{
writer.WriteFloat(vector3s[j].x);
writer.WriteFloat(vector3s[j].y);
writer.WriteFloat(vector3s[j].z);
}
break;
case FieldType.Vector2Array:
Vector2[] vector2s = (Vector2[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)vector2s.Length);
for (int j = 0; j < vector2s.Length; j++)
{
writer.WriteFloat(vector2s[j].x);
writer.WriteFloat(vector2s[j].y);
}
break;
case FieldType.QuaternionArray:
Quaternion[] quaternions = (Quaternion[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)quaternions.Length);
for (int j = 0; j < quaternions.Length; j++)
{
writer.WriteFloat(quaternions[j].eulerAngles.x);
writer.WriteFloat(quaternions[j].eulerAngles.y);
writer.WriteFloat(quaternions[j].eulerAngles.z);
}
break;
}
FieldTypeHelper.WriteFieldType(writer, syncedVarFields[i].FieldInfo, this, syncedVarFields[i].FieldType);
syncedVarFields[i].FieldValue = syncedVarFields[i].FieldInfo.GetValue(this);
syncedVarFields[i].Dirty = false;
}
@ -604,134 +351,7 @@ namespace MLAPI.MonoBehaviours.Core
if (syncedVarFields[i].Dirty == true)
{
writer.WriteByte(i); //FieldIndex
switch (syncedVarFields[i].FieldType)
{
case FieldType.Bool:
writer.WriteBool((bool)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Byte:
writer.WriteByte((byte)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Double:
writer.WriteDouble((double)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Single:
writer.WriteFloat((float)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Int:
writer.WriteInt((int)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Long:
writer.WriteLong((long)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SByte:
writer.WriteSByte((sbyte)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Short:
writer.WriteShort((short)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UInt:
writer.WriteUInt((uint)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ULong:
writer.WriteULong((ulong)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UShort:
writer.WriteUShort((ushort)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.String:
writer.WriteString((string)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Vector3:
Vector3 vector3 = (Vector3)syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteFloat(vector3.x);
writer.WriteFloat(vector3.y);
writer.WriteFloat(vector3.z);
break;
case FieldType.Vector2:
Vector2 vector2 = (Vector2)syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteFloat(vector2.x);
writer.WriteFloat(vector2.y);
break;
case FieldType.Quaternion:
Vector3 euler = ((Quaternion)syncedVarFields[i].FieldInfo.GetValue(this)).eulerAngles;
writer.WriteFloat(euler.x);
writer.WriteFloat(euler.y);
writer.WriteFloat(euler.z);
break;
case FieldType.BoolArray:
bool[] bools = (bool[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)bools.Length);
for (int j = 0; j < bools.Length; j++)
writer.WriteBool(bools[j]);
break;
case FieldType.ByteArray:
writer.WriteByteArray((byte[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.DoubleArray:
writer.WriteDoubleArray((double[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SingleArray:
writer.WriteFloatArray((float[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.IntArray:
writer.WriteIntArray((int[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.LongArray:
writer.WriteLongArray((long[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SByteArray:
writer.WriteSByteArray((sbyte[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ShortArray:
writer.WriteShortArray((short[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UIntArray:
writer.WriteUIntArray((uint[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ULongArray:
writer.WriteULongArray((ulong[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UShortArray:
writer.WriteUShortArray((ushort[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.StringArray:
string[] strings = (string[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)strings.Length);
for (int j = 0; j < strings.Length; j++)
writer.WriteString(strings[j]);
break;
case FieldType.Vector3Array:
Vector3[] vector3s = (Vector3[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)vector3s.Length);
for (int j = 0; j < vector3s.Length; j++)
{
writer.WriteFloat(vector3s[j].x);
writer.WriteFloat(vector3s[j].y);
writer.WriteFloat(vector3s[j].z);
}
break;
case FieldType.Vector2Array:
Vector2[] vector2s = (Vector2[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)vector2s.Length);
for (int j = 0; j < vector2s.Length; j++)
{
writer.WriteFloat(vector2s[j].x);
writer.WriteFloat(vector2s[j].y);
}
break;
case FieldType.QuaternionArray:
Quaternion[] quaternions = (Quaternion[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)quaternions.Length);
for (int j = 0; j < quaternions.Length; j++)
{
writer.WriteFloat(quaternions[j].eulerAngles.x);
writer.WriteFloat(quaternions[j].eulerAngles.y);
writer.WriteFloat(quaternions[j].eulerAngles.z);
}
break;
}
FieldTypeHelper.WriteFieldType(writer, syncedVarFields[i].FieldInfo, this, syncedVarFields[i].FieldType);
if (nonTargetDirtyCount == 0)
{
//Only targeted SyncedVars were changed. Thus we need to set them as non dirty here since it wont be done by the next loop.
@ -750,149 +370,21 @@ namespace MLAPI.MonoBehaviours.Core
//It's sync time. This is the NON target receivers packet.
using (BitWriter writer = new BitWriter())
{
//Write all indexes
writer.WriteByte(nonTargetDirtyCount);
writer.WriteUInt(networkId); //NetId
writer.WriteUShort(networkedObject.GetOrderIndex(this)); //Behaviour OrderIndex
for (byte i = 0; i < syncedVarFields.Count; i++)
//Write all indexes
writer.WriteByte(nonTargetDirtyCount);
writer.WriteUInt(networkId); //NetId
writer.WriteUShort(networkedObject.GetOrderIndex(this)); //Behaviour OrderIndex
for (byte i = 0; i < syncedVarFields.Count; i++)
{
//Writes all the indexes of the dirty syncvars.
if (syncedVarFields[i].Dirty == true && !syncedVarFields[i].Target)
{
//Writes all the indexes of the dirty syncvars.
if (syncedVarFields[i].Dirty == true && !syncedVarFields[i].Target)
{
writer.WriteByte(i); //FieldIndex
switch (syncedVarFields[i].FieldType)
{
case FieldType.Bool:
writer.WriteBool((bool)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Byte:
writer.WriteByte((byte)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Double:
writer.WriteDouble((double)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Single:
writer.WriteFloat((float)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Int:
writer.WriteInt((int)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Long:
writer.WriteLong((long)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SByte:
writer.WriteSByte((sbyte)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Short:
writer.WriteShort((short)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UInt:
writer.WriteUInt((uint)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ULong:
writer.WriteULong((ulong)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UShort:
writer.WriteUShort((ushort)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.String:
writer.WriteString((string)syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.Vector3:
Vector3 vector3 = (Vector3)syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteFloat(vector3.x);
writer.WriteFloat(vector3.y);
writer.WriteFloat(vector3.z);
break;
case FieldType.Vector2:
Vector2 vector2 = (Vector2)syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteFloat(vector2.x);
writer.WriteFloat(vector2.y);
break;
case FieldType.Quaternion:
Vector3 euler = ((Quaternion)syncedVarFields[i].FieldInfo.GetValue(this)).eulerAngles;
writer.WriteFloat(euler.x);
writer.WriteFloat(euler.y);
writer.WriteFloat(euler.z);
break;
case FieldType.BoolArray:
bool[] bools = (bool[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)bools.Length);
for (int j = 0; j < bools.Length; j++)
writer.WriteBool(bools[j]);
break;
case FieldType.ByteArray:
writer.WriteByteArray((byte[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.DoubleArray:
writer.WriteDoubleArray((double[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SingleArray:
writer.WriteFloatArray((float[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.IntArray:
writer.WriteIntArray((int[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.LongArray:
writer.WriteLongArray((long[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.SByteArray:
writer.WriteSByteArray((sbyte[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ShortArray:
writer.WriteShortArray((short[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UIntArray:
writer.WriteUIntArray((uint[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.ULongArray:
writer.WriteULongArray((ulong[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.UShortArray:
writer.WriteUShortArray((ushort[])syncedVarFields[i].FieldInfo.GetValue(this));
break;
case FieldType.StringArray:
string[] strings = (string[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)strings.Length);
for (int j = 0; j < strings.Length; j++)
writer.WriteString(strings[j]);
break;
case FieldType.Vector3Array:
Vector3[] vector3s = (Vector3[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)vector3s.Length);
for (int j = 0; j < vector3s.Length; j++)
{
writer.WriteFloat(vector3s[j].x);
writer.WriteFloat(vector3s[j].y);
writer.WriteFloat(vector3s[j].z);
}
break;
case FieldType.Vector2Array:
Vector2[] vector2s = (Vector2[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)vector2s.Length);
for (int j = 0; j < vector2s.Length; j++)
{
writer.WriteFloat(vector2s[j].x);
writer.WriteFloat(vector2s[j].y);
}
break;
case FieldType.QuaternionArray:
Quaternion[] quaternions = (Quaternion[])syncedVarFields[i].FieldInfo.GetValue(this);
writer.WriteUShort((ushort)quaternions.Length);
for (int j = 0; j < quaternions.Length; j++)
{
writer.WriteFloat(quaternions[j].eulerAngles.x);
writer.WriteFloat(quaternions[j].eulerAngles.y);
writer.WriteFloat(quaternions[j].eulerAngles.z);
}
break;
}
syncedVarFields[i].FieldValue = syncedVarFields[i].FieldInfo.GetValue(this);
syncedVarFields[i].Dirty = false;
}
writer.WriteByte(i); //FieldIndex
FieldTypeHelper.WriteFieldType(writer, syncedVarFields[i].FieldInfo, this, syncedVarFields[i].FieldType);
syncedVarFields[i].FieldValue = syncedVarFields[i].FieldInfo.GetValue(this);
syncedVarFields[i].Dirty = false;
}
}
InternalMessageHandler.Send("MLAPI_SYNC_VAR_UPDATE", "MLAPI_INTERNAL", writer.Finalize(), ownerClientId); // Send to everyone except target.
}
}