UNetwork.MsgType converted to Enum. Easier + faster string conversion and more flexible code.

This commit is contained in:
vis2k 2018-07-19 21:03:00 +02:00
parent 7cea90460f
commit ee2d0373eb
14 changed files with 155 additions and 218 deletions

View File

@ -74,7 +74,7 @@ int ShowServerMessageHandlers(Rect r, int posY)
foreach (var handler in NetworkServer.handlers) foreach (var handler in NetworkServer.handlers)
{ {
GUI.Label(new Rect(r.xMin + k_Padding * 4, posY, 400, k_RowHeight), MsgType.MsgTypeToString(handler.Key)); GUI.Label(new Rect(r.xMin + k_Padding * 4, posY, 400, k_RowHeight), ((MsgType)handler.Key).ToString());
GUI.Label(new Rect(r.xMin + k_Padding * 4 + k_ColumnWidth, posY, 400, k_RowHeight), FormatHandler(handler)); GUI.Label(new Rect(r.xMin + k_Padding * 4 + k_ColumnWidth, posY, 400, k_RowHeight), FormatHandler(handler));
posY += k_RowHeight; posY += k_RowHeight;
} }
@ -95,7 +95,7 @@ int ShowClientMessageHandlers(Rect r, int posY)
foreach (var handler in client.handlers) foreach (var handler in client.handlers)
{ {
GUI.Label(new Rect(r.xMin + k_Padding * 4, posY, 400, k_RowHeight), MsgType.MsgTypeToString(handler.Key)); GUI.Label(new Rect(r.xMin + k_Padding * 4, posY, 400, k_RowHeight), ((MsgType)handler.Key).ToString());
GUI.Label(new Rect(r.xMin + k_Padding * 4 + k_ColumnWidth, posY, 400, k_RowHeight), FormatHandler(handler)); GUI.Label(new Rect(r.xMin + k_Padding * 4 + k_ColumnWidth, posY, 400, k_RowHeight), FormatHandler(handler));
posY += k_RowHeight; posY += k_RowHeight;
} }

View File

