use type safe register handler instead of casting (#49)

This commit is contained in:
Paul Pacheco 2018-09-30 03:27:55 -05:00 committed by vis2k
parent 3063273ad4
commit 0afd9f50ea
3 changed files with 38 additions and 38 deletions

View File

@ -198,31 +198,31 @@ internal static void RegisterSystemHandlers(NetworkClient client, bool localClie
{
if (localClient)
{
client.RegisterHandler((short)MsgType.ObjectDestroy, OnLocalClientObjectDestroy);
client.RegisterHandler((short)MsgType.ObjectHide, OnLocalClientObjectHide);
client.RegisterHandler((short)MsgType.SpawnPrefab, OnLocalClientSpawnPrefab);
client.RegisterHandler((short)MsgType.SpawnSceneObject, OnLocalClientSpawnSceneObject);
client.RegisterHandler((short)MsgType.LocalClientAuthority, OnClientAuthority);
client.RegisterHandler(MsgType.ObjectDestroy, OnLocalClientObjectDestroy);
client.RegisterHandler(MsgType.ObjectHide, OnLocalClientObjectHide);
client.RegisterHandler(MsgType.SpawnPrefab, OnLocalClientSpawnPrefab);
client.RegisterHandler(MsgType.SpawnSceneObject, OnLocalClientSpawnSceneObject);
client.RegisterHandler(MsgType.LocalClientAuthority, OnClientAuthority);
}
else
{
// LocalClient shares the sim/scene with the server, no need for these events
client.RegisterHandler((short)MsgType.SpawnPrefab, OnSpawnPrefab);
client.RegisterHandler((short)MsgType.SpawnSceneObject, OnSpawnSceneObject);
client.RegisterHandler((short)MsgType.SpawnFinished, OnObjectSpawnFinished);
client.RegisterHandler((short)MsgType.ObjectDestroy, OnObjectDestroy);
client.RegisterHandler((short)MsgType.ObjectHide, OnObjectDestroy);
client.RegisterHandler((short)MsgType.UpdateVars, OnUpdateVarsMessage);
client.RegisterHandler((short)MsgType.Owner, OnOwnerMessage);
client.RegisterHandler((short)MsgType.SyncList, OnSyncListMessage);
client.RegisterHandler((short)MsgType.Animation, NetworkAnimator.OnAnimationClientMessage);
client.RegisterHandler((short)MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersClientMessage);
client.RegisterHandler((short)MsgType.LocalClientAuthority, OnClientAuthority);
client.RegisterHandler(MsgType.SpawnPrefab, OnSpawnPrefab);
client.RegisterHandler(MsgType.SpawnSceneObject, OnSpawnSceneObject);
client.RegisterHandler(MsgType.SpawnFinished, OnObjectSpawnFinished);
client.RegisterHandler(MsgType.ObjectDestroy, OnObjectDestroy);
client.RegisterHandler(MsgType.ObjectHide, OnObjectDestroy);
client.RegisterHandler(MsgType.UpdateVars, OnUpdateVarsMessage);
client.RegisterHandler(MsgType.Owner, OnOwnerMessage);
client.RegisterHandler(MsgType.SyncList, OnSyncListMessage);
client.RegisterHandler(MsgType.Animation, NetworkAnimator.OnAnimationClientMessage);
client.RegisterHandler(MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersClientMessage);
client.RegisterHandler(MsgType.LocalClientAuthority, OnClientAuthority);
}
client.RegisterHandler((short)MsgType.Rpc, OnRPCMessage);
client.RegisterHandler((short)MsgType.SyncEvent, OnSyncEventMessage);
client.RegisterHandler((short)MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerClientMessage);
client.RegisterHandler(MsgType.Rpc, OnRPCMessage);
client.RegisterHandler(MsgType.SyncEvent, OnSyncEventMessage);
client.RegisterHandler(MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerClientMessage);
}
// ------------------------ NetworkScene pass-throughs ---------------------

View File

@ -182,12 +182,12 @@ void OnValidate()
internal void RegisterServerMessages()
{
NetworkServer.RegisterHandler((short)MsgType.Connect, OnServerConnectInternal);
NetworkServer.RegisterHandler((short)MsgType.Disconnect, OnServerDisconnectInternal);
NetworkServer.RegisterHandler((short)MsgType.Ready, OnServerReadyMessageInternal);
NetworkServer.RegisterHandler((short)MsgType.AddPlayer, OnServerAddPlayerMessageInternal);
NetworkServer.RegisterHandler((short)MsgType.RemovePlayer, OnServerRemovePlayerMessageInternal);
NetworkServer.RegisterHandler((short)MsgType.Error, OnServerErrorInternal);
NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnectInternal);
NetworkServer.RegisterHandler(MsgType.Disconnect, OnServerDisconnectInternal);
NetworkServer.RegisterHandler(MsgType.Ready, OnServerReadyMessageInternal);
NetworkServer.RegisterHandler(MsgType.AddPlayer, OnServerAddPlayerMessageInternal);
NetworkServer.RegisterHandler(MsgType.RemovePlayer, OnServerRemovePlayerMessageInternal);
NetworkServer.RegisterHandler(MsgType.Error, OnServerErrorInternal);
}
public bool StartServer()
@ -247,11 +247,11 @@ public bool StartServer()
internal void RegisterClientMessages(NetworkClient client)
{
client.RegisterHandler((short)MsgType.Connect, OnClientConnectInternal);
client.RegisterHandler((short)MsgType.Disconnect, OnClientDisconnectInternal);
client.RegisterHandler((short)MsgType.NotReady, OnClientNotReadyMessageInternal);
client.RegisterHandler((short)MsgType.Error, OnClientErrorInternal);
client.RegisterHandler((short)MsgType.Scene, OnClientSceneInternal);
client.RegisterHandler(MsgType.Connect, OnClientConnectInternal);
client.RegisterHandler(MsgType.Disconnect, OnClientDisconnectInternal);
client.RegisterHandler(MsgType.NotReady, OnClientNotReadyMessageInternal);
client.RegisterHandler(MsgType.Error, OnClientErrorInternal);
client.RegisterHandler(MsgType.Scene, OnClientSceneInternal);
if (m_PlayerPrefab != null)
{

View File

@ -88,14 +88,14 @@ public static void Initialize()
internal static void RegisterMessageHandlers()
{
RegisterHandler((short)MsgType.Ready, OnClientReadyMessage);
RegisterHandler((short)MsgType.Command, OnCommandMessage);
RegisterHandler((short)MsgType.LocalPlayerTransform, NetworkTransform.HandleTransform);
RegisterHandler((short)MsgType.LocalChildTransform, NetworkTransformChild.HandleChildTransform);
RegisterHandler((short)MsgType.RemovePlayer, OnRemovePlayerMessage);
RegisterHandler((short)MsgType.Animation, NetworkAnimator.OnAnimationServerMessage);
RegisterHandler((short)MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage);
RegisterHandler((short)MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage);
RegisterHandler(MsgType.Ready, OnClientReadyMessage);
RegisterHandler(MsgType.Command, OnCommandMessage);
RegisterHandler(MsgType.LocalPlayerTransform, NetworkTransform.HandleTransform);
RegisterHandler(MsgType.LocalChildTransform, NetworkTransformChild.HandleChildTransform);
RegisterHandler(MsgType.RemovePlayer, OnRemovePlayerMessage);
RegisterHandler(MsgType.Animation, NetworkAnimator.OnAnimationServerMessage);
RegisterHandler(MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage);
RegisterHandler(MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage);
}
public static bool Listen(int serverPort, int maxConnections)