public static void RegisterClass <T>( Action <NetOutgoingMessage, object> customSerializer = null, Action <NetIncomingMessage, object> customDeserializer = null) where T : class, new() { SynchronizingInfo.RegisterSyncInfo(new SynchronizingInfo { Type = typeof(T), IsIdentifiable = false, ObjectConstructor = () => new T(), CustomSerializer = customSerializer, CustomDeserializer = customDeserializer }); ObjectSync.Sync.RegisterClass <T>(() => new T()); }
public static void RegisterIdentifiable <T>( Func <long, object> idToObject, Func <object, long> objectToId, Action <NetOutgoingMessage, object> customSerializer = null, Action <NetIncomingMessage, object> customDeserializer = null) where T : class, new() { SynchronizingInfo.RegisterSyncInfo(new SynchronizingInfo { Type = typeof(T), IsIdentifiable = true, ObjectConstructor = () => new T(), IdToObject = idToObject, ObjectToId = objectToId, CustomSerializer = customSerializer, CustomDeserializer = customDeserializer }); ObjectSync.Sync.RegisterClass <T>(() => new T()); }
public void RegisterTypes() { SynchronizingInfo.RegisterClass <LobbyPlayerList>(); SynchronizingInfo.RegisterClass <LobbyPlayerGreeting>(); SynchronizingInfo.RegisterClass <SerializedMatchSettings>(); SynchronizingInfo.RegisterClass <GameStartInfo>(); SynchronizingInfo.RegisterClass <Team>(); SynchronizingInfo.RegisterClass <Message>(); SynchronizingInfo.RegisterClass <NetworkMessage>(); SynchronizingInfo.RegisterClass <InputMessage>(); SynchronizingInfo.RegisterClass <Terrain.TerrainModification>(); SynchronizingInfo.RegisterClass <Session.NetSessionState>( (msg, obj) => ((Session.NetSessionState)obj).Serialize(msg), (msg, obj) => ((Session.NetSessionState)obj).Deserialize(msg) ); SynchronizingInfo.RegisterIdentifiable <Entity>( (id) => Ballz.The().Match.World.EntityById((int)id), (obj) => ((Entity)obj).ID, (msg, obj) => ((Entity)obj).Serialize(msg), (msg, obj) => ((Entity)obj).Deserialize(msg) ); SynchronizingInfo.RegisterIdentifiable <Ball>( (id) => Ballz.The().Match.World.EntityById((int)id), (obj) => ((Entity)obj).ID, (msg, obj) => ((Ball)obj).Serialize(msg), (msg, obj) => ((Ball)obj).Deserialize(msg) ); SynchronizingInfo.RegisterIdentifiable <Shot>( (id) => Ballz.The().Match.World.EntityById((int)id), (obj) => ((Entity)obj).ID, (msg, obj) => ((Shot)obj).Serialize(msg), (msg, obj) => ((Shot)obj).Deserialize(msg) ); }
private static void RegisterSyncInfo(SynchronizingInfo info) { InfoByType[info.Type] = info; InfoByTypeId[info.TypeId] = info; }