diff --git a/Mirror/Editor/NetworkManagerEditor.cs b/Mirror/Editor/NetworkManagerEditor.cs index f38a551bf..8aaf1adc0 100644 --- a/Mirror/Editor/NetworkManagerEditor.cs +++ b/Mirror/Editor/NetworkManagerEditor.cs @@ -20,7 +20,7 @@ public class NetworkManagerEditor : Editor SerializedProperty m_ServerBindToIPProperty; SerializedProperty m_ServerBindAddressProperty; - protected SerializedProperty m_LogLevelProperty; + protected SerializedProperty m_ShowDebugMessagesProperty; SerializedProperty m_PlayerPrefabProperty; SerializedProperty m_AutoCreatePlayerProperty; @@ -36,6 +36,7 @@ public class NetworkManagerEditor : Editor GUIContent m_OnlineSceneLabel; protected GUIContent m_DontDestroyOnLoadLabel; protected GUIContent m_RunInBackgroundLabel; + protected GUIContent m_ShowDebugMessagesLabel; GUIContent m_MaxConnectionsLabel; @@ -71,6 +72,7 @@ protected void Init() m_OnlineSceneLabel = new GUIContent("Online Scene", "The scene loaded when the network comes online (connected to server)"); m_DontDestroyOnLoadLabel = new GUIContent("Don't Destroy on Load", "Enable to persist the NetworkManager across scene changes."); m_RunInBackgroundLabel = new GUIContent("Run in Background", "Enable to ensure that the application runs when it does not have focus.\n\nThis is required when testing multiple instances on a single machine, but not recommended for shipping on mobile platforms."); + m_ShowDebugMessagesLabel = new GUIContent("Show Debug Messages", "Enable to show Debug log messages."); m_MaxConnectionsLabel = new GUIContent("Max Connections", "Maximum number of network connections"); m_UseWebSocketsLabel = new GUIContent("Use WebSockets", "This makes the server listen for connections using WebSockets. This allows WebGL clients to connect to the server."); @@ -85,7 +87,7 @@ protected void Init() // top-level properties m_DontDestroyOnLoadProperty = serializedObject.FindProperty("m_DontDestroyOnLoad"); m_RunInBackgroundProperty = serializedObject.FindProperty("m_RunInBackground"); - m_LogLevelProperty = serializedObject.FindProperty("m_LogLevel"); + m_ShowDebugMessagesProperty = serializedObject.FindProperty("m_ShowDebugMessages"); // network foldout properties m_NetworkAddressProperty = serializedObject.FindProperty("m_NetworkAddress"); @@ -160,7 +162,7 @@ protected SceneAsset GetSceneObject(string sceneObjectName) return AssetDatabase.LoadAssetAtPath(editorScene.path, typeof(SceneAsset)) as SceneAsset; } } - if (LogFilter.logWarn) { Debug.LogWarning("Scene [" + sceneObjectName + "] cannot be used with networking. Add this scene to the 'Scenes in the Build' in build settings."); } + Debug.LogWarning("Scene [" + sceneObjectName + "] cannot be used with networking. Add this scene to the 'Scenes in the Build' in build settings."); return null; } @@ -294,18 +296,18 @@ protected void ShowDerivedProperties(Type baseType, Type superType) public override void OnInspectorGUI() { - if (m_DontDestroyOnLoadProperty == null || m_DontDestroyOnLoadLabel == null) + if (m_DontDestroyOnLoadProperty == null || m_DontDestroyOnLoadLabel == null || m_ShowDebugMessagesLabel == null) m_Initialized = false; Init(); serializedObject.Update(); EditorGUILayout.PropertyField(m_DontDestroyOnLoadProperty, m_DontDestroyOnLoadLabel); - EditorGUILayout.PropertyField(m_RunInBackgroundProperty , m_RunInBackgroundLabel); + EditorGUILayout.PropertyField(m_RunInBackgroundProperty, m_RunInBackgroundLabel); - if (EditorGUILayout.PropertyField(m_LogLevelProperty)) + if (EditorGUILayout.PropertyField(m_ShowDebugMessagesProperty, m_ShowDebugMessagesLabel)) { - LogFilter.currentLogLevel = m_NetworkManager.logLevel; + LogFilter.Debug = m_NetworkManager.showDebugMessages; } ShowScenes(); @@ -350,7 +352,7 @@ internal void DrawChild(Rect r, int index, bool isActive, bool isFocused) { if (newGameObject != null && !newGameObject.GetComponent()) { - if (LogFilter.logError) { Debug.LogError("Prefab " + newGameObject + " cannot be added as spawnable as it doesn't have a NetworkIdentity."); } + Debug.LogError("Prefab " + newGameObject + " cannot be added as spawnable as it doesn't have a NetworkIdentity."); return; } prefab.objectReferenceValue = newGameObject; diff --git a/Mirror/Editor/NetworkScenePostProcess.cs b/Mirror/Editor/NetworkScenePostProcess.cs index f6b1e6157..33d96fd38 100644 --- a/Mirror/Editor/NetworkScenePostProcess.cs +++ b/Mirror/Editor/NetworkScenePostProcess.cs @@ -149,7 +149,7 @@ public static void OnPostProcessScene() uv.gameObject.SetActive(false); uv.ForceSceneId(nextSceneId++); - if (LogFilter.logDebug) { Debug.Log("PostProcess sceneid assigned: name=" + uv.name + " scene=" + uv.gameObject.scene.name + " sceneid=" + uv.sceneId); } + if (LogFilter.Debug) { Debug.Log("PostProcess sceneid assigned: name=" + uv.name + " scene=" + uv.gameObject.scene.name + " sceneid=" + uv.sceneId); } // saftey check for prefabs with more than one NetworkIdentity var prefabGO = PrefabUtility.GetPrefabParent(uv.gameObject) as GameObject; diff --git a/Mirror/Editor/NetworkTransformChildEditor.cs b/Mirror/Editor/NetworkTransformChildEditor.cs index 6e9dcc45f..ea1ced06e 100644 --- a/Mirror/Editor/NetworkTransformChildEditor.cs +++ b/Mirror/Editor/NetworkTransformChildEditor.cs @@ -42,7 +42,7 @@ public void Init() m_Target = serializedObject.FindProperty("m_Target"); if (sync.GetComponent() == null) { - if (LogFilter.logError) { Debug.LogError("NetworkTransformChild must be on the root object with the NetworkTransform, not on the child node"); } + Debug.LogError("NetworkTransformChild must be on the root object with the NetworkTransform, not on the child node"); m_Target.objectReferenceValue = null; } @@ -98,7 +98,7 @@ protected void ShowControls() { if (sync.GetComponent() == null) { - if (LogFilter.logError) { Debug.LogError("NetworkTransformChild must be on the root object with the NetworkTransform, not on the child node"); } + Debug.LogError("NetworkTransformChild must be on the root object with the NetworkTransform, not on the child node"); m_Target.objectReferenceValue = null; } } diff --git a/Mirror/Runtime/ClientScene.cs b/Mirror/Runtime/ClientScene.cs index 56baee11d..c1cbaa322 100644 --- a/Mirror/Runtime/ClientScene.cs +++ b/Mirror/Runtime/ClientScene.cs @@ -48,14 +48,14 @@ internal static void Shutdown() // this is called from message handler for Owner message internal static void InternalAddPlayer(NetworkIdentity view) { - if (LogFilter.logDebug) { Debug.LogWarning("ClientScene::InternalAddPlayer"); } + if (LogFilter.Debug) { Debug.LogWarning("ClientScene::InternalAddPlayer"); } // NOTE: It can be "normal" when changing scenes for the player to be destroyed and recreated. // But, the player structures are not cleaned up, we'll just replace the old player s_LocalPlayer = view; if (s_ReadyConnection == null) { - if (LogFilter.logWarn) { Debug.LogWarning("No ready connection found for setting player controller during InternalAddPlayer"); } + Debug.LogWarning("No ready connection found for setting player controller during InternalAddPlayer"); } else { @@ -87,17 +87,17 @@ public static bool AddPlayer(NetworkConnection readyConn, MessageBase extraMessa if (!s_IsReady) { - if (LogFilter.logError) { Debug.LogError("Must call AddPlayer() with a connection the first time to become ready."); } + Debug.LogError("Must call AddPlayer() with a connection the first time to become ready."); return false; } if (s_ReadyConnection.playerController != null) { - if (LogFilter.logError) { Debug.LogError("ClientScene::AddPlayer: a PlayerController was already added. Did you call AddPlayer twice?"); } + Debug.LogError("ClientScene::AddPlayer: a PlayerController was already added. Did you call AddPlayer twice?"); return false; } - if (LogFilter.logDebug) { Debug.Log("ClientScene::AddPlayer() called with connection [" + s_ReadyConnection + "]"); } + if (LogFilter.Debug) { Debug.Log("ClientScene::AddPlayer() called with connection [" + s_ReadyConnection + "]"); } AddPlayerMessage msg = new AddPlayerMessage(); if (extraMessage != null) @@ -112,7 +112,7 @@ public static bool AddPlayer(NetworkConnection readyConn, MessageBase extraMessa public static bool RemovePlayer() { - if (LogFilter.logDebug) { Debug.Log("ClientScene::RemovePlayer() called with connection [" + s_ReadyConnection + "]"); } + if (LogFilter.Debug) { Debug.Log("ClientScene::RemovePlayer() called with connection [" + s_ReadyConnection + "]"); } if (s_ReadyConnection.playerController != null) { @@ -132,11 +132,11 @@ public static bool Ready(NetworkConnection conn) { if (s_IsReady) { - if (LogFilter.logError) { Debug.LogError("A connection has already been set as ready. There can only be one."); } + Debug.LogError("A connection has already been set as ready. There can only be one."); return false; } - if (LogFilter.logDebug) { Debug.Log("ClientScene::Ready() called with connection [" + conn + "]"); } + if (LogFilter.Debug) { Debug.Log("ClientScene::Ready() called with connection [" + conn + "]"); } if (conn != null) { @@ -147,7 +147,7 @@ public static bool Ready(NetworkConnection conn) s_ReadyConnection.isReady = true; return true; } - if (LogFilter.logError) { Debug.LogError("Ready() called with invalid connection object: conn=null"); } + Debug.LogError("Ready() called with invalid connection object: conn=null"); return false; } @@ -182,7 +182,7 @@ internal static void PrepareToSpawnSceneObjects() uv.sceneId != 0) { s_SpawnableObjects[uv.sceneId] = uv; - if (LogFilter.logDebug) { Debug.Log("ClientScene::PrepareSpawnObjects sceneId:" + uv.sceneId); } + if (LogFilter.Debug) { Debug.Log("ClientScene::PrepareSpawnObjects sceneId:" + uv.sceneId); } } } } @@ -336,10 +336,10 @@ static void OnSpawnPrefab(NetworkMessage netMsg) if (msg.assetId == Guid.Empty) { - if (LogFilter.logError) { Debug.LogError("OnObjSpawn netId: " + msg.netId + " has invalid asset Id"); } + Debug.LogError("OnObjSpawn netId: " + msg.netId + " has invalid asset Id"); return; } - if (LogFilter.logDebug) { Debug.Log("Client spawn handler instantiating [netId:" + msg.netId + " asset ID:" + msg.assetId + " pos:" + msg.position + "]"); } + if (LogFilter.Debug) { Debug.Log("Client spawn handler instantiating [netId:" + msg.netId + " asset ID:" + msg.assetId + " pos:" + msg.position + "]"); } NetworkIdentity localNetworkIdentity; if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localNetworkIdentity)) @@ -355,7 +355,7 @@ static void OnSpawnPrefab(NetworkMessage netMsg) if (NetworkScene.GetPrefab(msg.assetId, out prefab)) { var obj = (GameObject)Object.Instantiate(prefab, msg.position, msg.rotation); - if (LogFilter.logDebug) + if (LogFilter.Debug) { Debug.Log("Client spawn handler instantiating [netId:" + msg.netId + " asset ID:" + msg.assetId + " pos:" + msg.position + " rotation: " + msg.rotation + "]"); } @@ -363,7 +363,7 @@ static void OnSpawnPrefab(NetworkMessage netMsg) localNetworkIdentity = obj.GetComponent(); if (localNetworkIdentity == null) { - if (LogFilter.logError) { Debug.LogError("Client object spawned for " + msg.assetId + " does not have a NetworkIdentity"); } + Debug.LogError("Client object spawned for " + msg.assetId + " does not have a NetworkIdentity"); return; } localNetworkIdentity.Reset(); @@ -375,13 +375,13 @@ static void OnSpawnPrefab(NetworkMessage netMsg) GameObject obj = handler(msg.position, msg.assetId); if (obj == null) { - if (LogFilter.logWarn) { Debug.LogWarning("Client spawn handler for " + msg.assetId + " returned null"); } + Debug.LogWarning("Client spawn handler for " + msg.assetId + " returned null"); return; } localNetworkIdentity = obj.GetComponent(); if (localNetworkIdentity == null) { - if (LogFilter.logError) { Debug.LogError("Client object spawned for " + msg.assetId + " does not have a network identity"); } + Debug.LogError("Client object spawned for " + msg.assetId + " does not have a network identity"); return; } localNetworkIdentity.Reset(); @@ -390,7 +390,7 @@ static void OnSpawnPrefab(NetworkMessage netMsg) } else { - if (LogFilter.logError) { Debug.LogError("Failed to spawn server object, did you forget to add it to the NetworkManager? assetId=" + msg.assetId + " netId=" + msg.netId); } + Debug.LogError("Failed to spawn server object, did you forget to add it to the NetworkManager? assetId=" + msg.assetId + " netId=" + msg.netId); } } @@ -399,7 +399,7 @@ static void OnSpawnSceneObject(NetworkMessage netMsg) SpawnSceneObjectMessage msg = new SpawnSceneObjectMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDebug) { Debug.Log("Client spawn scene handler instantiating [netId:" + msg.netId + " sceneId:" + msg.sceneId + " pos:" + msg.position); } + if (LogFilter.Debug) { Debug.Log("Client spawn scene handler instantiating [netId:" + msg.netId + " sceneId:" + msg.sceneId + " pos:" + msg.position); } NetworkIdentity localNetworkIdentity; if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localNetworkIdentity)) @@ -413,17 +413,14 @@ static void OnSpawnSceneObject(NetworkMessage netMsg) NetworkIdentity spawnedId = SpawnSceneObject(msg.sceneId); if (spawnedId == null) { - if (LogFilter.logError) - { - Debug.LogError("Spawn scene object not found for " + msg.sceneId + " SpawnableObjects.Count=" + s_SpawnableObjects.Count); - // dump the whole spawnable objects dict for easier debugging - foreach (var kvp in s_SpawnableObjects) - Debug.Log("Spawnable: SceneId=" + kvp.Key + " name=" + kvp.Value.name); - } + Debug.LogError("Spawn scene object not found for " + msg.sceneId + " SpawnableObjects.Count=" + s_SpawnableObjects.Count); + // dump the whole spawnable objects dict for easier debugging + foreach (var kvp in s_SpawnableObjects) + Debug.Log("Spawnable: SceneId=" + kvp.Key + " name=" + kvp.Value.name); return; } - if (LogFilter.logDebug) { Debug.Log("Client spawn for [netId:" + msg.netId + "] [sceneId:" + msg.sceneId + "] obj:" + spawnedId.gameObject.name); } + if (LogFilter.Debug) { Debug.Log("Client spawn for [netId:" + msg.netId + "] [sceneId:" + msg.sceneId + "] obj:" + spawnedId.gameObject.name); } spawnedId.Reset(); ApplySpawnPayload(spawnedId, msg.position, msg.payload, msg.netId, spawnedId.gameObject); } @@ -432,7 +429,7 @@ static void OnObjectSpawnFinished(NetworkMessage netMsg) { ObjectSpawnFinishedMessage msg = new ObjectSpawnFinishedMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDebug) { Debug.Log("SpawnFinished:" + msg.state); } + if (LogFilter.Debug) { Debug.Log("SpawnFinished:" + msg.state); } if (msg.state == 0) { @@ -456,7 +453,7 @@ static void OnObjectDestroy(NetworkMessage netMsg) { ObjectDestroyMessage msg = new ObjectDestroyMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDebug) { Debug.Log("ClientScene::OnObjDestroy netId:" + msg.netId); } + if (LogFilter.Debug) { Debug.Log("ClientScene::OnObjDestroy netId:" + msg.netId); } NetworkIdentity localObject; if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localObject)) @@ -482,7 +479,7 @@ static void OnObjectDestroy(NetworkMessage netMsg) } else { - if (LogFilter.logDebug) { Debug.LogWarning("Did not find target for destroy message for " + msg.netId); } + if (LogFilter.Debug) { Debug.LogWarning("Did not find target for destroy message for " + msg.netId); } } } @@ -490,7 +487,7 @@ static void OnLocalClientObjectDestroy(NetworkMessage netMsg) { ObjectDestroyMessage msg = new ObjectDestroyMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDebug) { Debug.Log("ClientScene::OnLocalObjectObjDestroy netId:" + msg.netId); } + if (LogFilter.Debug) { Debug.Log("ClientScene::OnLocalObjectObjDestroy netId:" + msg.netId); } s_NetworkScene.RemoveLocalObject(msg.netId); } @@ -499,7 +496,7 @@ static void OnLocalClientObjectHide(NetworkMessage netMsg) { ObjectDestroyMessage msg = new ObjectDestroyMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDebug) { Debug.Log("ClientScene::OnLocalObjectObjHide netId:" + msg.netId); } + if (LogFilter.Debug) { Debug.Log("ClientScene::OnLocalObjectObjHide netId:" + msg.netId); } NetworkIdentity localObject; if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localObject)) @@ -536,7 +533,7 @@ static void OnUpdateVarsMessage(NetworkMessage netMsg) { UpdateVarsMessage message = netMsg.ReadMessage(); - if (LogFilter.logDev) { Debug.Log("ClientScene::OnUpdateVarsMessage " + message.netId); } + if (LogFilter.Debug) { Debug.Log("ClientScene::OnUpdateVarsMessage " + message.netId); } NetworkIdentity localObject; if (s_NetworkScene.GetNetworkIdentity(message.netId, out localObject)) @@ -545,7 +542,7 @@ static void OnUpdateVarsMessage(NetworkMessage netMsg) } else { - if (LogFilter.logWarn) { Debug.LogWarning("Did not find target for sync message for " + message.netId + " . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message."); } + Debug.LogWarning("Did not find target for sync message for " + message.netId + " . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message."); } } @@ -553,7 +550,7 @@ static void OnRPCMessage(NetworkMessage netMsg) { RpcMessage message = netMsg.ReadMessage(); - if (LogFilter.logDebug) { Debug.Log("ClientScene::OnRPCMessage hash:" + message.rpcHash + " netId:" + message.netId); } + if (LogFilter.Debug) { Debug.Log("ClientScene::OnRPCMessage hash:" + message.rpcHash + " netId:" + message.netId); } NetworkIdentity uv; if (s_NetworkScene.GetNetworkIdentity(message.netId, out uv)) @@ -562,11 +559,8 @@ static void OnRPCMessage(NetworkMessage netMsg) } else { - if (LogFilter.logWarn) - { - string errorRpcName = NetworkBehaviour.GetCmdHashHandlerName(message.rpcHash); - Debug.LogWarningFormat("Could not find target object with netId:{0} for RPC call {1}", message.netId, errorRpcName); - } + string errorRpcName = NetworkBehaviour.GetCmdHashHandlerName(message.rpcHash); + Debug.LogWarningFormat("Could not find target object with netId:{0} for RPC call {1}", message.netId, errorRpcName); } } @@ -574,7 +568,7 @@ static void OnSyncEventMessage(NetworkMessage netMsg) { SyncEventMessage message = netMsg.ReadMessage(); - if (LogFilter.logDebug) { Debug.Log("ClientScene::OnSyncEventMessage " + message.netId); } + if (LogFilter.Debug) { Debug.Log("ClientScene::OnSyncEventMessage " + message.netId); } NetworkIdentity uv; if (s_NetworkScene.GetNetworkIdentity(message.netId, out uv)) @@ -583,7 +577,7 @@ static void OnSyncEventMessage(NetworkMessage netMsg) } else { - if (LogFilter.logWarn) { Debug.LogWarning("Did not find target for SyncEvent message for " + message.netId); } + Debug.LogWarning("Did not find target for SyncEvent message for " + message.netId); } } @@ -592,7 +586,7 @@ static void OnClientAuthority(NetworkMessage netMsg) ClientAuthorityMessage msg = new ClientAuthorityMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDebug) { Debug.Log("ClientScene::OnClientAuthority for connectionId=" + netMsg.conn.connectionId + " netId: " + msg.netId); } + if (LogFilter.Debug) { Debug.Log("ClientScene::OnClientAuthority for connectionId=" + netMsg.conn.connectionId + " netId: " + msg.netId); } NetworkIdentity uv; if (s_NetworkScene.GetNetworkIdentity(msg.netId, out uv)) @@ -607,7 +601,7 @@ static void OnOwnerMessage(NetworkMessage netMsg) OwnerMessage msg = new OwnerMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDebug) { Debug.Log("ClientScene::OnOwnerMessage - connectionId=" + netMsg.conn.connectionId + " netId: " + msg.netId); } + if (LogFilter.Debug) { Debug.Log("ClientScene::OnOwnerMessage - connectionId=" + netMsg.conn.connectionId + " netId: " + msg.netId); } // is there already an owner that is a different object?? if (netMsg.conn.playerController != null) @@ -643,10 +637,10 @@ static void CheckForOwner(NetworkIdentity uv) uv.SetConnectionToServer(s_ReadyConnection); uv.SetLocalPlayer(); - if (LogFilter.logDev) { Debug.Log("ClientScene::OnOwnerMessage - player=" + uv.gameObject.name); } + if (LogFilter.Debug) { Debug.Log("ClientScene::OnOwnerMessage - player=" + uv.gameObject.name); } if (s_ReadyConnection.connectionId < 0) { - if (LogFilter.logError) { Debug.LogError("Owner message received on a local client."); } + Debug.LogError("Owner message received on a local client."); return; } InternalAddPlayer(uv); diff --git a/Mirror/Runtime/LocalClient.cs b/Mirror/Runtime/LocalClient.cs index 4616a3f5c..7b5ef8828 100644 --- a/Mirror/Runtime/LocalClient.cs +++ b/Mirror/Runtime/LocalClient.cs @@ -53,7 +53,7 @@ internal override void Update() // Called by the server to set the LocalClient's LocalPlayer object during NetworkServer.AddPlayer() internal void AddLocalPlayer(NetworkIdentity localPlayer) { - if (LogFilter.logDev) Debug.Log("Local client AddLocalPlayer " + localPlayer.gameObject.name + " conn=" + m_Connection.connectionId); + if (LogFilter.Debug) Debug.Log("Local client AddLocalPlayer " + localPlayer.gameObject.name + " conn=" + m_Connection.connectionId); m_Connection.isReady = true; m_Connection.SetPlayerController(localPlayer); NetworkIdentity uv = localPlayer; @@ -121,7 +121,7 @@ internal void InvokeBytesOnClient(byte[] buffer) { PostInternalMessage((short)msgType, content); } - else if (LogFilter.logError) Debug.LogError("InvokeBytesOnClient failed to unpack message: " + BitConverter.ToString(buffer)); + else Debug.LogError("InvokeBytesOnClient failed to unpack message: " + BitConverter.ToString(buffer)); } } } diff --git a/Mirror/Runtime/LocalConnections.cs b/Mirror/Runtime/LocalConnections.cs index 6129f1911..187ee0682 100644 --- a/Mirror/Runtime/LocalConnections.cs +++ b/Mirror/Runtime/LocalConnections.cs @@ -37,7 +37,7 @@ protected override bool SendBytes(byte[] bytes) { if (bytes.Length == 0) { - if (LogFilter.logError) { Debug.LogError("LocalConnection:SendBytes cannot send zero bytes"); } + Debug.LogError("LocalConnection:SendBytes cannot send zero bytes"); return false; } return NetworkServer.InvokeBytes(this, bytes); diff --git a/Mirror/Runtime/LogFilter.cs b/Mirror/Runtime/LogFilter.cs index 31a49814c..f7d74992d 100644 --- a/Mirror/Runtime/LogFilter.cs +++ b/Mirror/Runtime/LogFilter.cs @@ -5,23 +5,6 @@ namespace Mirror { public static class LogFilter { - // this only exists for inspector UI?! - public enum FilterLevel - { - Developer = 0, - Debug = 1, - Info = 2, - Warn = 3, - Error = 4, - SetInScripting = -1 - } - - public static FilterLevel currentLogLevel = FilterLevel.Info; - - internal static bool logDev { get { return currentLogLevel <= FilterLevel.Developer; } } - public static bool logDebug { get { return currentLogLevel <= FilterLevel.Debug; } } - public static bool logInfo { get { return currentLogLevel <= FilterLevel.Info; } } - public static bool logWarn { get { return currentLogLevel <= FilterLevel.Warn; } } - public static bool logError { get { return currentLogLevel <= FilterLevel.Error; } } + public static bool Debug = false; } } diff --git a/Mirror/Runtime/NetworkAnimator.cs b/Mirror/Runtime/NetworkAnimator.cs index 648d61ded..cf08d7b9f 100644 --- a/Mirror/Runtime/NetworkAnimator.cs +++ b/Mirror/Runtime/NetworkAnimator.cs @@ -368,7 +368,7 @@ internal static void OnAnimationServerMessage(NetworkMessage netMsg) { AnimationMessage msg = new AnimationMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDev) { Debug.Log("OnAnimationMessage for netId=" + msg.netId + " conn=" + netMsg.conn); } + if (LogFilter.Debug) { Debug.Log("OnAnimationMessage for netId=" + msg.netId + " conn=" + netMsg.conn); } GameObject go = NetworkServer.FindLocalObject(msg.netId); if (go == null) @@ -390,7 +390,7 @@ internal static void OnAnimationParametersServerMessage(NetworkMessage netMsg) AnimationParametersMessage msg = new AnimationParametersMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDev) { Debug.Log("OnAnimationParametersMessage for netId=" + msg.netId + " conn=" + netMsg.conn); } + if (LogFilter.Debug) { Debug.Log("OnAnimationParametersMessage for netId=" + msg.netId + " conn=" + netMsg.conn); } GameObject go = NetworkServer.FindLocalObject(msg.netId); if (go == null) @@ -410,7 +410,7 @@ internal static void OnAnimationTriggerServerMessage(NetworkMessage netMsg) { AnimationTriggerMessage msg = new AnimationTriggerMessage(); netMsg.ReadMessage(msg); - if (LogFilter.logDev) { Debug.Log("OnAnimationTriggerMessage for netId=" + msg.netId + " conn=" + netMsg.conn); } + if (LogFilter.Debug) { Debug.Log("OnAnimationTriggerMessage for netId=" + msg.netId + " conn=" + netMsg.conn); } GameObject go = NetworkServer.FindLocalObject(msg.netId); if (go == null) diff --git a/Mirror/Runtime/NetworkBehaviour.cs b/Mirror/Runtime/NetworkBehaviour.cs index b59b4ec1c..2e28fb8b5 100644 --- a/Mirror/Runtime/NetworkBehaviour.cs +++ b/Mirror/Runtime/NetworkBehaviour.cs @@ -31,7 +31,7 @@ public class NetworkBehaviour : MonoBehaviour // objects that can synchronize themselves, such as synclists protected readonly List m_SyncObjects = new List(); - + const float k_DefaultSendInterval = 0.1f; NetworkIdentity m_MyView; @@ -42,7 +42,7 @@ NetworkIdentity myView m_MyView = m_MyView ?? GetComponent(); if (m_MyView == null) { - if (LogFilter.logError) { Debug.LogError("There is no NetworkIdentity on this object. Please add one."); } + Debug.LogError("There is no NetworkIdentity on this object. Please add one."); } return m_MyView; } @@ -64,13 +64,13 @@ protected void SendCommandInternal(int cmdHash, NetworkWriter writer, string cmd // local players can always send commands, regardless of authority, other objects must have authority. if (!(isLocalPlayer || hasAuthority)) { - if (LogFilter.logWarn) { Debug.LogWarning("Trying to send command for object without authority."); } + Debug.LogWarning("Trying to send command for object without authority."); return; } if (ClientScene.readyConnection == null) { - if (LogFilter.logError) { Debug.LogError("Send command attempted with no client running [client=" + connectionToServer + "]."); } + Debug.LogError("Send command attempted with no client running [client=" + connectionToServer + "]."); return; } @@ -97,7 +97,7 @@ protected void SendRPCInternal(int rpcHash, NetworkWriter writer, string rpcName // This cannot use NetworkServer.active, as that is not specific to this object. if (!isServer) { - if (LogFilter.logWarn) { Debug.LogWarning("ClientRpc call on un-spawned object"); } + Debug.LogWarning("ClientRpc call on un-spawned object"); return; } @@ -116,7 +116,7 @@ protected void SendTargetRPCInternal(NetworkConnection conn, int rpcHash, Networ // This cannot use NetworkServer.active, as that is not specific to this object. if (!isServer) { - if (LogFilter.logWarn) { Debug.LogWarning("TargetRpc call on un-spawned object"); } + Debug.LogWarning("TargetRpc call on un-spawned object"); return; } @@ -142,7 +142,7 @@ protected void SendEventInternal(int eventHash, NetworkWriter writer, string eve { if (!NetworkServer.active) { - if (LogFilter.logWarn) { Debug.LogWarning("SendEvent no server?"); } + Debug.LogWarning("SendEvent no server?"); return; } @@ -199,7 +199,7 @@ protected static void RegisterCommandDelegate(Type invokeClass, int cmdHash, Cmd inv.invokeClass = invokeClass; inv.invokeFunction = func; s_CmdHandlerDelegates[cmdHash] = inv; - if (LogFilter.logDev) { Debug.Log("RegisterCommandDelegate hash:" + cmdHash + " " + func.GetMethodName()); } + if (LogFilter.logDebug) { Debug.Log("RegisterCommandDelegate hash:" + cmdHash + " " + func.GetMethodName()); } } [EditorBrowsable(EditorBrowsableState.Never)] @@ -214,7 +214,7 @@ protected static void RegisterRpcDelegate(Type invokeClass, int cmdHash, CmdDele inv.invokeClass = invokeClass; inv.invokeFunction = func; s_CmdHandlerDelegates[cmdHash] = inv; - if (LogFilter.logDev) { Debug.Log("RegisterRpcDelegate hash:" + cmdHash + " " + func.GetMethodName()); } + if (LogFilter.logDebug) { Debug.Log("RegisterRpcDelegate hash:" + cmdHash + " " + func.GetMethodName()); } } [EditorBrowsable(EditorBrowsableState.Never)] @@ -229,7 +229,7 @@ protected static void RegisterEventDelegate(Type invokeClass, int cmdHash, CmdDe inv.invokeClass = invokeClass; inv.invokeFunction = func; s_CmdHandlerDelegates[cmdHash] = inv; - if (LogFilter.logDev) { Debug.Log("RegisterEventDelegate hash:" + cmdHash + " " + func.GetMethodName()); } + if (LogFilter.logDebug) { Debug.Log("RegisterEventDelegate hash:" + cmdHash + " " + func.GetMethodName()); } } internal static string GetInvoker(int cmdHash) @@ -264,7 +264,7 @@ static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out Type i Invoker invoker = null; if (!s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker)) { - if (LogFilter.logDev) { Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found"); } + if (LogFilter.logDebug) { Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found"); } invokeClass = null; invokeFunction = null; return false; @@ -272,7 +272,7 @@ static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out Type i if (invoker == null) { - if (LogFilter.logDev) { Debug.Log("GetInvokerForHash hash:" + cmdHash + " invoker null"); } + if (LogFilter.logDebug) { Debug.Log("GetInvokerForHash hash:" + cmdHash + " invoker null"); } invokeClass = null; invokeFunction = null; return false; @@ -280,7 +280,7 @@ static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out Type i if (invoker.invokeType != invokeType) { - if (LogFilter.logError) { Debug.LogError("GetInvokerForHash hash:" + cmdHash + " mismatched invokeType"); } + Debug.LogError("GetInvokerForHash hash:" + cmdHash + " mismatched invokeType"); invokeClass = null; invokeFunction = null; return false; @@ -416,7 +416,7 @@ protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gam newGameObjectNetId = uv.netId; if (newGameObjectNetId == 0) { - if (LogFilter.logWarn) { Debug.LogWarning("SetSyncVarGameObject GameObject " + newGameObject + " has a zero netId. Maybe it is not spawned yet?"); } + Debug.LogWarning("SetSyncVarGameObject GameObject " + newGameObject + " has a zero netId. Maybe it is not spawned yet?"); } } } @@ -429,7 +429,7 @@ protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gam if (newGameObjectNetId != oldGameObjectNetId) { - if (LogFilter.logDev) { Debug.Log("SetSyncVar GameObject " + GetType().Name + " bit [" + dirtyBit + "] netfieldId:" + oldGameObjectNetId + "->" + newGameObjectNetId); } + if (LogFilter.logDebug) { Debug.Log("SetSyncVar GameObject " + GetType().Name + " bit [" + dirtyBit + "] netfieldId:" + oldGameObjectNetId + "->" + newGameObjectNetId); } SetDirtyBit(dirtyBit); gameObjectField = newGameObject; netIdField = newGameObjectNetId; @@ -443,7 +443,7 @@ protected void SetSyncVar(T value, ref T fieldValue, ulong dirtyBit) if ((value == null && fieldValue != null) || (value != null && !value.Equals(fieldValue))) { - if (LogFilter.logDev) { Debug.Log("SetSyncVar " + GetType().Name + " bit [" + dirtyBit + "] " + fieldValue + "->" + value); } + if (LogFilter.logDebug) { Debug.Log("SetSyncVar " + GetType().Name + " bit [" + dirtyBit + "] " + fieldValue + "->" + value); } SetDirtyBit(dirtyBit); fieldValue = value; } diff --git a/Mirror/Runtime/NetworkClient.cs b/Mirror/Runtime/NetworkClient.cs index 60a50da5b..9c98dd869 100644 --- a/Mirror/Runtime/NetworkClient.cs +++ b/Mirror/Runtime/NetworkClient.cs @@ -80,13 +80,13 @@ public void SetNetworkConnectionClass() where T : NetworkConnection public NetworkClient() { - if (LogFilter.logDev) { Debug.Log("Client created version " + Version.Current); } + if (LogFilter.Debug) { Debug.Log("Client created version " + Version.Current); } AddClient(this); } public NetworkClient(NetworkConnection conn) { - if (LogFilter.logDev) { Debug.Log("Client created version " + Version.Current); } + if (LogFilter.Debug) { Debug.Log("Client created version " + Version.Current); } AddClient(this); SetActive(true); @@ -100,7 +100,7 @@ public void Connect(string serverIp, int serverPort) { PrepareForConnect(); - if (LogFilter.logDebug) { Debug.Log("Client Connect: " + serverIp + ":" + serverPort); } + if (LogFilter.Debug) { Debug.Log("Client Connect: " + serverIp + ":" + serverPort); } string hostnameOrIp = serverIp; m_ServerPort = serverPort; @@ -141,18 +141,18 @@ public bool Send(short msgType, MessageBase msg) { if (connectState != ConnectState.Connected) { - if (LogFilter.logError) { Debug.LogError("NetworkClient Send when not connected to a server"); } + Debug.LogError("NetworkClient Send when not connected to a server"); return false; } return m_Connection.Send(msgType, msg); } - if (LogFilter.logError) { Debug.LogError("NetworkClient Send with no connection"); } + Debug.LogError("NetworkClient Send with no connection"); return false; } public void Shutdown() { - if (LogFilter.logDebug) Debug.Log("Shutting down client " + m_ClientId); + if (LogFilter.Debug) Debug.Log("Shutting down client " + m_ClientId); m_ClientId = -1; RemoveClient(this); if (s_Clients.Count == 0) @@ -253,7 +253,7 @@ internal virtual void Update() void GenerateConnectError(byte error) { - if (LogFilter.logError) { Debug.LogError("UNet Client Error Connect Error: " + error); } + Debug.LogError("UNet Client Error Connect Error: " + error); GenerateError(error); } @@ -261,14 +261,14 @@ void GenerateConnectError(byte error) void GenerateDataError(byte error) { NetworkError dataError = (NetworkError)error; - if (LogFilter.logError) { Debug.LogError("UNet Client Data Error: " + dataError); } + Debug.LogError("UNet Client Data Error: " + dataError); GenerateError(error); } void GenerateDisconnectError(byte error) { NetworkError disconnectError = (NetworkError)error; - if (LogFilter.logError) { Debug.LogError("UNet Client Disconnect Error: " + disconnectError); } + Debug.LogError("UNet Client Disconnect Error: " + disconnectError); GenerateError(error); } */ @@ -308,7 +308,7 @@ public void RegisterHandler(short msgType, NetworkMessageDelegate handler) { if (m_MessageHandlers.ContainsKey(msgType)) { - if (LogFilter.logDebug) { Debug.Log("NetworkClient.RegisterHandler replacing " + msgType); } + if (LogFilter.Debug) { Debug.Log("NetworkClient.RegisterHandler replacing " + msgType); } } m_MessageHandlers[msgType] = handler; } diff --git a/Mirror/Runtime/NetworkConnection.cs b/Mirror/Runtime/NetworkConnection.cs index a309eeef2..48ee21cc9 100644 --- a/Mirror/Runtime/NetworkConnection.cs +++ b/Mirror/Runtime/NetworkConnection.cs @@ -119,7 +119,7 @@ public bool InvokeHandler(short msgType, NetworkReader reader) msgDelegate(message); return true; } - if (LogFilter.logError) { Debug.LogError("NetworkConnection InvokeHandler no handler for " + msgType); } + Debug.LogError("NetworkConnection InvokeHandler no handler for " + msgType); return false; } @@ -138,7 +138,7 @@ public void RegisterHandler(short msgType, NetworkMessageDelegate handler) { if (m_MessageHandlers.ContainsKey(msgType)) { - if (LogFilter.logDebug) { Debug.Log("NetworkConnection.RegisterHandler replacing " + msgType); } + if (LogFilter.Debug) { Debug.Log("NetworkConnection.RegisterHandler replacing " + msgType); } } m_MessageHandlers[msgType] = handler; } @@ -176,14 +176,14 @@ protected virtual bool SendBytes(byte[] bytes) if (bytes.Length > Transport.MaxPacketSize) { - if (LogFilter.logError) { Debug.LogError("NetworkConnection:SendBytes cannot send packet larger than " + Transport.MaxPacketSize + " bytes"); } + Debug.LogError("NetworkConnection:SendBytes cannot send packet larger than " + Transport.MaxPacketSize + " bytes"); return false; } if (bytes.Length == 0) { // zero length packets getting into the packet queues are bad. - if (LogFilter.logError) { Debug.LogError("NetworkConnection:SendBytes cannot send zero bytes"); } + Debug.LogError("NetworkConnection:SendBytes cannot send zero bytes"); return false; } @@ -222,12 +222,12 @@ protected void HandleBytes(byte[] buffer) else { //NOTE: this throws away the rest of the buffer. Need moar error codes - if (LogFilter.logError) { Debug.LogError("Unknown message ID " + msgType + " connId:" + connectionId); } + Debug.LogError("Unknown message ID " + msgType + " connId:" + connectionId); } } else { - if (LogFilter.logError) { Debug.LogError("HandleBytes UnpackMessage failed for: " + BitConverter.ToString(buffer)); } + Debug.LogError("HandleBytes UnpackMessage failed for: " + BitConverter.ToString(buffer)); } } diff --git a/Mirror/Runtime/NetworkIdentity.cs b/Mirror/Runtime/NetworkIdentity.cs index fedb19ca1..255a7f4a0 100644 --- a/Mirror/Runtime/NetworkIdentity.cs +++ b/Mirror/Runtime/NetworkIdentity.cs @@ -83,7 +83,7 @@ internal void SetDynamicAssetId(Guid newAssetId) } else { - if (LogFilter.logWarn) { Debug.LogWarning("SetDynamicAssetId object already has an assetId <" + m_AssetId + ">"); } + Debug.LogWarning("SetDynamicAssetId object already has an assetId <" + m_AssetId + ">"); } } @@ -92,7 +92,7 @@ internal void SetClientOwner(NetworkConnection conn) { if (m_ClientAuthorityOwner != null) { - if (LogFilter.logError) { Debug.LogError("SetClientOwner m_ClientAuthorityOwner already set!"); } + Debug.LogError("SetClientOwner m_ClientAuthorityOwner already set!"); } m_ClientAuthorityOwner = conn; m_ClientAuthorityOwner.AddOwnedObject(this); @@ -195,7 +195,7 @@ void OnValidate() { if (m_ServerOnly && m_LocalPlayerAuthority) { - if (LogFilter.logWarn) { Debug.LogWarning("Disabling Local Player Authority for " + gameObject + " because it is server-only."); } + Debug.LogWarning("Disabling Local Player Authority for " + gameObject + " because it is server-only."); m_LocalPlayerAuthority = false; } @@ -225,7 +225,7 @@ bool ThisIsASceneObjectWithPrefabParent(out GameObject prefab) prefab = (GameObject)PrefabUtility.GetPrefabParent(gameObject); if (prefab == null) { - if (LogFilter.logError) { Debug.LogError("Failed to find prefab parent for scene object [name:" + gameObject.name + "]"); } + Debug.LogError("Failed to find prefab parent for scene object [name:" + gameObject.name + "]"); return false; } return true; @@ -279,12 +279,12 @@ internal void OnStartServer(bool allowNonZeroNetId) { if (!allowNonZeroNetId) { - if (LogFilter.logError) { Debug.LogError("Object has non-zero netId " + netId + " for " + gameObject); } + Debug.LogError("Object has non-zero netId " + netId + " for " + gameObject); return; } } - if (LogFilter.logDev) { Debug.Log("OnStartServer " + gameObject + " GUID:" + netId); } + if (LogFilter.logDebug) { Debug.Log("OnStartServer " + gameObject + " GUID:" + netId); } NetworkServer.SetLocalObjectOnServer(netId, gameObject); for (int i = 0; i < m_NetworkBehaviours.Length; i++) @@ -318,7 +318,7 @@ internal void OnStartClient() m_IsClient = true; CacheBehaviours(); - if (LogFilter.logDev) { Debug.Log("OnStartClient " + gameObject + " GUID:" + netId + " localPlayerAuthority:" + localPlayerAuthority); } + if (LogFilter.logDebug) { Debug.Log("OnStartClient " + gameObject + " GUID:" + netId + " localPlayerAuthority:" + localPlayerAuthority); } for (int i = 0; i < m_NetworkBehaviours.Length; i++) { NetworkBehaviour comp = m_NetworkBehaviours[i]; @@ -336,7 +336,7 @@ internal void OnStartClient() internal void OnStartAuthority() { - if (m_NetworkBehaviours == null && LogFilter.logError) + if (m_NetworkBehaviours == null) { Debug.LogError("Network object " + name + " not initialized properly. Do you have more than one NetworkIdentity in the same object? Did you forget to spawn this object with NetworkServer?", this); return; @@ -434,7 +434,7 @@ internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, boo // be useful for debugging. if (bytes.Length > Transport.MaxPacketSize) { - if (LogFilter.logWarn) { Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp); } + Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp); } // serialize length,data into the real writer, untouched by user code @@ -448,7 +448,7 @@ internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter { if (components.Length > 64) { - if (LogFilter.logError) Debug.LogError("Only 64 NetworkBehaviour components are allowed for NetworkIdentity: " + name + " because of the dirtyComponentMask"); + Debug.LogError("Only 64 NetworkBehaviour components are allowed for NetworkIdentity: " + name + " because of the dirtyComponentMask"); return false; } @@ -546,7 +546,7 @@ internal void HandleClientAuthority(bool authority) { if (!localPlayerAuthority) { - if (LogFilter.logError) { Debug.LogError("HandleClientAuthority " + gameObject + " does not have localPlayerAuthority"); } + Debug.LogError("HandleClientAuthority " + gameObject + " does not have localPlayerAuthority"); return; } @@ -563,7 +563,7 @@ bool GetInvokeComponent(int cmdHash, Type invokeClass, out NetworkBehaviour invo if (invokeComponent == null) { string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logError) { Debug.LogError("Found no behaviour for incoming [" + errorCmdName + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); } + Debug.LogError("Found no behaviour for incoming [" + errorCmdName + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); return false; } return true; @@ -578,7 +578,7 @@ internal void HandleSyncEvent(int cmdHash, NetworkReader reader) if (gameObject == null) { string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logWarn) { Debug.LogWarning("SyncEvent [" + errorCmdName + "] received for deleted object [netId=" + netId + "]"); } + Debug.LogWarning("SyncEvent [" + errorCmdName + "] received for deleted object [netId=" + netId + "]"); return; } @@ -590,7 +590,7 @@ internal void HandleSyncEvent(int cmdHash, NetworkReader reader) { // We don't get a valid lookup of the command name when it doesn't exist... string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logError) { Debug.LogError("Found no receiver for incoming [" + errorCmdName + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); } + Debug.LogError("Found no receiver for incoming [" + errorCmdName + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); return; } @@ -599,7 +599,7 @@ internal void HandleSyncEvent(int cmdHash, NetworkReader reader) if (!GetInvokeComponent(cmdHash, invokeClass, out invokeComponent)) { string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logWarn) { Debug.LogWarning("SyncEvent [" + errorCmdName + "] handler not found [netId=" + netId + "]"); } + Debug.LogWarning("SyncEvent [" + errorCmdName + "] handler not found [netId=" + netId + "]"); return; } @@ -615,7 +615,7 @@ internal void HandleCommand(int cmdHash, NetworkReader reader) if (gameObject == null) { string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logWarn) { Debug.LogWarning("Command [" + errorCmdName + "] received for deleted object [netId=" + netId + "]"); } + Debug.LogWarning("Command [" + errorCmdName + "] received for deleted object [netId=" + netId + "]"); return; } @@ -627,7 +627,7 @@ internal void HandleCommand(int cmdHash, NetworkReader reader) { // We don't get a valid lookup of the command name when it doesn't exist... string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logError) { Debug.LogError("Found no receiver for incoming [" + errorCmdName + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); } + Debug.LogError("Found no receiver for incoming [" + errorCmdName + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); return; } @@ -636,7 +636,7 @@ internal void HandleCommand(int cmdHash, NetworkReader reader) if (!GetInvokeComponent(cmdHash, invokeClass, out invokeComponent)) { string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logWarn) { Debug.LogWarning("Command [" + errorCmdName + "] handler not found [netId=" + netId + "]"); } + Debug.LogWarning("Command [" + errorCmdName + "] handler not found [netId=" + netId + "]"); return; } @@ -652,7 +652,7 @@ internal void HandleRPC(int cmdHash, NetworkReader reader) if (gameObject == null) { string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logWarn) { Debug.LogWarning("ClientRpc [" + errorCmdName + "] received for deleted object [netId=" + netId + "]"); } + Debug.LogWarning("ClientRpc [" + errorCmdName + "] received for deleted object [netId=" + netId + "]"); return; } @@ -664,7 +664,7 @@ internal void HandleRPC(int cmdHash, NetworkReader reader) { // We don't get a valid lookup of the command name when it doesn't exist... string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logError) { Debug.LogError("Found no receiver for incoming [" + errorCmdName + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); } + Debug.LogError("Found no receiver for incoming [" + errorCmdName + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); return; } @@ -673,7 +673,7 @@ internal void HandleRPC(int cmdHash, NetworkReader reader) if (!GetInvokeComponent(cmdHash, invokeClass, out invokeComponent)) { string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); - if (LogFilter.logWarn) { Debug.LogWarning("ClientRpc [" + errorCmdName + "] handler not found [netId=" + netId + "]"); } + Debug.LogWarning("ClientRpc [" + errorCmdName + "] handler not found [netId=" + netId + "]"); return; } @@ -767,7 +767,7 @@ internal void AddObserver(NetworkConnection conn) { if (m_Observers == null) { - if (LogFilter.logError) { Debug.LogError("AddObserver for " + gameObject + " observer list is null"); } + Debug.LogError("AddObserver for " + gameObject + " observer list is null"); return; } @@ -778,7 +778,7 @@ internal void AddObserver(NetworkConnection conn) return; } - if (LogFilter.logDev) { Debug.Log("Added observer " + conn.address + " added for " + gameObject); } + if (LogFilter.logDebug) { Debug.Log("Added observer " + conn.address + " added for " + gameObject); } m_Observers[conn.connectionId] = conn; conn.AddToVisList(this); @@ -838,7 +838,7 @@ public void RebuildObservers(bool initialize) if (!conn.isReady) { - if (LogFilter.logWarn) { Debug.LogWarning("Observer is not ready for " + gameObject + " " + conn); } + Debug.LogWarning("Observer is not ready for " + gameObject + " " + conn); continue; } @@ -881,25 +881,25 @@ public bool RemoveClientAuthority(NetworkConnection conn) { if (!isServer) { - if (LogFilter.logError) { Debug.LogError("RemoveClientAuthority can only be call on the server for spawned objects."); } + Debug.LogError("RemoveClientAuthority can only be call on the server for spawned objects."); return false; } if (connectionToClient != null) { - if (LogFilter.logError) { Debug.LogError("RemoveClientAuthority cannot remove authority for a player object"); } + Debug.LogError("RemoveClientAuthority cannot remove authority for a player object"); return false; } if (m_ClientAuthorityOwner == null) { - if (LogFilter.logError) { Debug.LogError("RemoveClientAuthority for " + gameObject + " has no clientAuthority owner."); } + Debug.LogError("RemoveClientAuthority for " + gameObject + " has no clientAuthority owner."); return false; } if (m_ClientAuthorityOwner != conn) { - if (LogFilter.logError) { Debug.LogError("RemoveClientAuthority for " + gameObject + " has different owner."); } + Debug.LogError("RemoveClientAuthority for " + gameObject + " has different owner."); return false; } @@ -926,24 +926,24 @@ public bool AssignClientAuthority(NetworkConnection conn) { if (!isServer) { - if (LogFilter.logError) { Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects."); } + Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects."); return false; } if (!localPlayerAuthority) { - if (LogFilter.logError) { Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set."); } + Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set."); return false; } if (m_ClientAuthorityOwner != null && conn != m_ClientAuthorityOwner) { - if (LogFilter.logError) { Debug.LogError("AssignClientAuthority for " + gameObject + " already has an owner. Use RemoveClientAuthority() first."); } + Debug.LogError("AssignClientAuthority for " + gameObject + " already has an owner. Use RemoveClientAuthority() first."); return false; } if (conn == null) { - if (LogFilter.logError) { Debug.LogError("AssignClientAuthority for " + gameObject + " owner cannot be null. Use RemoveClientAuthority() instead."); } + Debug.LogError("AssignClientAuthority for " + gameObject + " owner cannot be null. Use RemoveClientAuthority() instead."); return false; } diff --git a/Mirror/Runtime/NetworkManager.cs b/Mirror/Runtime/NetworkManager.cs index 857471f56..ff6c0e02f 100644 --- a/Mirror/Runtime/NetworkManager.cs +++ b/Mirror/Runtime/NetworkManager.cs @@ -22,7 +22,7 @@ public class NetworkManager : MonoBehaviour [SerializeField] string m_NetworkAddress = "localhost"; [SerializeField] bool m_DontDestroyOnLoad = true; [SerializeField] bool m_RunInBackground = true; - [SerializeField] LogFilter.FilterLevel m_LogLevel = LogFilter.FilterLevel.Info; + [SerializeField] bool m_ShowDebugMessages; [SerializeField] GameObject m_PlayerPrefab; [SerializeField] bool m_AutoCreatePlayer = true; [SerializeField] PlayerSpawnMethod m_PlayerSpawnMethod; @@ -43,7 +43,7 @@ public class NetworkManager : MonoBehaviour public string networkAddress { get { return m_NetworkAddress; } set { m_NetworkAddress = value; } } public bool dontDestroyOnLoad { get { return m_DontDestroyOnLoad; } set { m_DontDestroyOnLoad = value; } } public bool runInBackground { get { return m_RunInBackground; } set { m_RunInBackground = value; } } - public LogFilter.FilterLevel logLevel { get { return m_LogLevel; } set { m_LogLevel = value; LogFilter.currentLogLevel = value; } } + public bool showDebugMessages { get { return m_ShowDebugMessages; } set { m_ShowDebugMessages = value; LogFilter.Debug = value; } } public GameObject playerPrefab { get { return m_PlayerPrefab; } set { m_PlayerPrefab = value; } } public bool autoCreatePlayer { get { return m_AutoCreatePlayer; } set { m_AutoCreatePlayer = value; } } public PlayerSpawnMethod playerSpawnMethod { get { return m_PlayerSpawnMethod; } set { m_PlayerSpawnMethod = value; } } @@ -108,26 +108,23 @@ void InitializeSingleton() } // do this early - if (logLevel != LogFilter.FilterLevel.SetInScripting) - { - LogFilter.currentLogLevel = logLevel; - } + LogFilter.Debug = showDebugMessages; if (m_DontDestroyOnLoad) { if (singleton != null) { - if (LogFilter.logDev) { Debug.Log("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used."); } + if (LogFilter.Debug) { Debug.Log("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used."); } Destroy(gameObject); return; } - if (LogFilter.logDev) { Debug.Log("NetworkManager created singleton (DontDestroyOnLoad)"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager created singleton (DontDestroyOnLoad)"); } singleton = this; if (Application.isPlaying) DontDestroyOnLoad(gameObject); } else { - if (LogFilter.logDev) { Debug.Log("NetworkManager created singleton (ForScene)"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager created singleton (ForScene)"); } singleton = this; } @@ -181,7 +178,7 @@ protected void OnValidate() if (m_PlayerPrefab != null && m_PlayerPrefab.GetComponent() == null) { - if (LogFilter.logError) { Debug.LogError("NetworkManager - playerPrefab must have a NetworkIdentity."); } + Debug.LogError("NetworkManager - playerPrefab must have a NetworkIdentity."); m_PlayerPrefab = null; } } @@ -209,7 +206,7 @@ public bool StartServer() { if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort, m_MaxConnections)) { - if (LogFilter.logError) { Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed."); } + Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed."); return false; } } @@ -217,7 +214,7 @@ public bool StartServer() { if (!NetworkServer.Listen(m_NetworkPort, m_MaxConnections)) { - if (LogFilter.logError) { Debug.LogError("StartServer listen failed."); } + Debug.LogError("StartServer listen failed."); return false; } } @@ -235,7 +232,7 @@ public bool StartServer() // this must be after Listen(), since that registers the default message handlers RegisterServerMessages(); - if (LogFilter.logDebug) { Debug.Log("NetworkManager StartServer port:" + m_NetworkPort); } + if (LogFilter.Debug) { Debug.Log("NetworkManager StartServer port:" + m_NetworkPort); } isNetworkActive = true; // Only change scene if the requested online scene is not blank, and is not already loaded @@ -289,10 +286,10 @@ public NetworkClient StartClient(int hostPort=0) if (string.IsNullOrEmpty(m_NetworkAddress)) { - if (LogFilter.logError) { Debug.LogError("Must set the Network Address field in the manager"); } + Debug.LogError("Must set the Network Address field in the manager"); return null; } - if (LogFilter.logDebug) { Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort); } + if (LogFilter.Debug) { Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort); } client.Connect(m_NetworkAddress, m_NetworkPort); @@ -315,7 +312,7 @@ public virtual NetworkClient StartHost() NetworkClient ConnectLocalClient() { - if (LogFilter.logDebug) { Debug.Log("NetworkManager StartHost port:" + m_NetworkPort); } + if (LogFilter.Debug) { Debug.Log("NetworkManager StartHost port:" + m_NetworkPort); } m_NetworkAddress = "localhost"; client = ClientScene.ConnectLocalServer(); RegisterClientMessages(client); @@ -337,7 +334,7 @@ public void StopServer() OnStopServer(); - if (LogFilter.logDebug) { Debug.Log("NetworkManager StopServer"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager StopServer"); } isNetworkActive = false; NetworkServer.Shutdown(); if (!string.IsNullOrEmpty(m_OfflineScene)) @@ -351,7 +348,7 @@ public void StopClient() { OnStopClient(); - if (LogFilter.logDebug) { Debug.Log("NetworkManager StopClient"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager StopClient"); } isNetworkActive = false; if (client != null) { @@ -373,11 +370,11 @@ public virtual void ServerChangeScene(string newSceneName) { if (string.IsNullOrEmpty(newSceneName)) { - if (LogFilter.logError) { Debug.LogError("ServerChangeScene empty scene name"); } + Debug.LogError("ServerChangeScene empty scene name"); return; } - if (LogFilter.logDebug) { Debug.Log("ServerChangeScene " + newSceneName); } + if (LogFilter.Debug) { Debug.Log("ServerChangeScene " + newSceneName); } NetworkServer.SetAllClientsNotReady(); networkSceneName = newSceneName; @@ -402,11 +399,11 @@ internal void ClientChangeScene(string newSceneName, bool forceReload) { if (string.IsNullOrEmpty(newSceneName)) { - if (LogFilter.logError) { Debug.LogError("ClientChangeScene empty scene name"); } + Debug.LogError("ClientChangeScene empty scene name"); return; } - if (LogFilter.logDebug) { Debug.Log("ClientChangeScene newSceneName:" + newSceneName + " networkSceneName:" + networkSceneName); } + if (LogFilter.Debug) { Debug.Log("ClientChangeScene newSceneName:" + newSceneName + " networkSceneName:" + networkSceneName); } if (newSceneName == networkSceneName) { @@ -422,7 +419,7 @@ internal void ClientChangeScene(string newSceneName, bool forceReload) // (client may be null after StopClient etc.) if (client != null) { - if (LogFilter.logDebug) { Debug.Log("ClientChangeScene: pausing handlers while scene is loading to avoid data loss after scene was loaded."); } + if (LogFilter.Debug) { Debug.Log("ClientChangeScene: pausing handlers while scene is loading to avoid data loss after scene was loaded."); } NetworkClient.pauseMessageHandling = true; } @@ -437,7 +434,7 @@ void FinishLoadScene() if (client != null) { // process queued messages that we received while loading the scene - if (LogFilter.logDebug) { Debug.Log("FinishLoadScene: resuming handlers after scene was loading."); } + if (LogFilter.Debug) { Debug.Log("FinishLoadScene: resuming handlers after scene was loading."); } NetworkClient.pauseMessageHandling = false; if (s_ClientReadyConnection != null) @@ -449,7 +446,7 @@ void FinishLoadScene() } else { - if (LogFilter.logDev) { Debug.Log("FinishLoadScene client is null"); } + if (LogFilter.Debug) { Debug.Log("FinishLoadScene client is null"); } } if (NetworkServer.active) @@ -473,7 +470,7 @@ internal static void UpdateScene() // This check below detects that problem and shuts down the transport layer to bring both systems back in sync. if (singleton == null && s_PendingSingleton != null && s_DomainReload) { - if (LogFilter.logWarn) { Debug.LogWarning("NetworkManager detected a script reload in the editor. This has caused the network to be shut down."); } + Debug.LogWarning("NetworkManager detected a script reload in the editor. This has caused the network to be shut down."); s_DomainReload = false; s_PendingSingleton.InitializeSingleton(); @@ -500,7 +497,7 @@ internal static void UpdateScene() if (!s_LoadingSceneAsync.isDone) return; - if (LogFilter.logDebug) { Debug.Log("ClientChangeScene done readyCon:" + s_ClientReadyConnection); } + if (LogFilter.Debug) { Debug.Log("ClientChangeScene done readyCon:" + s_ClientReadyConnection); } singleton.FinishLoadScene(); s_LoadingSceneAsync.allowSceneActivation = true; s_LoadingSceneAsync = null; @@ -509,18 +506,18 @@ internal static void UpdateScene() // protected so that inheriting classes' OnDestroy() can call base.OnDestroy() too protected void OnDestroy() { - if (LogFilter.logDev) { Debug.Log("NetworkManager destroyed"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager destroyed"); } } public static void RegisterStartPosition(Transform start) { - if (LogFilter.logDebug) { Debug.Log("RegisterStartPosition: (" + start.gameObject.name + ") " + start.position); } + if (LogFilter.Debug) { Debug.Log("RegisterStartPosition: (" + start.gameObject.name + ") " + start.position); } s_StartPositions.Add(start); } public static void UnRegisterStartPosition(Transform start) { - if (LogFilter.logDebug) { Debug.Log("UnRegisterStartPosition: (" + start.gameObject.name + ") " + start.position); } + if (LogFilter.Debug) { Debug.Log("UnRegisterStartPosition: (" + start.gameObject.name + ") " + start.position); } s_StartPositions.Remove(start); } @@ -547,7 +544,7 @@ public static void Shutdown() internal void OnServerConnectInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerConnectInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerConnectInternal"); } if (networkSceneName != "" && networkSceneName != m_OfflineScene) { @@ -560,19 +557,19 @@ internal void OnServerConnectInternal(NetworkMessage netMsg) internal void OnServerDisconnectInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerDisconnectInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerDisconnectInternal"); } OnServerDisconnect(netMsg.conn); } internal void OnServerReadyMessageInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerReadyMessageInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerReadyMessageInternal"); } OnServerReady(netMsg.conn); } internal void OnServerAddPlayerMessageInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerAddPlayerMessageInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerAddPlayerMessageInternal"); } AddPlayerMessage msg = new AddPlayerMessage(); netMsg.ReadMessage(msg); @@ -590,7 +587,7 @@ internal void OnServerAddPlayerMessageInternal(NetworkMessage netMsg) internal void OnServerRemovePlayerMessageInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerRemovePlayerMessageInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerRemovePlayerMessageInternal"); } RemovePlayerMessage msg = new RemovePlayerMessage(); netMsg.ReadMessage(msg); @@ -604,7 +601,7 @@ internal void OnServerRemovePlayerMessageInternal(NetworkMessage netMsg) internal void OnServerErrorInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerErrorInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerErrorInternal"); } ErrorMessage msg = new ErrorMessage(); netMsg.ReadMessage(msg); @@ -615,7 +612,7 @@ internal void OnServerErrorInternal(NetworkMessage netMsg) internal void OnClientConnectInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnClientConnectInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnClientConnectInternal"); } string loadedSceneName = SceneManager.GetSceneAt(0).name; if (string.IsNullOrEmpty(m_OnlineScene) || (m_OnlineScene == m_OfflineScene) || (loadedSceneName == m_OnlineScene)) @@ -632,7 +629,7 @@ internal void OnClientConnectInternal(NetworkMessage netMsg) internal void OnClientDisconnectInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnClientDisconnectInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnClientDisconnectInternal"); } if (!string.IsNullOrEmpty(m_OfflineScene)) { @@ -644,7 +641,7 @@ internal void OnClientDisconnectInternal(NetworkMessage netMsg) internal void OnClientNotReadyMessageInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnClientNotReadyMessageInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnClientNotReadyMessageInternal"); } ClientScene.SetNotReady(); OnClientNotReady(netMsg.conn); @@ -654,7 +651,7 @@ internal void OnClientNotReadyMessageInternal(NetworkMessage netMsg) internal void OnClientErrorInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnClientErrorInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnClientErrorInternal"); } ErrorMessage msg = new ErrorMessage(); netMsg.ReadMessage(msg); @@ -663,7 +660,7 @@ internal void OnClientErrorInternal(NetworkMessage netMsg) internal void OnClientSceneInternal(NetworkMessage netMsg) { - if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnClientSceneInternal"); } + if (LogFilter.Debug) { Debug.Log("NetworkManager:OnClientSceneInternal"); } string newSceneName = netMsg.reader.ReadString(); @@ -682,7 +679,7 @@ public virtual void OnServerConnect(NetworkConnection conn) public virtual void OnServerDisconnect(NetworkConnection conn) { NetworkServer.DestroyPlayerForConnection(conn); - if (LogFilter.logDebug) { Debug.Log("OnServerDisconnect: Client disconnected."); } + if (LogFilter.Debug) { Debug.Log("OnServerDisconnect: Client disconnected."); } } public virtual void OnServerReady(NetworkConnection conn) @@ -690,7 +687,7 @@ public virtual void OnServerReady(NetworkConnection conn) if (conn.playerController == null) { // this is now allowed (was not for a while) - if (LogFilter.logDebug) { Debug.Log("Ready with no player object"); } + if (LogFilter.Debug) { Debug.Log("Ready with no player object"); } } NetworkServer.SetClientReady(conn); } @@ -709,19 +706,19 @@ void OnServerAddPlayerInternal(NetworkConnection conn) { if (m_PlayerPrefab == null) { - if (LogFilter.logError) { Debug.LogError("The PlayerPrefab is empty on the NetworkManager. Please setup a PlayerPrefab object."); } + Debug.LogError("The PlayerPrefab is empty on the NetworkManager. Please setup a PlayerPrefab object."); return; } if (m_PlayerPrefab.GetComponent() == null) { - if (LogFilter.logError) { Debug.LogError("The PlayerPrefab does not have a NetworkIdentity. Please add a NetworkIdentity to the player prefab."); } + Debug.LogError("The PlayerPrefab does not have a NetworkIdentity. Please add a NetworkIdentity to the player prefab."); return; } if (conn.playerController != null) { - if (LogFilter.logError) { Debug.LogError("There is already a player for this connections."); } + Debug.LogError("There is already a player for this connections."); return; } diff --git a/Mirror/Runtime/NetworkReader.cs b/Mirror/Runtime/NetworkReader.cs index 7c9c62cbb..97573fa7d 100644 --- a/Mirror/Runtime/NetworkReader.cs +++ b/Mirror/Runtime/NetworkReader.cs @@ -208,7 +208,7 @@ public Transform ReadTransform() GameObject go = ClientScene.FindLocalObject(netId); if (go == null) { - if (LogFilter.logDebug) { Debug.Log("ReadTransform netId:" + netId); } + if (LogFilter.Debug) { Debug.Log("ReadTransform netId:" + netId); } return null; } @@ -234,7 +234,7 @@ public GameObject ReadGameObject() } if (go == null) { - if (LogFilter.logDebug) { Debug.Log("ReadGameObject netId:" + netId + "go: null"); } + if (LogFilter.Debug) { Debug.Log("ReadGameObject netId:" + netId + "go: null"); } } return go; @@ -258,7 +258,7 @@ public NetworkIdentity ReadNetworkIdentity() } if (go == null) { - if (LogFilter.logDebug) { Debug.Log("ReadNetworkIdentity netId:" + netId + "go: null"); } + if (LogFilter.Debug) { Debug.Log("ReadNetworkIdentity netId:" + netId + "go: null"); } return null; } diff --git a/Mirror/Runtime/NetworkScene.cs b/Mirror/Runtime/NetworkScene.cs index 95435f4df..609dbea79 100644 --- a/Mirror/Runtime/NetworkScene.cs +++ b/Mirror/Runtime/NetworkScene.cs @@ -31,7 +31,7 @@ internal void Shutdown() internal void SetLocalObject(uint netId, GameObject obj, bool isClient, bool isServer) { - if (LogFilter.logDev) { Debug.Log("SetLocalObject " + netId + " " + obj); } + if (LogFilter.Debug) { Debug.Log("SetLocalObject " + netId + " " + obj); } if (obj == null) { @@ -100,12 +100,12 @@ internal static void RegisterPrefab(GameObject prefab, Guid newAssetId) { view.SetDynamicAssetId(newAssetId); - if (LogFilter.logDebug) { Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + view.assetId); } + if (LogFilter.Debug) { Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + view.assetId); } s_GuidToPrefab[view.assetId] = prefab; } else { - if (LogFilter.logError) { Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component"); } + Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component"); } } @@ -114,22 +114,19 @@ internal static void RegisterPrefab(GameObject prefab) NetworkIdentity view = prefab.GetComponent(); if (view) { - if (LogFilter.logDebug) { Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + view.assetId); } + if (LogFilter.Debug) { Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + view.assetId); } s_GuidToPrefab[view.assetId] = prefab; var uvs = prefab.GetComponentsInChildren(); if (uvs.Length > 1) { - if (LogFilter.logWarn) - { - Debug.LogWarning("The prefab '" + prefab.name + - "' has multiple NetworkIdentity components. There can only be one NetworkIdentity on a prefab, and it must be on the root object."); - } + Debug.LogWarning("The prefab '" + prefab.name + + "' has multiple NetworkIdentity components. There can only be one NetworkIdentity on a prefab, and it must be on the root object."); } } else { - if (LogFilter.logError) { Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component"); } + Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component"); } } @@ -161,11 +158,11 @@ internal static void RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandl { if (spawnHandler == null || unspawnHandler == null) { - if (LogFilter.logError) { Debug.LogError("RegisterSpawnHandler custom spawn function null for " + assetId); } + Debug.LogError("RegisterSpawnHandler custom spawn function null for " + assetId); return; } - if (LogFilter.logDebug) { Debug.Log("RegisterSpawnHandler asset '" + assetId + "' " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName()); } + if (LogFilter.Debug) { Debug.Log("RegisterSpawnHandler asset '" + assetId + "' " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName()); } s_SpawnHandlers[assetId] = spawnHandler; s_UnspawnHandlers[assetId] = unspawnHandler; @@ -176,7 +173,7 @@ internal static void UnregisterPrefab(GameObject prefab) NetworkIdentity identity = prefab.GetComponent(); if (identity == null) { - if (LogFilter.logError) { Debug.LogError("Could not unregister '" + prefab.name + "' since it contains no NetworkIdentity component"); } + Debug.LogError("Could not unregister '" + prefab.name + "' since it contains no NetworkIdentity component"); return; } s_SpawnHandlers.Remove(identity.assetId); @@ -188,23 +185,23 @@ internal static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandle NetworkIdentity identity = prefab.GetComponent(); if (identity == null) { - if (LogFilter.logError) { Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component"); } + Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component"); return; } if (spawnHandler == null || unspawnHandler == null) { - if (LogFilter.logError) { Debug.LogError("RegisterPrefab custom spawn function null for " + identity.assetId); } + Debug.LogError("RegisterPrefab custom spawn function null for " + identity.assetId); return; } if (identity.assetId == Guid.Empty) { - if (LogFilter.logError) { Debug.LogError("RegisterPrefab game object " + prefab.name + " has no prefab. Use RegisterSpawnHandler() instead?"); } + Debug.LogError("RegisterPrefab game object " + prefab.name + " has no prefab. Use RegisterSpawnHandler() instead?"); return; } - if (LogFilter.logDebug) { Debug.Log("Registering custom prefab '" + prefab.name + "' as asset:" + identity.assetId + " " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName()); } + if (LogFilter.Debug) { Debug.Log("Registering custom prefab '" + prefab.name + "' as asset:" + identity.assetId + " " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName()); } s_SpawnHandlers[identity.assetId] = spawnHandler; s_UnspawnHandlers[identity.assetId] = unspawnHandler; diff --git a/Mirror/Runtime/NetworkServer.cs b/Mirror/Runtime/NetworkServer.cs index dce949f93..5345bbbbb 100644 --- a/Mirror/Runtime/NetworkServer.cs +++ b/Mirror/Runtime/NetworkServer.cs @@ -83,9 +83,7 @@ public static void Initialize() return; s_Initialized = true; - if (LogFilter.logDev) { Debug.Log("NetworkServer Created version " + Version.Current); } - - if (LogFilter.logDebug) { Debug.Log("NetworkServer initialize."); } + if (LogFilter.logDebug) { Debug.Log("NetworkServer Created version " + Version.Current); } } internal static void RegisterMessageHandlers() @@ -194,7 +192,7 @@ internal static void RemoveLocalClient(NetworkConnection localClientConnection) internal static void SetLocalObjectOnServer(uint netId, GameObject obj) { - if (LogFilter.logDev) { Debug.Log("SetLocalObjectOnServer " + netId + " " + obj); } + if (LogFilter.logDebug) { Debug.Log("SetLocalObjectOnServer " + netId + " " + obj); } s_NetworkScene.SetLocalObject(netId, obj, false, true); } @@ -210,7 +208,7 @@ internal static void ActivateLocalClientScene() { if (!uv.isClient) { - if (LogFilter.logDev) { Debug.Log("ActivateClientScene " + uv.netId + " " + uv.gameObject); } + if (LogFilter.logDebug) { Debug.Log("ActivateClientScene " + uv.netId + " " + uv.gameObject); } ClientScene.SetLocalObject(uv.netId, uv.gameObject); uv.OnStartClient(); @@ -222,7 +220,7 @@ internal static void ActivateLocalClientScene() // this is used for ObjectDestroy messages. static bool SendToObservers(GameObject contextObj, short msgType, MessageBase msg) { - if (LogFilter.logDev) { Debug.Log("Server.SendToObservers id:" + msgType); } + if (LogFilter.logDebug) { Debug.Log("Server.SendToObservers id:" + msgType); } NetworkIdentity uv = contextObj.GetComponent(); if (uv != null && uv.observers != null) @@ -239,7 +237,7 @@ static bool SendToObservers(GameObject contextObj, short msgType, MessageBase ms public static bool SendToAll(short msgType, MessageBase msg) { - if (LogFilter.logDev) { Debug.Log("Server.SendToAll id:" + msgType); } + if (LogFilter.logDebug) { Debug.Log("Server.SendToAll id:" + msgType); } bool result = true; foreach (KeyValuePair kvp in connections) @@ -252,7 +250,7 @@ public static bool SendToAll(short msgType, MessageBase msg) public static bool SendToReady(GameObject contextObj, short msgType, MessageBase msg) { - if (LogFilter.logDev) { Debug.Log("Server.SendToReady msgType:" + msgType); } + if (LogFilter.logDebug) { Debug.Log("Server.SendToReady msgType:" + msgType); } if (contextObj == null) { @@ -423,7 +421,7 @@ static void OnDisconnected(NetworkConnection conn) if (conn.playerController != null) { //NOTE: should there be default behaviour here to destroy the associated player? - if (LogFilter.logWarn) { Debug.LogWarning("Player not destroyed when connection disconnected."); } + Debug.LogWarning("Player not destroyed when connection disconnected."); } if (LogFilter.logDebug) { Debug.Log("Server lost client:" + conn.connectionId); } @@ -440,7 +438,7 @@ static void HandleData(int connectionId, byte[] data, byte error) } else { - if (LogFilter.logError) { Debug.LogError("HandleData Unknown connectionId:" + connectionId); } + Debug.LogError("HandleData Unknown connectionId:" + connectionId); } } @@ -451,7 +449,7 @@ static void OnData(NetworkConnection conn, byte[] data) static void GenerateConnectError(byte error) { - if (LogFilter.logError) { Debug.LogError("UNet Server Connect Error: " + error); } + Debug.LogError("UNet Server Connect Error: " + error); GenerateError(null, error); } @@ -459,14 +457,14 @@ static void GenerateConnectError(byte error) static void GenerateDataError(NetworkConnection conn, byte error) { NetworkError dataError = (NetworkError)error; - if (LogFilter.logError) { Debug.LogError("UNet Server Data Error: " + dataError); } + Debug.LogError("UNet Server Data Error: " + dataError); GenerateError(conn, error); } static void GenerateDisconnectError(NetworkConnection conn, byte error) { NetworkError disconnectError = (NetworkError)error; - if (LogFilter.logError) { Debug.LogError("UNet Server Disconnect Error: " + disconnectError + " conn:[" + conn + "]:" + conn.connectionId); } + Debug.LogError("UNet Server Disconnect Error: " + disconnectError + " conn:[" + conn + "]:" + conn.connectionId); GenerateError(conn, error); } */ @@ -536,7 +534,7 @@ public static void SendToClientOfPlayer(GameObject player, short msgType, Messag } } - if (LogFilter.logError) { Debug.LogError("Failed to send message to player object '" + player.name + ", not found in connection list"); } + Debug.LogError("Failed to send message to player object '" + player.name + ", not found in connection list"); } public static void SendToClient(int connectionId, short msgType, MessageBase msg) @@ -547,7 +545,7 @@ public static void SendToClient(int connectionId, short msgType, MessageBase msg conn.Send(msgType, msg); return; } - if (LogFilter.logError) { Debug.LogError("Failed to send message to connection ID '" + connectionId + ", not found in connection list"); } + Debug.LogError("Failed to send message to connection ID '" + connectionId + ", not found in connection list"); } public static bool ReplacePlayerForConnection(NetworkConnection conn, GameObject player, Guid assetId) @@ -585,7 +583,7 @@ internal static bool InternalAddPlayerForConnection(NetworkConnection conn, Game NetworkIdentity playerNetworkIdentity; if (!GetNetworkIdentity(playerGameObject, out playerNetworkIdentity)) { - if (LogFilter.logError) { Debug.Log("AddPlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + playerGameObject); } + Debug.Log("AddPlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + playerGameObject); return false; } playerNetworkIdentity.Reset(); @@ -593,7 +591,7 @@ internal static bool InternalAddPlayerForConnection(NetworkConnection conn, Game // cannot have a player object in "Add" version if (conn.playerController != null) { - if (LogFilter.logError) { Debug.Log("AddPlayer: player object already exists"); } + Debug.Log("AddPlayer: player object already exists"); return false; } @@ -621,12 +619,12 @@ internal static bool InternalAddPlayerForConnection(NetworkConnection conn, Game static bool SetupLocalPlayerForConnection(NetworkConnection conn, NetworkIdentity uv) { - if (LogFilter.logDev) { Debug.Log("NetworkServer SetupLocalPlayerForConnection netID:" + uv.netId); } + if (LogFilter.logDebug) { Debug.Log("NetworkServer SetupLocalPlayerForConnection netID:" + uv.netId); } var localConnection = conn as ULocalConnectionToClient; if (localConnection != null) { - if (LogFilter.logDev) { Debug.Log("NetworkServer AddPlayer handling ULocalConnectionToClient"); } + if (LogFilter.logDebug) { Debug.Log("NetworkServer AddPlayer handling ULocalConnectionToClient"); } // Spawn this player for other players, instead of SpawnObject: if (uv.netId == 0) @@ -671,12 +669,12 @@ internal static bool InternalReplacePlayerForConnection(NetworkConnection conn, NetworkIdentity playerNetworkIdentity; if (!GetNetworkIdentity(playerGameObject, out playerNetworkIdentity)) { - if (LogFilter.logError) { Debug.LogError("ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + playerGameObject); } + Debug.LogError("ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + playerGameObject); return false; } //NOTE: there can be an existing player - if (LogFilter.logDev) { Debug.Log("NetworkServer ReplacePlayer"); } + if (LogFilter.logDebug) { Debug.Log("NetworkServer ReplacePlayer"); } // is there already an owner that is a different object?? if (conn.playerController != null) @@ -692,7 +690,7 @@ internal static bool InternalReplacePlayerForConnection(NetworkConnection conn, //NOTE: DONT set connection ready. - if (LogFilter.logDev) { Debug.Log("NetworkServer ReplacePlayer setup local"); } + if (LogFilter.logDebug) { Debug.Log("NetworkServer ReplacePlayer setup local"); } if (SetupLocalPlayerForConnection(conn, playerNetworkIdentity)) { @@ -714,7 +712,7 @@ static bool GetNetworkIdentity(GameObject go, out NetworkIdentity view) view = go.GetComponent(); if (view == null) { - if (LogFilter.logError) { Debug.LogError("UNET failure. GameObject doesn't have NetworkIdentity."); } + Debug.LogError("UNET failure. GameObject doesn't have NetworkIdentity."); return false; } return true; @@ -746,7 +744,7 @@ internal static void SetClientReadyInternal(NetworkConnection conn) var localConnection = conn as ULocalConnectionToClient; if (localConnection != null) { - if (LogFilter.logDev) { Debug.Log("NetworkServer Ready handling ULocalConnectionToClient"); } + if (LogFilter.logDebug) { Debug.Log("NetworkServer Ready handling ULocalConnectionToClient"); } // Setup spawned objects for local player // Only handle the local objects for the first player (no need to redo it when doing more local players) @@ -764,7 +762,7 @@ internal static void SetClientReadyInternal(NetworkConnection conn) } if (!uv.isClient) { - if (LogFilter.logDev) { Debug.Log("LocalClient.SetSpawnObject calling OnStartClient"); } + if (LogFilter.logDebug) { Debug.Log("LocalClient.SetSpawnObject calling OnStartClient"); } uv.OnStartClient(); } } @@ -783,7 +781,7 @@ internal static void SetClientReadyInternal(NetworkConnection conn) { if (uv == null) { - if (LogFilter.logWarn) { Debug.LogWarning("Invalid object found in server local object list (null NetworkIdentity)."); } + Debug.LogWarning("Invalid object found in server local object list (null NetworkIdentity)."); continue; } if (!uv.gameObject.activeSelf) @@ -868,7 +866,7 @@ static void OnRemovePlayerMessage(NetworkMessage netMsg) } else { - if (LogFilter.logError) { Debug.LogError("Received remove player message but connection has no player"); } + Debug.LogError("Received remove player message but connection has no player"); } } @@ -880,14 +878,14 @@ static void OnCommandMessage(NetworkMessage netMsg) var cmdObject = FindLocalObject(message.netId); if (cmdObject == null) { - if (LogFilter.logWarn) { Debug.LogWarning("Instance not found when handling Command message [netId=" + message.netId + "]"); } + Debug.LogWarning("Instance not found when handling Command message [netId=" + message.netId + "]"); return; } var uv = cmdObject.GetComponent(); if (uv == null) { - if (LogFilter.logWarn) { Debug.LogWarning("NetworkIdentity deleted when handling Command message [netId=" + message.netId + "]"); } + Debug.LogWarning("NetworkIdentity deleted when handling Command message [netId=" + message.netId + "]"); return; } @@ -898,12 +896,12 @@ static void OnCommandMessage(NetworkMessage netMsg) { if (uv.clientAuthorityOwner != netMsg.conn) { - if (LogFilter.logWarn) { Debug.LogWarning("Command for object without authority [netId=" + message.netId + "]"); } + Debug.LogWarning("Command for object without authority [netId=" + message.netId + "]"); return; } } - if (LogFilter.logDev) { Debug.Log("OnCommandMessage for netId=" + message.netId + " conn=" + netMsg.conn); } + if (LogFilter.logDebug) { Debug.Log("OnCommandMessage for netId=" + message.netId + " conn=" + netMsg.conn); } uv.HandleCommand(message.cmdHash, new NetworkReader(message.payload)); } @@ -911,14 +909,14 @@ internal static void SpawnObject(GameObject obj) { if (!NetworkServer.active) { - if (LogFilter.logError) { Debug.LogError("SpawnObject for " + obj + ", NetworkServer is not active. Cannot spawn objects without an active server."); } + Debug.LogError("SpawnObject for " + obj + ", NetworkServer is not active. Cannot spawn objects without an active server."); return; } NetworkIdentity objNetworkIdentity; if (!GetNetworkIdentity(obj, out objNetworkIdentity)) { - if (LogFilter.logError) { Debug.LogError("SpawnObject " + obj + " has no NetworkIdentity. Please add a NetworkIdentity to " + obj); } + Debug.LogError("SpawnObject " + obj + " has no NetworkIdentity. Please add a NetworkIdentity to " + obj); return; } objNetworkIdentity.Reset(); @@ -1022,7 +1020,7 @@ static void UnSpawnObject(GameObject obj) { if (obj == null) { - if (LogFilter.logDev) { Debug.Log("NetworkServer UnspawnObject is null"); } + if (LogFilter.logDebug) { Debug.Log("NetworkServer UnspawnObject is null"); } return; } @@ -1041,7 +1039,7 @@ static void DestroyObject(GameObject obj) { if (obj == null) { - if (LogFilter.logDev) { Debug.Log("NetworkServer DestroyObject is null"); } + if (LogFilter.logDebug) { Debug.Log("NetworkServer DestroyObject is null"); } return; } @@ -1204,7 +1202,7 @@ internal static bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer) return true; } } - if (LogFilter.logError) { Debug.LogError("InvokeBytes: failed to unpack message:" + BitConverter.ToString(buffer)); } + Debug.LogError("InvokeBytes: failed to unpack message:" + BitConverter.ToString(buffer)); return false; } diff --git a/Mirror/Runtime/NetworkTime.cs b/Mirror/Runtime/NetworkTime.cs index 17bd1e711..f281e6622 100644 --- a/Mirror/Runtime/NetworkTime.cs +++ b/Mirror/Runtime/NetworkTime.cs @@ -4,7 +4,7 @@ namespace Mirror { // calculates synchronized time and rtt - public static class NetworkTime + public static class NetworkTime { // Date and time when the application started static readonly DateTime epoch = DateTime.Now; @@ -27,7 +27,7 @@ public static void Reset(int windowSize) internal static NetworkPingMessage GetPing() { - return new NetworkPingMessage(LocalTime()); + return new NetworkPingMessage(LocalTime()); } // executed at the server when we receive a ping message @@ -38,7 +38,7 @@ internal static void OnServerPing(NetworkMessage netMsg) var pingMsg = new NetworkPingMessage(); netMsg.ReadMessage(pingMsg); - if (LogFilter.logDev) { Debug.Log("OnPingServerMessage conn=" + netMsg.conn); } + if (LogFilter.Debug) { Debug.Log("OnPingServerMessage conn=" + netMsg.conn); } var pongMsg = new NetworkPongMessage { @@ -70,29 +70,29 @@ internal static void OnClientPong(NetworkMessage netMsg) // returns the same time in both client and server // time should be a double because after a while - // float loses too much accuracy if the server is up for more than + // float loses too much accuracy if the server is up for more than // a few days. I measured the accuracy of float and I got this: // for the same day, accuracy is better than 1 ms // after 1 day, accuracy goes down to 7 ms // after 10 days, accuracy is 61 ms // after 30 days , accuracy is 238 ms // after 60 days, accuracy is 454 ms - // in other words, if the server is running for 2 months, + // in other words, if the server is running for 2 months, // and you cast down to float, then the time will jump in 0.4s intervals. public static double time { - get + get { // Notice _offset is 0 at the server return LocalTime() - _offset.Value; } } - // measure volatility of time. + // measure volatility of time. // the higher the number, the less accurate the time is public static double timeVar { - get + get { return _offset.Var; } @@ -101,7 +101,7 @@ public static double timeVar // standard deviation of time public static double timeSd { - get + get { return Math.Sqrt(timeVar); } @@ -115,11 +115,11 @@ public static double offset } } - // how long does it take for a message to go + // how long does it take for a message to go // to the server and come back public static double rtt { - get + get { return _rtt.Value; } @@ -129,7 +129,7 @@ public static double rtt // the higher the number, the less accurate rtt is public static double rttVar { - get + get { return _rtt.Var; } diff --git a/Mirror/Runtime/NetworkTranformChild.cs b/Mirror/Runtime/NetworkTranformChild.cs index 3e3ae2d39..69c596693 100644 --- a/Mirror/Runtime/NetworkTranformChild.cs +++ b/Mirror/Runtime/NetworkTranformChild.cs @@ -60,7 +60,7 @@ void OnValidate() Transform parent = m_Target.parent; if (parent == null) { - if (LogFilter.logError) { Debug.LogError("NetworkTransformChild target cannot be the root transform."); } + Debug.LogError("NetworkTransformChild target cannot be the root transform."); m_Target = null; return; } @@ -72,7 +72,7 @@ void OnValidate() m_Root = parent.gameObject.GetComponent(); if (m_Root == null) { - if (LogFilter.logError) { Debug.LogError("NetworkTransformChild root must have NetworkTransform"); } + Debug.LogError("NetworkTransformChild root must have NetworkTransform"); m_Target = null; return; } @@ -93,7 +93,7 @@ void OnValidate() } if (m_ChildIndex == UInt32.MaxValue) { - if (LogFilter.logError) { Debug.LogError("NetworkTransformChild component must be a child in the same hierarchy"); } + Debug.LogError("NetworkTransformChild component must be a child in the same hierarchy"); m_Target = null; } } @@ -397,36 +397,36 @@ internal static void HandleChildTransform(NetworkMessage netMsg) GameObject foundObj = NetworkServer.FindLocalObject(message.netId); if (foundObj == null) { - if (LogFilter.logError) { Debug.LogError("Received NetworkTransformChild data for GameObject that doesn't exist"); } + Debug.LogError("Received NetworkTransformChild data for GameObject that doesn't exist"); return; } var children = foundObj.GetComponents(); if (children == null || children.Length == 0) { - if (LogFilter.logError) { Debug.LogError("HandleChildTransform no children"); } + Debug.LogError("HandleChildTransform no children"); return; } if (message.childIndex >= children.Length) { - if (LogFilter.logError) { Debug.LogError("HandleChildTransform childIndex invalid"); } + Debug.LogError("HandleChildTransform childIndex invalid"); return; } NetworkTransformChild foundSync = children[message.childIndex]; if (foundSync == null) { - if (LogFilter.logError) { Debug.LogError("HandleChildTransform null target"); } + Debug.LogError("HandleChildTransform null target"); return; } if (!foundSync.localPlayerAuthority) { - if (LogFilter.logError) { Debug.LogError("HandleChildTransform no localPlayerAuthority"); } + Debug.LogError("HandleChildTransform no localPlayerAuthority"); return; } if (!netMsg.conn.clientOwnedObjects.Contains(message.netId)) { - if (LogFilter.logWarn) { Debug.LogWarning("NetworkTransformChild netId:" + message.netId + " is not for a valid player"); } + Debug.LogWarning("NetworkTransformChild netId:" + message.netId + " is not for a valid player"); return; } diff --git a/Mirror/Runtime/NetworkTransform.cs b/Mirror/Runtime/NetworkTransform.cs index 3edbe55de..c5b26ee1b 100644 --- a/Mirror/Runtime/NetworkTransform.cs +++ b/Mirror/Runtime/NetworkTransform.cs @@ -236,7 +236,7 @@ void VerifySerializeComponentExists() m_CharacterController = m_CharacterController ?? GetComponent(); if (!m_CharacterController) { - throw new InvalidOperationException(string.Format("transformSyncMode set to {0} but no CharacterController component was found, did you call NetworkServer.Spawn on a prefab?", transformSyncMode)); + throw new InvalidOperationException(string.Format("transformSyncMode set to {0} but no CharacterController component was found, did you call NetworkServer.Spawn on a prefab?", transformSyncMode)); } break; @@ -1162,23 +1162,23 @@ public static void HandleTransform(NetworkMessage netMsg) GameObject foundObj = NetworkServer.FindLocalObject(message.netId); if (foundObj == null) { - if (LogFilter.logError) { Debug.LogError("Received NetworkTransform data for GameObject that doesn't exist"); } + Debug.LogError("Received NetworkTransform data for GameObject that doesn't exist"); return; } NetworkTransform foundSync = foundObj.GetComponent(); if (foundSync == null) { - if (LogFilter.logError) { Debug.LogError("HandleTransform null target"); } + Debug.LogError("HandleTransform null target"); return; } if (!foundSync.localPlayerAuthority) { - if (LogFilter.logError) { Debug.LogError("HandleTransform no localPlayerAuthority"); } + Debug.LogError("HandleTransform no localPlayerAuthority"); return; } if (netMsg.conn.clientOwnedObjects == null) { - if (LogFilter.logError) { Debug.LogError("HandleTransform object not owned by connection"); } + Debug.LogError("HandleTransform object not owned by connection"); return; } @@ -1206,7 +1206,7 @@ public static void HandleTransform(NetworkMessage netMsg) return; } - if (LogFilter.logWarn) { Debug.LogWarning("HandleTransform netId:" + message.netId + " is not for a valid player"); } + Debug.LogWarning("HandleTransform netId:" + message.netId + " is not for a valid player"); } // --------------------- Compression Helper functions ------------------------ diff --git a/Mirror/Runtime/NetworkWriter.cs b/Mirror/Runtime/NetworkWriter.cs index b2deaf044..9d3eaf1e4 100644 --- a/Mirror/Runtime/NetworkWriter.cs +++ b/Mirror/Runtime/NetworkWriter.cs @@ -74,13 +74,13 @@ public void WriteBytesAndSize(byte[] buffer, int offset, int count) } if (count > Transport.MaxPacketSize) { - if (LogFilter.logError) { Debug.LogError("NetworkWriter WriteBytesAndSize: size is too large (" + count + ") bytes. The maximum buffer size is " + Transport.MaxPacketSize + " bytes."); } + Debug.LogError("NetworkWriter WriteBytesAndSize: size is too large (" + count + ") bytes. The maximum buffer size is " + Transport.MaxPacketSize + " bytes."); return; } - + if (count < 0) { - if (LogFilter.logError) { Debug.LogError("NetworkWriter WriteBytesAndSize: size " + count + " cannot be negative"); } + Debug.LogError("NetworkWriter WriteBytesAndSize: size " + count + " cannot be negative"); return; } @@ -304,7 +304,7 @@ public void Write(Transform value) } else { - if (LogFilter.logWarn) { Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity"); } + Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity"); WritePackedUInt32(0); } } @@ -323,7 +323,7 @@ public void Write(GameObject value) } else { - if (LogFilter.logWarn) { Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity"); } + Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity"); WritePackedUInt32(0); } }