Added Byte arrays support to SyncVar.

This commit is contained in:
Albin Corén 2018-03-10 01:48:08 +01:00
parent c51dc5aa23
commit e7372d6cc3
2 changed files with 22 additions and 1 deletions

View File

@ -17,6 +17,7 @@
String,
Vector3,
Vector2,
Quaternion
Quaternion,
ByteArray
}
}

View File

@ -238,6 +238,12 @@ namespace MLAPI
syncedFieldValues.Add(sortedFields[i].GetValue(this));
syncedFieldTypes.Add(FieldType.Quaternion);
}
else if(sortedFields[i].FieldType == typeof(byte[]))
{
syncedFields.Add(sortedFields[i]);
syncedFieldValues.Add(sortedFields[i].GetValue(this));
syncedFieldTypes.Add(FieldType.ByteArray);
}
else
{
Debug.LogError("MLAPI: The type " + sortedFields[i].FieldType.ToString() + " can not be used as a syncvar");
@ -331,6 +337,10 @@ namespace MLAPI
writer.Write(euler.y);
writer.Write(euler.z);
break;
case FieldType.ByteArray:
writer.Write((ushort)((byte[])syncedFields[i].GetValue(this)).Length);
writer.Write((byte[])syncedFields[i].GetValue(this));
break;
}
}
}
@ -420,6 +430,10 @@ namespace MLAPI
writer.Write(euler.y);
writer.Write(euler.z);
break;
case FieldType.ByteArray:
writer.Write((ushort)((byte[])syncedFields[i].GetValue(this)).Length);
writer.Write((byte[])syncedFields[i].GetValue(this));
break;
}
syncedFieldValues[i] = syncedFields[i].GetValue(this);
@ -537,6 +551,12 @@ namespace MLAPI
else
dirtyFields[i] = false; //Up to date
break;
case FieldType.ByteArray:
if(((byte[])syncedFields[i].GetValue(this)).SequenceEqual(((byte[])syncedFieldValues[i])))
dirtyFields[i] = true; //This fields value is out of sync!
else
dirtyFields[i] = false; //Up to date
break;
}
}
}