@ -147,7 +147,7 @@ public static bool AddPlayer(NetworkConnection readyConn, short playerController
extraMessage.Serialize(writer); extraMessage.Serialize(writer);
msg.msgData = writer.ToArray(); msg.msgData = writer.ToArray();
} }
s_ReadyConnection.Send(MsgType.AddPlayer, msg); s_ReadyConnection.Send((short)MsgType.AddPlayer, msg);
return true; return true;
} }
@ -160,7 +160,7 @@ public static bool RemovePlayer(short playerControllerId)
{ {
var msg = new RemovePlayerMessage(); var msg = new RemovePlayerMessage();
msg.playerControllerId = playerControllerId; msg.playerControllerId = playerControllerId;
s_ReadyConnection.Send(MsgType.RemovePlayer, msg); s_ReadyConnection.Send((short)MsgType.RemovePlayer, msg);
s_ReadyConnection.RemovePlayerController(playerControllerId); s_ReadyConnection.RemovePlayerController(playerControllerId);
s_LocalPlayers[playerControllerId] = new PlayerController(); s_LocalPlayers[playerControllerId] = new PlayerController();
@ -185,7 +185,7 @@ public static bool Ready(NetworkConnection conn)
if (conn != null) if (conn != null)
{ {
var msg = new ReadyMessage(); var msg = new ReadyMessage();
conn.Send(MsgType.Ready, msg); conn.Send((short)MsgType.Ready, msg);
s_IsReady = true; s_IsReady = true;
s_ReadyConnection = conn; s_ReadyConnection = conn;
s_ReadyConnection.isReady = true; s_ReadyConnection.isReady = true;
@ -246,31 +246,31 @@ static internal void RegisterSystemHandlers(NetworkClient client, bool localClie
{ {
if (localClient) if (localClient)
{ {
client.RegisterHandler(MsgType.ObjectDestroy, OnLocalClientObjectDestroy); client.RegisterHandler((short)MsgType.ObjectDestroy, OnLocalClientObjectDestroy);
client.RegisterHandler(MsgType.ObjectHide, OnLocalClientObjectHide); client.RegisterHandler((short)MsgType.ObjectHide, OnLocalClientObjectHide);
client.RegisterHandler(MsgType.ObjectSpawn, OnLocalClientObjectSpawn); client.RegisterHandler((short)MsgType.ObjectSpawn, OnLocalClientObjectSpawn);
client.RegisterHandler(MsgType.ObjectSpawnScene, OnLocalClientObjectSpawnScene); client.RegisterHandler((short)MsgType.ObjectSpawnScene, OnLocalClientObjectSpawnScene);
client.RegisterHandler(MsgType.LocalClientAuthority, OnClientAuthority); client.RegisterHandler((short)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(MsgType.ObjectSpawn, OnObjectSpawn); client.RegisterHandler((short)MsgType.ObjectSpawn, OnObjectSpawn);
client.RegisterHandler(MsgType.ObjectSpawnScene, OnObjectSpawnScene); client.RegisterHandler((short)MsgType.ObjectSpawnScene, OnObjectSpawnScene);
client.RegisterHandler(MsgType.SpawnFinished, OnObjectSpawnFinished); client.RegisterHandler((short)MsgType.SpawnFinished, OnObjectSpawnFinished);
client.RegisterHandler(MsgType.ObjectDestroy, OnObjectDestroy); client.RegisterHandler((short)MsgType.ObjectDestroy, OnObjectDestroy);
client.RegisterHandler(MsgType.ObjectHide, OnObjectDestroy); client.RegisterHandler((short)MsgType.ObjectHide, OnObjectDestroy);
client.RegisterHandler(MsgType.UpdateVars, OnUpdateVarsMessage); client.RegisterHandler((short)MsgType.UpdateVars, OnUpdateVarsMessage);
client.RegisterHandler(MsgType.Owner, OnOwnerMessage); client.RegisterHandler((short)MsgType.Owner, OnOwnerMessage);
client.RegisterHandler(MsgType.SyncList, OnSyncListMessage); client.RegisterHandler((short)MsgType.SyncList, OnSyncListMessage);
client.RegisterHandler(MsgType.Animation, NetworkAnimator.OnAnimationClientMessage); client.RegisterHandler((short)MsgType.Animation, NetworkAnimator.OnAnimationClientMessage);
client.RegisterHandler(MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersClientMessage); client.RegisterHandler((short)MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersClientMessage);
client.RegisterHandler(MsgType.LocalClientAuthority, OnClientAuthority); client.RegisterHandler((short)MsgType.LocalClientAuthority, OnClientAuthority);
} }
client.RegisterHandler(MsgType.Rpc, OnRPCMessage); client.RegisterHandler((short)MsgType.Rpc, OnRPCMessage);
client.RegisterHandler(MsgType.SyncEvent, OnSyncEventMessage); client.RegisterHandler((short)MsgType.SyncEvent, OnSyncEventMessage);
client.RegisterHandler(MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerClientMessage); client.RegisterHandler((short)MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerClientMessage);
} }
// ------------------------ NetworkScene pass-throughs --------------------- // ------------------------ NetworkScene pass-throughs ---------------------
@ -388,7 +388,7 @@ static void OnObjectSpawn(NetworkMessage netMsg)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.ObjectSpawn, GetStringForAssetId(msg.assetId), 1); (short)MsgType.ObjectSpawn, GetStringForAssetId(msg.assetId), 1);
#endif #endif
NetworkIdentity localNetworkIdentity; NetworkIdentity localNetworkIdentity;
@ -455,7 +455,7 @@ static void OnObjectSpawnScene(NetworkMessage netMsg)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.ObjectSpawnScene, "sceneId", 1); (short)MsgType.ObjectSpawnScene, "sceneId", 1);
#endif #endif
NetworkIdentity localNetworkIdentity; NetworkIdentity localNetworkIdentity;
@ -521,7 +521,7 @@ static void OnObjectDestroy(NetworkMessage netMsg)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.ObjectDestroy, GetStringForAssetId(localObject.assetId), 1); (short)MsgType.ObjectDestroy, GetStringForAssetId(localObject.assetId), 1);
#endif #endif
localObject.OnNetworkDestroy(); localObject.OnNetworkDestroy();
@ -652,7 +652,7 @@ static void OnSyncEventMessage(NetworkMessage netMsg)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.SyncEvent, NetworkBehaviour.GetCmdHashHandlerName(cmdHash), 1); (short)MsgType.SyncEvent, NetworkBehaviour.GetCmdHashHandlerName(cmdHash), 1);
#endif #endif
} }
@ -676,7 +676,7 @@ static void OnSyncListMessage(NetworkMessage netMsg)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.SyncList, NetworkBehaviour.GetCmdHashHandlerName(cmdHash), 1); (short)MsgType.SyncList, NetworkBehaviour.GetCmdHashHandlerName(cmdHash), 1);
#endif #endif
} }

View File

@ -21,7 +21,7 @@ public override void Disconnect()
ClientScene.HandleClientDisconnect(m_Connection); ClientScene.HandleClientDisconnect(m_Connection);
if (m_Connected) if (m_Connected)
{ {
PostInternalMessage(MsgType.Disconnect); PostInternalMessage((short)MsgType.Disconnect);
m_Connected = false; m_Connected = false;
} }
m_AsyncConnect = ConnectState.Disconnected; m_AsyncConnect = ConnectState.Disconnected;
@ -40,7 +40,7 @@ internal void InternalConnectLocalServer(bool generateConnectMsg)
if (generateConnectMsg) if (generateConnectMsg)
{ {
PostInternalMessage(MsgType.Connect); PostInternalMessage((short)MsgType.Connect);
} }
m_Connected = true; m_Connected = true;
} }

View File

