public CustomType(Type type, byte code, SerializeStreamMethod serializeFunction, DeserializeStreamMethod deserializeFunction) { this.Type = type; this.Code = code; this.SerializeStreamFunction = serializeFunction; this.DeserializeStreamFunction = deserializeFunction; }
/// <summary> /// Register serialization & deserialization mechanisms for transmitting the given class by ID. /// The given class does not need to implements its own serialization logic. /// </summary> public static void RegisterSerializerAndDeserializer(Type type) { int id = NetworkableId <Type> .ToId(type); Debug.Log("Using id " + id + " for tagging of class " + type.Name + " in network messages when sending/receiving NetworkableById types"); // Construct SerializerAndDeserializer<type> Type serializerAndDeserializerType = typeof(SerializerAndDeserializer <>); Type serializerAndDeserializerTypeSpecialized = serializerAndDeserializerType.MakeGenericType(type); // Find a method Serialize(StreamBuffer, object) in SerializerAndDeserializer<type> MethodInfo serializeMethodInfo = serializerAndDeserializerTypeSpecialized.GetMethod("Serialize", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public, null, new Type[] { typeof(StreamBuffer), typeof(object) }, null); Assert.IsNotNull(serializeMethodInfo, "Unable to find virtual Serialize(StreamBuffer, object) method in " + serializerAndDeserializerTypeSpecialized.Name); SerializeStreamMethod serializer = (SerializeStreamMethod)Delegate.CreateDelegate(typeof(SerializeStreamMethod), serializeMethodInfo); // Find a method Deserialize(StreamBuffer, short) in SerializerAndDeserializer<type> MethodInfo deserializeMethodInfo = serializerAndDeserializerTypeSpecialized.GetMethod("Deserialize", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public, null, new Type[] { typeof(StreamBuffer), typeof(short) }, null); Assert.IsNotNull(serializeMethodInfo, "Unable to find static Deserialize(StreamBuffer, short) method in " + serializerAndDeserializerTypeSpecialized.Name); DeserializeStreamMethod deserializer = (DeserializeStreamMethod)Delegate.CreateDelegate(typeof(DeserializeStreamMethod), deserializeMethodInfo); // Register serializer and deserializer methods for class bool success = PhotonPeer.RegisterType(type, (byte)id, serializer, deserializer); Assert.IsTrue(success, "Failed registering new serialization type for " + type.Name + " with code " + id); }
public SerializableTypeInfo(Type type, byte id, SerializeStreamMethod serializeFunction, DeserializeStreamMethod deserializeFunction) { this.Type = type; this.Id = id; this.SerializeStreamFunction = serializeFunction; this.DeserializeStreamFunction = deserializeFunction; }
public static void RegisterType(Type type, byte id, SerializeStreamMethod serializeFunction, DeserializeStreamMethod deserializeFunction) { if (TypeDict.ContainsKey(type) || IdDict.ContainsKey(id)) { throw new Exception("Type Already Registed :" + type + "/" + id); } SerializableTypeInfo customType = new SerializableTypeInfo(type, id, serializeFunction, deserializeFunction); TypeDict.Add(type, customType); IdDict.Add(id, customType); }
public static bool TryRegisterType(Type type, byte typeCode, SerializeStreamMethod serializeFunction, DeserializeStreamMethod deserializeFunction) { bool flag = Protocol.CodeDict.ContainsKey(typeCode) || Protocol.TypeDict.ContainsKey(type); bool result; if (flag) { result = false; } else { CustomType value = new CustomType(type, typeCode, serializeFunction, deserializeFunction); Protocol.CodeDict.Add(typeCode, value); Protocol.TypeDict.Add(type, value); result = true; } return(result); }
public static bool RegisterType(Type customType, byte code, SerializeStreamMethod serializeMethod, DeserializeStreamMethod constructor) { return(Protocol.TryRegisterType(customType, code, serializeMethod, constructor)); }
public static bool TryRegisterType(Type type, byte typeCode, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) => default; // 0x00000001806C6660-0x00000001806C6830 public static bool TryRegisterType(Type type, byte typeCode, SerializeStreamMethod serializeFunction, DeserializeStreamMethod deserializeFunction) => default; // 0x00000001806C6490-0x00000001806C6660
public static bool TryRegisterType(Type type, byte typeCode, SerializeStreamMethod serializeFunction, DeserializeStreamMethod deserializeFunction) { if (CodeDict.ContainsKey(typeCode) || TypeDict.ContainsKey(type)) { return(false); } CustomType value = new CustomType(type, typeCode, serializeFunction, deserializeFunction); CodeDict.Add(typeCode, value); TypeDict.Add(type, value); return(true); }
} // 0x00000001806ACFB0-0x00000001806AD020 public CustomType(Type type, byte code, SerializeStreamMethod serializeFunction, DeserializeStreamMethod deserializeFunction) { } // 0x00000001806AD020-0x00000001806AD090