mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
use type safe register handler instead of casting (#49)
This commit is contained in:
parent
3063273ad4
commit
0afd9f50ea
@ -198,31 +198,31 @@ internal static void RegisterSystemHandlers(NetworkClient client, bool localClie
|
|||||||
{
|
{
|
||||||
if (localClient)
|
if (localClient)
|
||||||
{
|
{
|
||||||
client.RegisterHandler((short)MsgType.ObjectDestroy, OnLocalClientObjectDestroy);
|
client.RegisterHandler(MsgType.ObjectDestroy, OnLocalClientObjectDestroy);
|
||||||
client.RegisterHandler((short)MsgType.ObjectHide, OnLocalClientObjectHide);
|
client.RegisterHandler(MsgType.ObjectHide, OnLocalClientObjectHide);
|
||||||
client.RegisterHandler((short)MsgType.SpawnPrefab, OnLocalClientSpawnPrefab);
|
client.RegisterHandler(MsgType.SpawnPrefab, OnLocalClientSpawnPrefab);
|
||||||
client.RegisterHandler((short)MsgType.SpawnSceneObject, OnLocalClientSpawnSceneObject);
|
client.RegisterHandler(MsgType.SpawnSceneObject, OnLocalClientSpawnSceneObject);
|
||||||
client.RegisterHandler((short)MsgType.LocalClientAuthority, OnClientAuthority);
|
client.RegisterHandler(MsgType.LocalClientAuthority, OnClientAuthority);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// LocalClient shares the sim/scene with the server, no need for these events
|
// LocalClient shares the sim/scene with the server, no need for these events
|
||||||
client.RegisterHandler((short)MsgType.SpawnPrefab, OnSpawnPrefab);
|
client.RegisterHandler(MsgType.SpawnPrefab, OnSpawnPrefab);
|
||||||
client.RegisterHandler((short)MsgType.SpawnSceneObject, OnSpawnSceneObject);
|
client.RegisterHandler(MsgType.SpawnSceneObject, OnSpawnSceneObject);
|
||||||
client.RegisterHandler((short)MsgType.SpawnFinished, OnObjectSpawnFinished);
|
client.RegisterHandler(MsgType.SpawnFinished, OnObjectSpawnFinished);
|
||||||
client.RegisterHandler((short)MsgType.ObjectDestroy, OnObjectDestroy);
|
client.RegisterHandler(MsgType.ObjectDestroy, OnObjectDestroy);
|
||||||
client.RegisterHandler((short)MsgType.ObjectHide, OnObjectDestroy);
|
client.RegisterHandler(MsgType.ObjectHide, OnObjectDestroy);
|
||||||
client.RegisterHandler((short)MsgType.UpdateVars, OnUpdateVarsMessage);
|
client.RegisterHandler(MsgType.UpdateVars, OnUpdateVarsMessage);
|
||||||
client.RegisterHandler((short)MsgType.Owner, OnOwnerMessage);
|
client.RegisterHandler(MsgType.Owner, OnOwnerMessage);
|
||||||
client.RegisterHandler((short)MsgType.SyncList, OnSyncListMessage);
|
client.RegisterHandler(MsgType.SyncList, OnSyncListMessage);
|
||||||
client.RegisterHandler((short)MsgType.Animation, NetworkAnimator.OnAnimationClientMessage);
|
client.RegisterHandler(MsgType.Animation, NetworkAnimator.OnAnimationClientMessage);
|
||||||
client.RegisterHandler((short)MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersClientMessage);
|
client.RegisterHandler(MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersClientMessage);
|
||||||
client.RegisterHandler((short)MsgType.LocalClientAuthority, OnClientAuthority);
|
client.RegisterHandler(MsgType.LocalClientAuthority, OnClientAuthority);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.RegisterHandler((short)MsgType.Rpc, OnRPCMessage);
|
client.RegisterHandler(MsgType.Rpc, OnRPCMessage);
|
||||||
client.RegisterHandler((short)MsgType.SyncEvent, OnSyncEventMessage);
|
client.RegisterHandler(MsgType.SyncEvent, OnSyncEventMessage);
|
||||||
client.RegisterHandler((short)MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerClientMessage);
|
client.RegisterHandler(MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerClientMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------ NetworkScene pass-throughs ---------------------
|
// ------------------------ NetworkScene pass-throughs ---------------------
|
||||||
|
@ -182,12 +182,12 @@ void OnValidate()
|
|||||||
|
|
||||||
internal void RegisterServerMessages()
|
internal void RegisterServerMessages()
|
||||||
{
|
{
|
||||||
NetworkServer.RegisterHandler((short)MsgType.Connect, OnServerConnectInternal);
|
NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnectInternal);
|
||||||
NetworkServer.RegisterHandler((short)MsgType.Disconnect, OnServerDisconnectInternal);
|
NetworkServer.RegisterHandler(MsgType.Disconnect, OnServerDisconnectInternal);
|
||||||
NetworkServer.RegisterHandler((short)MsgType.Ready, OnServerReadyMessageInternal);
|
NetworkServer.RegisterHandler(MsgType.Ready, OnServerReadyMessageInternal);
|
||||||
NetworkServer.RegisterHandler((short)MsgType.AddPlayer, OnServerAddPlayerMessageInternal);
|
NetworkServer.RegisterHandler(MsgType.AddPlayer, OnServerAddPlayerMessageInternal);
|
||||||
NetworkServer.RegisterHandler((short)MsgType.RemovePlayer, OnServerRemovePlayerMessageInternal);
|
NetworkServer.RegisterHandler(MsgType.RemovePlayer, OnServerRemovePlayerMessageInternal);
|
||||||
NetworkServer.RegisterHandler((short)MsgType.Error, OnServerErrorInternal);
|
NetworkServer.RegisterHandler(MsgType.Error, OnServerErrorInternal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool StartServer()
|
public bool StartServer()
|
||||||
@ -247,11 +247,11 @@ public bool StartServer()
|
|||||||
|
|
||||||
internal void RegisterClientMessages(NetworkClient client)
|
internal void RegisterClientMessages(NetworkClient client)
|
||||||
{
|
{
|
||||||
client.RegisterHandler((short)MsgType.Connect, OnClientConnectInternal);
|
client.RegisterHandler(MsgType.Connect, OnClientConnectInternal);
|
||||||
client.RegisterHandler((short)MsgType.Disconnect, OnClientDisconnectInternal);
|
client.RegisterHandler(MsgType.Disconnect, OnClientDisconnectInternal);
|
||||||
client.RegisterHandler((short)MsgType.NotReady, OnClientNotReadyMessageInternal);
|
client.RegisterHandler(MsgType.NotReady, OnClientNotReadyMessageInternal);
|
||||||
client.RegisterHandler((short)MsgType.Error, OnClientErrorInternal);
|
client.RegisterHandler(MsgType.Error, OnClientErrorInternal);
|
||||||
client.RegisterHandler((short)MsgType.Scene, OnClientSceneInternal);
|
client.RegisterHandler(MsgType.Scene, OnClientSceneInternal);
|
||||||
|
|
||||||
if (m_PlayerPrefab != null)
|
if (m_PlayerPrefab != null)
|
||||||
{
|
{
|
||||||
|
@ -88,14 +88,14 @@ public static void Initialize()
|
|||||||
|
|
||||||
internal static void RegisterMessageHandlers()
|
internal static void RegisterMessageHandlers()
|
||||||
{
|
{
|
||||||
RegisterHandler((short)MsgType.Ready, OnClientReadyMessage);
|
RegisterHandler(MsgType.Ready, OnClientReadyMessage);
|
||||||
RegisterHandler((short)MsgType.Command, OnCommandMessage);
|
RegisterHandler(MsgType.Command, OnCommandMessage);
|
||||||
RegisterHandler((short)MsgType.LocalPlayerTransform, NetworkTransform.HandleTransform);
|
RegisterHandler(MsgType.LocalPlayerTransform, NetworkTransform.HandleTransform);
|
||||||
RegisterHandler((short)MsgType.LocalChildTransform, NetworkTransformChild.HandleChildTransform);
|
RegisterHandler(MsgType.LocalChildTransform, NetworkTransformChild.HandleChildTransform);
|
||||||
RegisterHandler((short)MsgType.RemovePlayer, OnRemovePlayerMessage);
|
RegisterHandler(MsgType.RemovePlayer, OnRemovePlayerMessage);
|
||||||
RegisterHandler((short)MsgType.Animation, NetworkAnimator.OnAnimationServerMessage);
|
RegisterHandler(MsgType.Animation, NetworkAnimator.OnAnimationServerMessage);
|
||||||
RegisterHandler((short)MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage);
|
RegisterHandler(MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage);
|
||||||
RegisterHandler((short)MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage);
|
RegisterHandler(MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Listen(int serverPort, int maxConnections)
|
public static bool Listen(int serverPort, int maxConnections)
|
||||||
|
Loading…
Reference in New Issue
Block a user