@ -114,7 +114,7 @@ void FixedUpdate()
WriteParameters(m_ParameterWriter, false); WriteParameters(m_ParameterWriter, false);
animMsg.parameters = m_ParameterWriter.ToArray(); animMsg.parameters = m_ParameterWriter.ToArray();
SendMessage(MsgType.Animation, animMsg); SendMessage((short)MsgType.Animation, animMsg);
} }
bool CheckAnimStateChanged(out int stateHash, out float normalizedTime) bool CheckAnimStateChanged(out int stateHash, out float normalizedTime)
@ -165,7 +165,7 @@ void CheckSendRate()
WriteParameters(m_ParameterWriter, true); WriteParameters(m_ParameterWriter, true);
animMsg.parameters = m_ParameterWriter.ToArray(); animMsg.parameters = m_ParameterWriter.ToArray();
SendMessage(MsgType.AnimationParameters, animMsg); SendMessage((short)MsgType.AnimationParameters, animMsg);
} }
} }
@ -351,7 +351,7 @@ public void SetTrigger(int hash)
var client = ClientScene.readyConnection; var client = ClientScene.readyConnection;
if (client != null) if (client != null)
{ {
client.Send(MsgType.AnimationTrigger, animMsg); client.Send((short)MsgType.AnimationTrigger, animMsg);
} }
} }
return; return;
@ -359,7 +359,7 @@ public void SetTrigger(int hash)
if (isServer && !localPlayerAuthority) if (isServer && !localPlayerAuthority)
{ {
NetworkServer.SendToReady(gameObject, MsgType.AnimationTrigger, animMsg); NetworkServer.SendToReady(gameObject, (short)MsgType.AnimationTrigger, animMsg);
} }
} }
@ -382,7 +382,7 @@ static internal void OnAnimationServerMessage(NetworkMessage netMsg)
NetworkReader reader = new NetworkReader(msg.parameters); NetworkReader reader = new NetworkReader(msg.parameters);
animSync.HandleAnimMsg(msg, reader); animSync.HandleAnimMsg(msg, reader);
NetworkServer.SendToReady(go, MsgType.Animation, msg); NetworkServer.SendToReady(go, (short)MsgType.Animation, msg);
} }
} }
@ -403,7 +403,7 @@ static internal void OnAnimationParametersServerMessage(NetworkMessage netMsg)
{ {
NetworkReader reader = new NetworkReader(msg.parameters); NetworkReader reader = new NetworkReader(msg.parameters);
animSync.HandleAnimParamsMsg(msg, reader); animSync.HandleAnimParamsMsg(msg, reader);
NetworkServer.SendToReady(go, MsgType.AnimationParameters, msg); NetworkServer.SendToReady(go, (short)MsgType.AnimationParameters, msg);
} }
} }
@ -423,7 +423,7 @@ static internal void OnAnimationTriggerServerMessage(NetworkMessage netMsg)
{ {
animSync.HandleAnimTriggerMsg(msg.hash); animSync.HandleAnimTriggerMsg(msg.hash);
NetworkServer.SendToReady(go, MsgType.AnimationTrigger, msg); NetworkServer.SendToReady(go, (short)MsgType.AnimationTrigger, msg);
} }
} }

View File

@ -73,7 +73,7 @@ protected void SendCommandInternal(NetworkWriter writer, int channelId, string c
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.Command, cmdName, 1); (short)MsgType.Command, cmdName, 1);
#endif #endif
} }
@ -101,7 +101,7 @@ protected void SendRPCInternal(NetworkWriter writer, int channelId, string rpcNa
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.Rpc, rpcName, 1); (short)MsgType.Rpc, rpcName, 1);
#endif #endif
} }
@ -122,7 +122,7 @@ protected void SendTargetRPCInternal(NetworkConnection conn, NetworkWriter write
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.Rpc, rpcName, 1); (short)MsgType.Rpc, rpcName, 1);
#endif #endif
} }
@ -149,7 +149,7 @@ protected void SendEventInternal(NetworkWriter writer, int channelId, string eve
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.SyncEvent, eventName, 1); (short)MsgType.SyncEvent, eventName, 1);
#endif #endif
} }

View File

