/// Serialization function for a list of IUnifiedSerializable. /// T must have an public parameterless constructor. public static void Serialize <T>(this IUnifiedSerializer s, ref List <T> list) where T : IUnifiedSerializable, new() { int numElements = s.isWriting ? list.Count : 0; s.Serialize(ref numElements); if (s.isWriting) { for (int i = 0; i < numElements; ++i) { list[i].Serialize(s); } } else { list = new List <T>(numElements); for (int i = 0; i < numElements; ++i) { var element = new T(); element.Serialize(s); list.Add(element); } } }
public static void Serialize(this IUnifiedSerializer s, ref Quaternion value) { s.Serialize(ref value.x); s.Serialize(ref value.y); s.Serialize(ref value.z); s.Serialize(ref value.w); }
public override void Serialize(IUnifiedSerializer s) { s.Serialize(ref isReject); if (isReject) { s.Serialize(ref rejectionMessage); } }
public override void Serialize(IUnifiedSerializer s) { int value = (int)kind; s.Serialize(ref value); kind = (Kind)value; s.Serialize(ref message); }
public void Serialize(IUnifiedSerializer s) { s.Serialize(ref id); bool isNicknameNull = nickname == null; s.Serialize(ref isNicknameNull); if (!isNicknameNull) { s.Serialize(ref nickname); } }
/// A helper function. Serializes/deserializes objects of non-primitive types. public static void Serialize <T>(this IUnifiedSerializer s, ref T serializable) where T : IUnifiedSerializable, new() { if (s.isReading) { serializable = new T(); } else { Assert.IsFalse(serializable == null, "Serializing a null is not supported yet. Prefix it with a boolean describing if it's a null or not manually."); } serializable.Serialize(s); }
public void Serialize(IUnifiedSerializer s) { byte value = (byte)currentPlayerColor; s.Serialize(ref value); currentPlayerColor = (TileState)value; Vector2Int sizeValue = size; s.Serialize(ref sizeValue); size = sizeValue; SerializeTiles(s); }
public static void Serialize(this IUnifiedSerializer s, ref Vector2Int value) { int x = value.x; int y = value.y; s.Serialize(ref x); s.Serialize(ref y); if (s.isReading) { value.x = x; value.y = y; } }
public override void Serialize(IUnifiedSerializer s) { s.Serialize(ref checkerboard); // TODO Extract this into an extension method for serializing any nullable. bool hasOtherPlayer = otherPlayerInfo.HasValue; s.Serialize(ref hasOtherPlayer); if (hasOtherPlayer) { PlayerInfo value = s.isWriting ? otherPlayerInfo.Value : new PlayerInfo(); s.Serialize(ref value); otherPlayerInfo = value; } }
/// Serialization function for an array of IUnifiedSerializable|s. /// T must have an public parameterless constructor. public static void Serialize <TElement>(this IUnifiedSerializer s, ref TElement[] array) where TElement : IUnifiedSerializable, new() { int numElements = s.isWriting ? array.Length : 0; s.Serialize(ref numElements); if (s.isReading) { array = new TElement[numElements]; } for (int i = 0; i < numElements; ++i) { s.Serialize(ref array[i]); } }
public static void Serialize(this IUnifiedSerializer s, ref string[] strings) { int numNames = strings?.Length ?? 0; s.Serialize(ref numNames); if (s.isReading) { strings = new string[numNames]; } Assert.IsNotNull(strings); for (int i = 0; i < numNames; ++i) { s.Serialize(ref strings[i]); } }
private void SerializeTiles(IUnifiedSerializer s) { if (s.isReading) { tiles = new TileState[size.x, size.y]; } for (int y = 0; y < size.y; ++y) { for (int x = 0; x < size.x; ++x) { byte value = (byte)tiles[x, y]; s.Serialize(ref value); tiles[x, y] = (TileState)value; } } }
/// Serialization function for an array of IUnifiedSerializable. /// T must have an public parameterless constructor. public static void Serialize <T>(this IUnifiedSerializer s, ref T[] array) where T : IUnifiedSerializable, new() { int numElements = s.isWriting ? array.Length : 0; s.Serialize(ref numElements); if (s.isWriting) { for (int i = 0; i < numElements; ++i) { array[i].Serialize(s); } } else { array = new T[numElements]; for (int i = 0; i < numElements; ++i) { array[i] = new T(); array[i].Serialize(s); } } }
public void Serialize(IUnifiedSerializer s) { }
public override void Serialize(IUnifiedSerializer s) { s.Serialize(ref message); }
public override void Serialize(IUnifiedSerializer s) { s.Serialize(ref checkerboard); s.Serialize(ref whitePlayerId); }
public static void Serialize(this IUnifiedSerializer s, ref Vector3 value) { s.Serialize(ref value.x); s.Serialize(ref value.y); s.Serialize(ref value.z); }
/// A helper function. Equivalent to serializable.Serialize(s). /// Exists just so that you could call s.Serialize on non-primitive types. public static void Serialize <T>(this IUnifiedSerializer s, ref T serializable) where T : IUnifiedSerializable, new() { serializable.Serialize(s); }
public override void Serialize(IUnifiedSerializer s) { s.Serialize(ref playerInfo); }
public override void Serialize(IUnifiedSerializer s) { s.Serialize(ref playerId); s.Serialize(ref nickname); }
public virtual void Serialize(IUnifiedSerializer s) { }
public override void Serialize(IUnifiedSerializer s) { s.Serialize(ref origin); s.Serialize(ref target); }
public override void Serialize(IUnifiedSerializer s) { s.Serialize(ref protocolIdentifier); s.Serialize(ref nickname); }