@ -337,7 +337,7 @@ public bool SendByChannel(short msgType, MessageBase msg, int channelId)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.UserMessage, msgType.ToString() + ":" + msg.GetType().Name, 1); (short)MsgType.UserMessage, msgType.ToString() + ":" + msg.GetType().Name, 1);
#endif #endif
if (m_Connection != null) if (m_Connection != null)
{ {
@ -430,7 +430,7 @@ internal virtual void Update()
} }
m_AsyncConnect = ConnectState.Connected; m_AsyncConnect = ConnectState.Connected;
m_Connection.InvokeHandlerNoData(MsgType.Connect); m_Connection.InvokeHandlerNoData((short)MsgType.Connect);
break; break;
case NetworkEventType.DataEvent: case NetworkEventType.DataEvent:
@ -443,7 +443,7 @@ internal virtual void Update()
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.LLAPIMsg, "msg", 1); (short)MsgType.LLAPIMsg, "msg", 1);
#endif #endif
m_MsgReader.SeekZero(); m_MsgReader.SeekZero();
@ -465,7 +465,7 @@ internal virtual void Update()
ClientScene.HandleClientDisconnect(m_Connection); ClientScene.HandleClientDisconnect(m_Connection);
if (m_Connection != null) if (m_Connection != null)
{ {
m_Connection.InvokeHandlerNoData(MsgType.Disconnect); m_Connection.InvokeHandlerNoData((short)MsgType.Disconnect);
} }
break; break;
@ -513,7 +513,7 @@ void GenerateDisconnectError(byte error)
void GenerateError(byte error) void GenerateError(byte error)
{ {
NetworkMessageDelegate msgDelegate; NetworkMessageDelegate msgDelegate;
if (m_MessageHandlers.TryGetValue(MsgType.Error, out msgDelegate)) if (m_MessageHandlers.TryGetValue((short)MsgType.Error, out msgDelegate))
{ {
ErrorMessage msg = new ErrorMessage(); ErrorMessage msg = new ErrorMessage();
msg.errorCode = error; msg.errorCode = error;
@ -523,7 +523,7 @@ void GenerateError(byte error)
msg.Serialize(writer); msg.Serialize(writer);
NetworkMessage netMsg = new NetworkMessage(); NetworkMessage netMsg = new NetworkMessage();
netMsg.msgType = MsgType.Error; netMsg.msgType = (short)MsgType.Error;
netMsg.reader = new NetworkReader(writer.ToArray()); netMsg.reader = new NetworkReader(writer.ToArray());
netMsg.conn = m_Connection; netMsg.conn = m_Connection;
netMsg.channelId = 0; netMsg.channelId = 0;

View File

@ -198,7 +198,7 @@ public virtual bool SendBytes(byte[] bytes, int bytesToSend, int channelId)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.HLAPIMsg, "msg", 1); (short)MsgType.HLAPIMsg, "msg", 1);
#endif #endif
if (bytesToSend > UInt16.MaxValue) if (bytesToSend > UInt16.MaxValue)
{ {
@ -287,7 +287,7 @@ protected void HandleReader(NetworkReader reader, int receivedSize, int channelI
if (pauseQueue != null) if (pauseQueue != null)
{ {
pauseQueue.Enqueue(msg); pauseQueue.Enqueue(msg);
if (LogFilter.logWarn) { Debug.LogWarning("HandleReader: added message to pause queue: " + msgType + " str=" + MsgType.MsgTypeToString(msgType) + " queue size=" + pauseQueue.Count); } if (LogFilter.logWarn) { Debug.LogWarning("HandleReader: added message to pause queue: " + msgType + " str=" + ((MsgType)msgType) + " queue size=" + pauseQueue.Count); }
} }
else else
{ {
@ -298,13 +298,13 @@ protected void HandleReader(NetworkReader reader, int receivedSize, int channelI
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.HLAPIMsg, "msg", 1); (short)MsgType.HLAPIMsg, "msg", 1);
if (msgType > MsgType.Highest) if (msgType > (short)MsgType.Highest)
{ {
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.UserMessage, msgType.ToString() + ":" + msgType.GetType().Name, 1); (short)MsgType.UserMessage, msgType.ToString() + ":" + msgType.GetType().Name, 1);
} }
#endif #endif
} }
@ -408,7 +408,7 @@ internal void ResumeHandling()
{ {
foreach (NetworkMessage msg in pauseQueue) foreach (NetworkMessage msg in pauseQueue)
{ {
if (LogFilter.logWarn) { Debug.LogWarning("processing queued message: " + msg.msgType + " str=" + MsgType.MsgTypeToString(msg.msgType)); } if (LogFilter.logWarn) { Debug.LogWarning("processing queued message: " + msg.msgType + " str=" + msg.msgType); }
var msgDelegate = m_MessageHandlers[msg.msgType]; var msgDelegate = m_MessageHandlers[msg.msgType];
msgDelegate(msg); msgDelegate(msg);
} }

View File

@ -536,7 +536,7 @@ internal void HandleSyncEvent(int cmdHash, NetworkReader reader)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.SyncEvent, NetworkBehaviour.GetCmdHashEventName(cmdHash), 1); (short)MsgType.SyncEvent, NetworkBehaviour.GetCmdHashEventName(cmdHash), 1);
#endif #endif
} }
@ -579,7 +579,7 @@ internal void HandleSyncList(int cmdHash, NetworkReader reader)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.SyncList, NetworkBehaviour.GetCmdHashListName(cmdHash), 1); (short)MsgType.SyncList, NetworkBehaviour.GetCmdHashListName(cmdHash), 1);
#endif #endif
} }
@ -622,7 +622,7 @@ internal void HandleCommand(int cmdHash, NetworkReader reader)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.Command, NetworkBehaviour.GetCmdHashCmdName(cmdHash), 1); (short)MsgType.Command, NetworkBehaviour.GetCmdHashCmdName(cmdHash), 1);
#endif #endif
} }
@ -665,7 +665,7 @@ internal void HandleRPC(int cmdHash, NetworkReader reader)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.Rpc, NetworkBehaviour.GetCmdHashRpcName(cmdHash), 1); (short)MsgType.Rpc, NetworkBehaviour.GetCmdHashRpcName(cmdHash), 1);
#endif #endif
} }
@ -691,7 +691,7 @@ internal void UNetUpdate()
if ((dirtyChannelBits & (uint)(1 << channelId)) != 0) if ((dirtyChannelBits & (uint)(1 << channelId)) != 0)
{ {
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
writer.StartMessage(MsgType.UpdateVars); writer.StartMessage((short)MsgType.UpdateVars);
writer.Write(netId); writer.Write(netId);
bool wroteData = false; bool wroteData = false;
@ -714,7 +714,7 @@ internal void UNetUpdate()
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.UpdateVars, comp.GetType().Name, 1); (short)MsgType.UpdateVars, comp.GetType().Name, 1);
#endif #endif
wroteData = true; wroteData = true;
@ -968,7 +968,7 @@ public bool RemoveClientAuthority(NetworkConnection conn)
var msg = new ClientAuthorityMessage(); var msg = new ClientAuthorityMessage();
msg.netId = netId; msg.netId = netId;
msg.authority = false; msg.authority = false;
conn.Send(MsgType.LocalClientAuthority, msg); conn.Send((short)MsgType.LocalClientAuthority, msg);
if (clientAuthorityCallback != null) if (clientAuthorityCallback != null)
{ {
@ -1012,7 +1012,7 @@ public bool AssignClientAuthority(NetworkConnection conn)
var msg = new ClientAuthorityMessage(); var msg = new ClientAuthorityMessage();
msg.netId = netId; msg.netId = netId;
msg.authority = true; msg.authority = true;
conn.Send(MsgType.LocalClientAuthority, msg); conn.Send((short)MsgType.LocalClientAuthority, msg);
if (clientAuthorityCallback != null) if (clientAuthorityCallback != null)
{ {

View File

@ -226,12 +226,12 @@ void OnValidate()
internal void RegisterServerMessages() internal void RegisterServerMessages()
{ {
NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnectInternal); NetworkServer.RegisterHandler((short)MsgType.Connect, OnServerConnectInternal);
NetworkServer.RegisterHandler(MsgType.Disconnect, OnServerDisconnectInternal); NetworkServer.RegisterHandler((short)MsgType.Disconnect, OnServerDisconnectInternal);
NetworkServer.RegisterHandler(MsgType.Ready, OnServerReadyMessageInternal); NetworkServer.RegisterHandler((short)MsgType.Ready, OnServerReadyMessageInternal);
NetworkServer.RegisterHandler(MsgType.AddPlayer, OnServerAddPlayerMessageInternal); NetworkServer.RegisterHandler((short)MsgType.AddPlayer, OnServerAddPlayerMessageInternal);
NetworkServer.RegisterHandler(MsgType.RemovePlayer, OnServerRemovePlayerMessageInternal); NetworkServer.RegisterHandler((short)MsgType.RemovePlayer, OnServerRemovePlayerMessageInternal);
NetworkServer.RegisterHandler(MsgType.Error, OnServerErrorInternal); NetworkServer.RegisterHandler((short)MsgType.Error, OnServerErrorInternal);
} }
public bool StartServer() public bool StartServer()
@ -309,11 +309,11 @@ bool StartServer(ConnectionConfig config, int maxConnections)
internal void RegisterClientMessages(NetworkClient client) internal void RegisterClientMessages(NetworkClient client)
{ {
client.RegisterHandler(MsgType.Connect, OnClientConnectInternal); client.RegisterHandler((short)MsgType.Connect, OnClientConnectInternal);
client.RegisterHandler(MsgType.Disconnect, OnClientDisconnectInternal); client.RegisterHandler((short)MsgType.Disconnect, OnClientDisconnectInternal);
client.RegisterHandler(MsgType.NotReady, OnClientNotReadyMessageInternal); client.RegisterHandler((short)MsgType.NotReady, OnClientNotReadyMessageInternal);
client.RegisterHandler(MsgType.Error, OnClientErrorInternal); client.RegisterHandler((short)MsgType.Error, OnClientErrorInternal);
client.RegisterHandler(MsgType.Scene, OnClientSceneInternal); client.RegisterHandler((short)MsgType.Scene, OnClientSceneInternal);
if (m_PlayerPrefab != null) if (m_PlayerPrefab != null)
{ {
@ -525,7 +525,7 @@ public virtual void ServerChangeScene(string newSceneName)
s_LoadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName); s_LoadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName);
StringMessage msg = new StringMessage(networkSceneName); StringMessage msg = new StringMessage(networkSceneName);
NetworkServer.SendToAll(MsgType.Scene, msg); NetworkServer.SendToAll((short)MsgType.Scene, msg);
s_StartPositionIndex = 0; s_StartPositionIndex = 0;
s_StartPositions.Clear(); s_StartPositions.Clear();
@ -693,7 +693,7 @@ internal void OnServerConnectInternal(NetworkMessage netMsg)
if (networkSceneName != "" && networkSceneName != m_OfflineScene) if (networkSceneName != "" && networkSceneName != m_OfflineScene)
{ {
StringMessage msg = new StringMessage(networkSceneName); StringMessage msg = new StringMessage(networkSceneName);
netMsg.conn.Send(MsgType.Scene, msg); netMsg.conn.Send((short)MsgType.Scene, msg);
} }
OnServerConnect(netMsg.conn); OnServerConnect(netMsg.conn);

View File

@ -125,14 +125,14 @@ public static void Initialize()
static internal void RegisterMessageHandlers() static internal void RegisterMessageHandlers()
{ {
RegisterHandler(MsgType.Ready, OnClientReadyMessage); RegisterHandler((short)MsgType.Ready, OnClientReadyMessage);
RegisterHandler(MsgType.Command, OnCommandMessage); RegisterHandler((short)MsgType.Command, OnCommandMessage);
RegisterHandler(MsgType.LocalPlayerTransform, NetworkTransform.HandleTransform); RegisterHandler((short)MsgType.LocalPlayerTransform, NetworkTransform.HandleTransform);
RegisterHandler(MsgType.LocalChildTransform, NetworkTransformChild.HandleChildTransform); RegisterHandler((short)MsgType.LocalChildTransform, NetworkTransformChild.HandleChildTransform);
RegisterHandler(MsgType.RemovePlayer, OnRemovePlayerMessage); RegisterHandler((short)MsgType.RemovePlayer, OnRemovePlayerMessage);
RegisterHandler(MsgType.Animation, NetworkAnimator.OnAnimationServerMessage); RegisterHandler((short)MsgType.Animation, NetworkAnimator.OnAnimationServerMessage);
RegisterHandler(MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage); RegisterHandler((short)MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage);
RegisterHandler(MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage); RegisterHandler((short)MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage);
// also setup max packet size. // also setup max packet size.
maxPacketSize = hostTopology.DefaultConfig.PacketSize; maxPacketSize = hostTopology.DefaultConfig.PacketSize;
@ -220,7 +220,7 @@ static internal int AddLocalClient(LocalClient localClient)
s_LocalConnection.connectionId = 0; s_LocalConnection.connectionId = 0;
SetConnectionAtIndex(s_LocalConnection); SetConnectionAtIndex(s_LocalConnection);
s_LocalConnection.InvokeHandlerNoData(MsgType.Connect); s_LocalConnection.InvokeHandlerNoData((short)MsgType.Connect);
return 0; return 0;
} }
@ -553,7 +553,7 @@ static void HandleConnect(int connectionId, byte error)
static void OnConnected(NetworkConnection conn) static void OnConnected(NetworkConnection conn)
{ {
if (LogFilter.logDebug) { Debug.Log("Server accepted client:" + conn.connectionId); } if (LogFilter.logDebug) { Debug.Log("Server accepted client:" + conn.connectionId); }
conn.InvokeHandlerNoData(MsgType.Connect); conn.InvokeHandlerNoData((short)MsgType.Connect);
} }
static void HandleDisconnect(int connectionId, byte error) static void HandleDisconnect(int connectionId, byte error)
@ -586,7 +586,7 @@ static void HandleDisconnect(int connectionId, byte error)
static void OnDisconnected(NetworkConnection conn) static void OnDisconnected(NetworkConnection conn)
{ {
conn.InvokeHandlerNoData(MsgType.Disconnect); conn.InvokeHandlerNoData((short)MsgType.Disconnect);
if (conn.playerControllers.Any(pc => pc.gameObject != null)) if (conn.playerControllers.Any(pc => pc.gameObject != null))
{ {
@ -631,7 +631,7 @@ static void OnData(NetworkConnection conn, int receivedSize, int channelId)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.LLAPIMsg, "msg", 1); (short)MsgType.LLAPIMsg, "msg", 1);
#endif #endif
conn.TransportReceive(s_MsgBuffer, receivedSize, channelId); conn.TransportReceive(s_MsgBuffer, receivedSize, channelId);
} }
@ -658,7 +658,7 @@ static void GenerateDisconnectError(NetworkConnection conn, byte error)
static void GenerateError(NetworkConnection conn, byte error) static void GenerateError(NetworkConnection conn, byte error)
{ {
if (handlers.ContainsKey(MsgType.Error)) if (handlers.ContainsKey((short)MsgType.Error))
{ {
ErrorMessage msg = new ErrorMessage(); ErrorMessage msg = new ErrorMessage();
msg.errorCode = error; msg.errorCode = error;
@ -669,7 +669,7 @@ static void GenerateError(NetworkConnection conn, byte error)
// pass a reader (attached to local buffer) to handler // pass a reader (attached to local buffer) to handler
NetworkReader reader = new NetworkReader(writer.ToArray()); NetworkReader reader = new NetworkReader(writer.ToArray());
conn.InvokeHandler(MsgType.Error, reader, 0); conn.InvokeHandler((short)MsgType.Error, reader, 0);
} }
} }
@ -876,7 +876,7 @@ static void FinishPlayerForConnection(NetworkConnection conn, NetworkIdentity uv
OwnerMessage owner = new OwnerMessage(); OwnerMessage owner = new OwnerMessage();
owner.netId = uv.netId; owner.netId = uv.netId;
owner.playerControllerId = uv.playerControllerId; owner.playerControllerId = uv.playerControllerId;
conn.Send(MsgType.Owner, owner); conn.Send((short)MsgType.Owner, owner);
} }
static internal bool InternalReplacePlayerForConnection(NetworkConnection conn, GameObject playerGameObject, short playerControllerId) static internal bool InternalReplacePlayerForConnection(NetworkConnection conn, GameObject playerGameObject, short playerControllerId)
@ -995,7 +995,7 @@ static internal void SetClientReadyInternal(NetworkConnection conn)
ObjectSpawnFinishedMessage msg = new ObjectSpawnFinishedMessage(); ObjectSpawnFinishedMessage msg = new ObjectSpawnFinishedMessage();
msg.state = 0; msg.state = 0;
conn.Send(MsgType.SpawnFinished, msg); conn.Send((short)MsgType.SpawnFinished, msg);
foreach (NetworkIdentity uv in objects.Values) foreach (NetworkIdentity uv in objects.Values)
{ {
@ -1019,7 +1019,7 @@ static internal void SetClientReadyInternal(NetworkConnection conn)
} }
msg.state = 1; msg.state = 1;
conn.Send(MsgType.SpawnFinished, msg); conn.Send((short)MsgType.SpawnFinished, msg);
} }
static internal void ShowForConnection(NetworkIdentity uv, NetworkConnection conn) static internal void ShowForConnection(NetworkIdentity uv, NetworkConnection conn)
@ -1032,7 +1032,7 @@ static internal void HideForConnection(NetworkIdentity uv, NetworkConnection con
{ {
ObjectDestroyMessage msg = new ObjectDestroyMessage(); ObjectDestroyMessage msg = new ObjectDestroyMessage();
msg.netId = uv.netId; msg.netId = uv.netId;
conn.Send(MsgType.ObjectHide, msg); conn.Send((short)MsgType.ObjectHide, msg);
} }
// call this to make all the clients not ready, such as when changing levels. // call this to make all the clients not ready, such as when changing levels.
@ -1062,7 +1062,7 @@ static internal void InternalSetClientNotReady(NetworkConnection conn)
conn.RemoveObservers(); conn.RemoveObservers();
NotReadyMessage msg = new NotReadyMessage(); NotReadyMessage msg = new NotReadyMessage();
conn.Send(MsgType.NotReady, msg); conn.Send((short)MsgType.NotReady, msg);
} }
} }
@ -1177,17 +1177,17 @@ static internal void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn
if (conn != null) if (conn != null)
{ {
conn.Send(MsgType.ObjectSpawn, msg); conn.Send((short)MsgType.ObjectSpawn, msg);
} }
else else
{ {
SendToReady(uv.gameObject, MsgType.ObjectSpawn, msg); SendToReady(uv.gameObject, (short)MsgType.ObjectSpawn, msg);
} }
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.ObjectSpawn, uv.assetId.ToString(), 1); (short)MsgType.ObjectSpawn, uv.assetId.ToString(), 1);
#endif #endif
} }
else else
@ -1207,17 +1207,17 @@ static internal void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn
if (conn != null) if (conn != null)
{ {
conn.Send(MsgType.ObjectSpawnScene, msg); conn.Send((short)MsgType.ObjectSpawnScene, msg);
} }
else else
{ {
SendToReady(uv.gameObject, MsgType.ObjectSpawn, msg); SendToReady(uv.gameObject, (short)MsgType.ObjectSpawn, msg);
} }
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.ObjectSpawnScene, "sceneId", 1); (short)MsgType.ObjectSpawnScene, "sceneId", 1);
#endif #endif
} }
} }
@ -1312,12 +1312,12 @@ static void DestroyObject(NetworkIdentity uv, bool destroyServerObject)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.ObjectDestroy, uv.assetId.ToString(), 1); (short)MsgType.ObjectDestroy, uv.assetId.ToString(), 1);
#endif #endif
ObjectDestroyMessage msg = new ObjectDestroyMessage(); ObjectDestroyMessage msg = new ObjectDestroyMessage();
msg.netId = uv.netId; msg.netId = uv.netId;
SendToObservers(uv.gameObject, MsgType.ObjectDestroy, msg); SendToObservers(uv.gameObject, (short)MsgType.ObjectDestroy, msg);
uv.ClearObservers(); uv.ClearObservers();
if (NetworkClient.active && s_LocalClientActive) if (NetworkClient.active && s_LocalClientActive)
@ -1502,7 +1502,7 @@ static bool AddExternalConnectionInternal(NetworkConnection conn)
if (LogFilter.logDebug) { Debug.Log("AddExternalConnection external connection " + conn.connectionId); } if (LogFilter.logDebug) { Debug.Log("AddExternalConnection external connection " + conn.connectionId); }
SetConnectionAtIndex(conn); SetConnectionAtIndex(conn);
s_ExternalConnections.Add(conn.connectionId); s_ExternalConnections.Add(conn.connectionId);
conn.InvokeHandlerNoData(MsgType.Connect); conn.InvokeHandlerNoData((short)MsgType.Connect);
return true; return true;
} }

View File

@ -391,7 +391,7 @@ void SendTransform()
return; return;
} }
m_LocalTransformWriter.StartMessage(MsgType.LocalChildTransform); m_LocalTransformWriter.StartMessage((short)MsgType.LocalChildTransform);
m_LocalTransformWriter.Write(netId); m_LocalTransformWriter.Write(netId);
m_LocalTransformWriter.WritePackedUInt32(m_ChildIndex); m_LocalTransformWriter.WritePackedUInt32(m_ChildIndex);
SerializeModeTransform(m_LocalTransformWriter); SerializeModeTransform(m_LocalTransformWriter);
@ -405,7 +405,7 @@ void SendTransform()
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.LocalChildTransform, "16:LocalChildTransform", 1); (short)MsgType.LocalChildTransform, "16:LocalChildTransform", 1);
#endif #endif
ClientScene.readyConnection.SendWriter(m_LocalTransformWriter, GetNetworkChannel()); ClientScene.readyConnection.SendWriter(m_LocalTransformWriter, GetNetworkChannel());
} }
@ -418,7 +418,7 @@ static internal void HandleChildTransform(NetworkMessage netMsg)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.LocalChildTransform, "16:LocalChildTransform", 1); (short)MsgType.LocalChildTransform, "16:LocalChildTransform", 1);
#endif #endif
GameObject foundObj = NetworkServer.FindLocalObject(netId); GameObject foundObj = NetworkServer.FindLocalObject(netId);

View File

@ -1189,7 +1189,7 @@ void SendTransform()
return; return;
} }
m_LocalTransformWriter.StartMessage(MsgType.LocalPlayerTransform); m_LocalTransformWriter.StartMessage((short)MsgType.LocalPlayerTransform);
m_LocalTransformWriter.Write(netId); m_LocalTransformWriter.Write(netId);
switch (transformSyncMode) switch (transformSyncMode)
@ -1243,7 +1243,7 @@ void SendTransform()
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.LocalPlayerTransform, "6:LocalPlayerTransform", 1); (short)MsgType.LocalPlayerTransform, "6:LocalPlayerTransform", 1);
#endif #endif
ClientScene.readyConnection.SendWriter(m_LocalTransformWriter, GetNetworkChannel()); ClientScene.readyConnection.SendWriter(m_LocalTransformWriter, GetNetworkChannel());
} }
@ -1255,7 +1255,7 @@ static public void HandleTransform(NetworkMessage netMsg)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
MsgType.LocalPlayerTransform, "6:LocalPlayerTransform", 1); (short)MsgType.LocalPlayerTransform, "6:LocalPlayerTransform", 1);
#endif #endif
GameObject foundObj = NetworkServer.FindLocalObject(netId); GameObject foundObj = NetworkServer.FindLocalObject(netId);

View File

@ -250,7 +250,7 @@ void SendMsg(Operation op, int itemIndex, T item)
} }
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
writer.StartMessage(MsgType.SyncList); writer.StartMessage((short)MsgType.SyncList);
writer.Write(uv.netId); writer.Write(uv.netId);
writer.WritePackedUInt32((uint)m_CmdHash); writer.WritePackedUInt32((uint)m_CmdHash);
writer.Write((byte)op); writer.Write((byte)op);
@ -263,7 +263,7 @@ void SendMsg(Operation op, int itemIndex, T item)
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
MsgType.SyncList, op.ToString(), 1); (short)MsgType.SyncList, op.ToString(), 1);
#endif #endif
// ensure it is invoked on host // ensure it is invoked on host

View File

@ -14,121 +14,58 @@ namespace UnityEngine.Networking
public delegate void UnSpawnDelegate(GameObject spawned); public delegate void UnSpawnDelegate(GameObject spawned);
// built-in system network messages // built-in system network messages
public class MsgType // original HLAPI uses short, so let's keep short to not break packet header etc.
// => use .ToString() to get the field name from the field value
// => we specify the short values so it's easier to look up opcodes when debugging packets
public enum MsgType : short
{ {
// internal system messages - cannot be replaced by user code // internal system messages - cannot be replaced by user code
public const short ObjectDestroy = 1; ObjectDestroy = 1,
public const short Rpc = 2; Rpc = 2,
public const short ObjectSpawn = 3; ObjectSpawn = 3,
public const short Owner = 4; Owner = 4,
public const short Command = 5; Command = 5,
public const short LocalPlayerTransform = 6; LocalPlayerTransform = 6,
public const short SyncEvent = 7; SyncEvent = 7,
public const short UpdateVars = 8; UpdateVars = 8,
public const short SyncList = 9; SyncList = 9,
public const short ObjectSpawnScene = 10; ObjectSpawnScene = 10,
public const short NetworkInfo = 11; NetworkInfo = 11,
public const short SpawnFinished = 12; SpawnFinished = 12,
public const short ObjectHide = 13; ObjectHide = 13,
public const short CRC = 14; CRC = 14,
public const short LocalClientAuthority = 15; LocalClientAuthority = 15,
public const short LocalChildTransform = 16; LocalChildTransform = 16,
public const short Fragment = 17; Fragment = 17,
public const short PeerClientAuthority = 18; PeerClientAuthority = 18,
// used for profiling // used for profiling
internal const short UserMessage = 0; UserMessage = 0,
internal const short HLAPIMsg = 28; HLAPIMsg = 28,
internal const short LLAPIMsg = 29; LLAPIMsg = 29,
internal const short HLAPIResend = 30; HLAPIResend = 30,
internal const short HLAPIPending = 31; HLAPIPending = 31,
public const short InternalHighest = 31; InternalHighest = 31,
// public system messages - can be replaced by user code // public system messages - can be replaced by user code
public const short Connect = 32; Connect = 32,
public const short Disconnect = 33; Disconnect = 33,
public const short Error = 34; Error = 34,
public const short Ready = 35; Ready = 35,
public const short NotReady = 36; NotReady = 36,
public const short AddPlayer = 37; AddPlayer = 37,
public const short RemovePlayer = 38; RemovePlayer = 38,
public const short Scene = 39; Scene = 39,
public const short Animation = 40; Animation = 40,
public const short AnimationParameters = 41; AnimationParameters = 41,
public const short AnimationTrigger = 42; AnimationTrigger = 42,
public const short LobbyReadyToBegin = 43; LobbyReadyToBegin = 43,
public const short LobbySceneLoaded = 44; LobbySceneLoaded = 44,
public const short LobbyAddPlayerFailed = 45; LobbyAddPlayerFailed = 45,
public const short LobbyReturnToLobby = 46; LobbyReturnToLobby = 46,
//NOTE: update msgLabels below if this is changed. Highest = 47
public const short Highest = 47;
static internal string[] msgLabels =
{
"none",
"ObjectDestroy",
"Rpc",
"ObjectSpawn",
"Owner",
"Command",
"LocalPlayerTransform",
"SyncEvent",
"UpdateVars",
"SyncList",
"ObjectSpawnScene", // 10
"NetworkInfo",
"SpawnFinished",
"ObjectHide",
"CRC",
"LocalClientAuthority",
"LocalChildTransform",
"Fragment",
"PeerClientAuthority",
"",
"", // 20
"",
"",
"",
"",
"",
"",
"",
"",
"",
"", // 30
"", // - SystemInternalHighest
"Connect", // 32,
"Disconnect",
"Error",
"Ready",
"NotReady",
"AddPlayer",
"RemovePlayer",
"Scene",
"Animation", // 40
"AnimationParams",
"AnimationTrigger",
"LobbyReadyToBegin",
"LobbySceneLoaded",
"LobbyAddPlayerFailed", // 45
"LobbyReturnToLobby", // 46
};
static public string MsgTypeToString(short value)
{
if (value < 0 || value > Highest)
{
return String.Empty;
}
string result = msgLabels[value];
if (string.IsNullOrEmpty(result))
{
result = "[" + value + "]";
}
return result;
}
} }
public class NetworkMessage public class NetworkMessage