mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
LogFilter simplified: Warning/Error are shown all the time, Debug messages depend on LogFilter.logDebug (#73)
* LogFilter.logError removed. Errors are now always logged. * LogFilter.logWarning removed. Warnings are now always logged. * LogFilter levels replaced with a simple 'logDebug' boolean. NetworkManager uses 'ShowDebugMessages' instead of LogLevel now. * LogFilter.logDebug renamed to .Debug
This commit is contained in:
parent
d5713ec218
commit
59f6b1c3f1
@ -20,7 +20,7 @@ public class NetworkManagerEditor : Editor
|
|||||||
SerializedProperty m_ServerBindToIPProperty;
|
SerializedProperty m_ServerBindToIPProperty;
|
||||||
SerializedProperty m_ServerBindAddressProperty;
|
SerializedProperty m_ServerBindAddressProperty;
|
||||||
|
|
||||||
protected SerializedProperty m_LogLevelProperty;
|
protected SerializedProperty m_ShowDebugMessagesProperty;
|
||||||
|
|
||||||
SerializedProperty m_PlayerPrefabProperty;
|
SerializedProperty m_PlayerPrefabProperty;
|
||||||
SerializedProperty m_AutoCreatePlayerProperty;
|
SerializedProperty m_AutoCreatePlayerProperty;
|
||||||
@ -36,6 +36,7 @@ public class NetworkManagerEditor : Editor
|
|||||||
GUIContent m_OnlineSceneLabel;
|
GUIContent m_OnlineSceneLabel;
|
||||||
protected GUIContent m_DontDestroyOnLoadLabel;
|
protected GUIContent m_DontDestroyOnLoadLabel;
|
||||||
protected GUIContent m_RunInBackgroundLabel;
|
protected GUIContent m_RunInBackgroundLabel;
|
||||||
|
protected GUIContent m_ShowDebugMessagesLabel;
|
||||||
|
|
||||||
GUIContent m_MaxConnectionsLabel;
|
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_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_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_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_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.");
|
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
|
// top-level properties
|
||||||
m_DontDestroyOnLoadProperty = serializedObject.FindProperty("m_DontDestroyOnLoad");
|
m_DontDestroyOnLoadProperty = serializedObject.FindProperty("m_DontDestroyOnLoad");
|
||||||
m_RunInBackgroundProperty = serializedObject.FindProperty("m_RunInBackground");
|
m_RunInBackgroundProperty = serializedObject.FindProperty("m_RunInBackground");
|
||||||
m_LogLevelProperty = serializedObject.FindProperty("m_LogLevel");
|
m_ShowDebugMessagesProperty = serializedObject.FindProperty("m_ShowDebugMessages");
|
||||||
|
|
||||||
// network foldout properties
|
// network foldout properties
|
||||||
m_NetworkAddressProperty = serializedObject.FindProperty("m_NetworkAddress");
|
m_NetworkAddressProperty = serializedObject.FindProperty("m_NetworkAddress");
|
||||||
@ -160,7 +162,7 @@ protected SceneAsset GetSceneObject(string sceneObjectName)
|
|||||||
return AssetDatabase.LoadAssetAtPath(editorScene.path, typeof(SceneAsset)) as SceneAsset;
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,18 +296,18 @@ protected void ShowDerivedProperties(Type baseType, Type superType)
|
|||||||
|
|
||||||
public override void OnInspectorGUI()
|
public override void OnInspectorGUI()
|
||||||
{
|
{
|
||||||
if (m_DontDestroyOnLoadProperty == null || m_DontDestroyOnLoadLabel == null)
|
if (m_DontDestroyOnLoadProperty == null || m_DontDestroyOnLoadLabel == null || m_ShowDebugMessagesLabel == null)
|
||||||
m_Initialized = false;
|
m_Initialized = false;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
EditorGUILayout.PropertyField(m_DontDestroyOnLoadProperty, m_DontDestroyOnLoadLabel);
|
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();
|
ShowScenes();
|
||||||
@ -350,7 +352,7 @@ internal void DrawChild(Rect r, int index, bool isActive, bool isFocused)
|
|||||||
{
|
{
|
||||||
if (newGameObject != null && !newGameObject.GetComponent<NetworkIdentity>())
|
if (newGameObject != null && !newGameObject.GetComponent<NetworkIdentity>())
|
||||||
{
|
{
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
prefab.objectReferenceValue = newGameObject;
|
prefab.objectReferenceValue = newGameObject;
|
||||||
|
@ -149,7 +149,7 @@ public static void OnPostProcessScene()
|
|||||||
|
|
||||||
uv.gameObject.SetActive(false);
|
uv.gameObject.SetActive(false);
|
||||||
uv.ForceSceneId(nextSceneId++);
|
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
|
// saftey check for prefabs with more than one NetworkIdentity
|
||||||
var prefabGO = PrefabUtility.GetPrefabParent(uv.gameObject) as GameObject;
|
var prefabGO = PrefabUtility.GetPrefabParent(uv.gameObject) as GameObject;
|
||||||
|
@ -42,7 +42,7 @@ public void Init()
|
|||||||
m_Target = serializedObject.FindProperty("m_Target");
|
m_Target = serializedObject.FindProperty("m_Target");
|
||||||
if (sync.GetComponent<NetworkTransform>() == null)
|
if (sync.GetComponent<NetworkTransform>() == 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;
|
m_Target.objectReferenceValue = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ protected void ShowControls()
|
|||||||
{
|
{
|
||||||
if (sync.GetComponent<NetworkTransform>() == null)
|
if (sync.GetComponent<NetworkTransform>() == 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;
|
m_Target.objectReferenceValue = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,14 +48,14 @@ internal static void Shutdown()
|
|||||||
// this is called from message handler for Owner message
|
// this is called from message handler for Owner message
|
||||||
internal static void InternalAddPlayer(NetworkIdentity view)
|
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.
|
// 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
|
// But, the player structures are not cleaned up, we'll just replace the old player
|
||||||
s_LocalPlayer = view;
|
s_LocalPlayer = view;
|
||||||
if (s_ReadyConnection == null)
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -87,17 +87,17 @@ public static bool AddPlayer(NetworkConnection readyConn, MessageBase extraMessa
|
|||||||
|
|
||||||
if (!s_IsReady)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_ReadyConnection.playerController != null)
|
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;
|
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();
|
AddPlayerMessage msg = new AddPlayerMessage();
|
||||||
if (extraMessage != null)
|
if (extraMessage != null)
|
||||||
@ -112,7 +112,7 @@ public static bool AddPlayer(NetworkConnection readyConn, MessageBase extraMessa
|
|||||||
|
|
||||||
public static bool RemovePlayer()
|
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)
|
if (s_ReadyConnection.playerController != null)
|
||||||
{
|
{
|
||||||
@ -132,11 +132,11 @@ public static bool Ready(NetworkConnection conn)
|
|||||||
{
|
{
|
||||||
if (s_IsReady)
|
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;
|
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)
|
if (conn != null)
|
||||||
{
|
{
|
||||||
@ -147,7 +147,7 @@ public static bool Ready(NetworkConnection conn)
|
|||||||
s_ReadyConnection.isReady = true;
|
s_ReadyConnection.isReady = true;
|
||||||
return 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ internal static void PrepareToSpawnSceneObjects()
|
|||||||
uv.sceneId != 0)
|
uv.sceneId != 0)
|
||||||
{
|
{
|
||||||
s_SpawnableObjects[uv.sceneId] = uv;
|
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 (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;
|
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;
|
NetworkIdentity localNetworkIdentity;
|
||||||
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out 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))
|
if (NetworkScene.GetPrefab(msg.assetId, out prefab))
|
||||||
{
|
{
|
||||||
var obj = (GameObject)Object.Instantiate(prefab, msg.position, msg.rotation);
|
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 + "]");
|
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<NetworkIdentity>();
|
localNetworkIdentity = obj.GetComponent<NetworkIdentity>();
|
||||||
if (localNetworkIdentity == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
localNetworkIdentity.Reset();
|
localNetworkIdentity.Reset();
|
||||||
@ -375,13 +375,13 @@ static void OnSpawnPrefab(NetworkMessage netMsg)
|
|||||||
GameObject obj = handler(msg.position, msg.assetId);
|
GameObject obj = handler(msg.position, msg.assetId);
|
||||||
if (obj == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
localNetworkIdentity = obj.GetComponent<NetworkIdentity>();
|
localNetworkIdentity = obj.GetComponent<NetworkIdentity>();
|
||||||
if (localNetworkIdentity == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
localNetworkIdentity.Reset();
|
localNetworkIdentity.Reset();
|
||||||
@ -390,7 +390,7 @@ static void OnSpawnPrefab(NetworkMessage netMsg)
|
|||||||
}
|
}
|
||||||
else
|
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();
|
SpawnSceneObjectMessage msg = new SpawnSceneObjectMessage();
|
||||||
netMsg.ReadMessage(msg);
|
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;
|
NetworkIdentity localNetworkIdentity;
|
||||||
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localNetworkIdentity))
|
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localNetworkIdentity))
|
||||||
@ -413,17 +413,14 @@ static void OnSpawnSceneObject(NetworkMessage netMsg)
|
|||||||
NetworkIdentity spawnedId = SpawnSceneObject(msg.sceneId);
|
NetworkIdentity spawnedId = SpawnSceneObject(msg.sceneId);
|
||||||
if (spawnedId == null)
|
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
|
||||||
Debug.LogError("Spawn scene object not found for " + msg.sceneId + " SpawnableObjects.Count=" + s_SpawnableObjects.Count);
|
foreach (var kvp in s_SpawnableObjects)
|
||||||
// dump the whole spawnable objects dict for easier debugging
|
Debug.Log("Spawnable: SceneId=" + kvp.Key + " name=" + kvp.Value.name);
|
||||||
foreach (var kvp in s_SpawnableObjects)
|
|
||||||
Debug.Log("Spawnable: SceneId=" + kvp.Key + " name=" + kvp.Value.name);
|
|
||||||
}
|
|
||||||
return;
|
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();
|
spawnedId.Reset();
|
||||||
ApplySpawnPayload(spawnedId, msg.position, msg.payload, msg.netId, spawnedId.gameObject);
|
ApplySpawnPayload(spawnedId, msg.position, msg.payload, msg.netId, spawnedId.gameObject);
|
||||||
}
|
}
|
||||||
@ -432,7 +429,7 @@ static void OnObjectSpawnFinished(NetworkMessage netMsg)
|
|||||||
{
|
{
|
||||||
ObjectSpawnFinishedMessage msg = new ObjectSpawnFinishedMessage();
|
ObjectSpawnFinishedMessage msg = new ObjectSpawnFinishedMessage();
|
||||||
netMsg.ReadMessage(msg);
|
netMsg.ReadMessage(msg);
|
||||||
if (LogFilter.logDebug) { Debug.Log("SpawnFinished:" + msg.state); }
|
if (LogFilter.Debug) { Debug.Log("SpawnFinished:" + msg.state); }
|
||||||
|
|
||||||
if (msg.state == 0)
|
if (msg.state == 0)
|
||||||
{
|
{
|
||||||
@ -456,7 +453,7 @@ static void OnObjectDestroy(NetworkMessage netMsg)
|
|||||||
{
|
{
|
||||||
ObjectDestroyMessage msg = new ObjectDestroyMessage();
|
ObjectDestroyMessage msg = new ObjectDestroyMessage();
|
||||||
netMsg.ReadMessage(msg);
|
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;
|
NetworkIdentity localObject;
|
||||||
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localObject))
|
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localObject))
|
||||||
@ -482,7 +479,7 @@ static void OnObjectDestroy(NetworkMessage netMsg)
|
|||||||
}
|
}
|
||||||
else
|
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();
|
ObjectDestroyMessage msg = new ObjectDestroyMessage();
|
||||||
netMsg.ReadMessage(msg);
|
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);
|
s_NetworkScene.RemoveLocalObject(msg.netId);
|
||||||
}
|
}
|
||||||
@ -499,7 +496,7 @@ static void OnLocalClientObjectHide(NetworkMessage netMsg)
|
|||||||
{
|
{
|
||||||
ObjectDestroyMessage msg = new ObjectDestroyMessage();
|
ObjectDestroyMessage msg = new ObjectDestroyMessage();
|
||||||
netMsg.ReadMessage(msg);
|
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;
|
NetworkIdentity localObject;
|
||||||
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localObject))
|
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localObject))
|
||||||
@ -536,7 +533,7 @@ static void OnUpdateVarsMessage(NetworkMessage netMsg)
|
|||||||
{
|
{
|
||||||
UpdateVarsMessage message = netMsg.ReadMessage<UpdateVarsMessage>();
|
UpdateVarsMessage message = netMsg.ReadMessage<UpdateVarsMessage>();
|
||||||
|
|
||||||
if (LogFilter.logDev) { Debug.Log("ClientScene::OnUpdateVarsMessage " + message.netId); }
|
if (LogFilter.Debug) { Debug.Log("ClientScene::OnUpdateVarsMessage " + message.netId); }
|
||||||
|
|
||||||
NetworkIdentity localObject;
|
NetworkIdentity localObject;
|
||||||
if (s_NetworkScene.GetNetworkIdentity(message.netId, out localObject))
|
if (s_NetworkScene.GetNetworkIdentity(message.netId, out localObject))
|
||||||
@ -545,7 +542,7 @@ static void OnUpdateVarsMessage(NetworkMessage netMsg)
|
|||||||
}
|
}
|
||||||
else
|
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<RpcMessage>();
|
RpcMessage message = netMsg.ReadMessage<RpcMessage>();
|
||||||
|
|
||||||
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;
|
NetworkIdentity uv;
|
||||||
if (s_NetworkScene.GetNetworkIdentity(message.netId, out uv))
|
if (s_NetworkScene.GetNetworkIdentity(message.netId, out uv))
|
||||||
@ -562,11 +559,8 @@ static void OnRPCMessage(NetworkMessage netMsg)
|
|||||||
}
|
}
|
||||||
else
|
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<SyncEventMessage>();
|
SyncEventMessage message = netMsg.ReadMessage<SyncEventMessage>();
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("ClientScene::OnSyncEventMessage " + message.netId); }
|
if (LogFilter.Debug) { Debug.Log("ClientScene::OnSyncEventMessage " + message.netId); }
|
||||||
|
|
||||||
NetworkIdentity uv;
|
NetworkIdentity uv;
|
||||||
if (s_NetworkScene.GetNetworkIdentity(message.netId, out uv))
|
if (s_NetworkScene.GetNetworkIdentity(message.netId, out uv))
|
||||||
@ -583,7 +577,7 @@ static void OnSyncEventMessage(NetworkMessage netMsg)
|
|||||||
}
|
}
|
||||||
else
|
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();
|
ClientAuthorityMessage msg = new ClientAuthorityMessage();
|
||||||
netMsg.ReadMessage(msg);
|
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;
|
NetworkIdentity uv;
|
||||||
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out uv))
|
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out uv))
|
||||||
@ -607,7 +601,7 @@ static void OnOwnerMessage(NetworkMessage netMsg)
|
|||||||
OwnerMessage msg = new OwnerMessage();
|
OwnerMessage msg = new OwnerMessage();
|
||||||
netMsg.ReadMessage(msg);
|
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??
|
// is there already an owner that is a different object??
|
||||||
if (netMsg.conn.playerController != null)
|
if (netMsg.conn.playerController != null)
|
||||||
@ -643,10 +637,10 @@ static void CheckForOwner(NetworkIdentity uv)
|
|||||||
uv.SetConnectionToServer(s_ReadyConnection);
|
uv.SetConnectionToServer(s_ReadyConnection);
|
||||||
uv.SetLocalPlayer();
|
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 (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;
|
return;
|
||||||
}
|
}
|
||||||
InternalAddPlayer(uv);
|
InternalAddPlayer(uv);
|
||||||
|
@ -53,7 +53,7 @@ internal override void Update()
|
|||||||
// Called by the server to set the LocalClient's LocalPlayer object during NetworkServer.AddPlayer()
|
// Called by the server to set the LocalClient's LocalPlayer object during NetworkServer.AddPlayer()
|
||||||
internal void AddLocalPlayer(NetworkIdentity localPlayer)
|
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.isReady = true;
|
||||||
m_Connection.SetPlayerController(localPlayer);
|
m_Connection.SetPlayerController(localPlayer);
|
||||||
NetworkIdentity uv = localPlayer;
|
NetworkIdentity uv = localPlayer;
|
||||||
@ -121,7 +121,7 @@ internal void InvokeBytesOnClient(byte[] buffer)
|
|||||||
{
|
{
|
||||||
PostInternalMessage((short)msgType, content);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ protected override bool SendBytes(byte[] bytes)
|
|||||||
{
|
{
|
||||||
if (bytes.Length == 0)
|
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 false;
|
||||||
}
|
}
|
||||||
return NetworkServer.InvokeBytes(this, bytes);
|
return NetworkServer.InvokeBytes(this, bytes);
|
||||||
|
@ -5,23 +5,6 @@ namespace Mirror
|
|||||||
{
|
{
|
||||||
public static class LogFilter
|
public static class LogFilter
|
||||||
{
|
{
|
||||||
// this only exists for inspector UI?!
|
public static bool Debug = false;
|
||||||
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; } }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ internal static void OnAnimationServerMessage(NetworkMessage netMsg)
|
|||||||
{
|
{
|
||||||
AnimationMessage msg = new AnimationMessage();
|
AnimationMessage msg = new AnimationMessage();
|
||||||
netMsg.ReadMessage(msg);
|
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);
|
GameObject go = NetworkServer.FindLocalObject(msg.netId);
|
||||||
if (go == null)
|
if (go == null)
|
||||||
@ -390,7 +390,7 @@ internal static void OnAnimationParametersServerMessage(NetworkMessage netMsg)
|
|||||||
AnimationParametersMessage msg = new AnimationParametersMessage();
|
AnimationParametersMessage msg = new AnimationParametersMessage();
|
||||||
netMsg.ReadMessage(msg);
|
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);
|
GameObject go = NetworkServer.FindLocalObject(msg.netId);
|
||||||
if (go == null)
|
if (go == null)
|
||||||
@ -410,7 +410,7 @@ internal static void OnAnimationTriggerServerMessage(NetworkMessage netMsg)
|
|||||||
{
|
{
|
||||||
AnimationTriggerMessage msg = new AnimationTriggerMessage();
|
AnimationTriggerMessage msg = new AnimationTriggerMessage();
|
||||||
netMsg.ReadMessage(msg);
|
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);
|
GameObject go = NetworkServer.FindLocalObject(msg.netId);
|
||||||
if (go == null)
|
if (go == null)
|
||||||
|
@ -31,7 +31,7 @@ public class NetworkBehaviour : MonoBehaviour
|
|||||||
|
|
||||||
// objects that can synchronize themselves, such as synclists
|
// objects that can synchronize themselves, such as synclists
|
||||||
protected readonly List<SyncObject> m_SyncObjects = new List<SyncObject>();
|
protected readonly List<SyncObject> m_SyncObjects = new List<SyncObject>();
|
||||||
|
|
||||||
const float k_DefaultSendInterval = 0.1f;
|
const float k_DefaultSendInterval = 0.1f;
|
||||||
|
|
||||||
NetworkIdentity m_MyView;
|
NetworkIdentity m_MyView;
|
||||||
@ -42,7 +42,7 @@ NetworkIdentity myView
|
|||||||
m_MyView = m_MyView ?? GetComponent<NetworkIdentity>();
|
m_MyView = m_MyView ?? GetComponent<NetworkIdentity>();
|
||||||
if (m_MyView == null)
|
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;
|
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.
|
// local players can always send commands, regardless of authority, other objects must have authority.
|
||||||
if (!(isLocalPlayer || hasAuthority))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ClientScene.readyConnection == null)
|
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;
|
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.
|
// This cannot use NetworkServer.active, as that is not specific to this object.
|
||||||
if (!isServer)
|
if (!isServer)
|
||||||
{
|
{
|
||||||
if (LogFilter.logWarn) { Debug.LogWarning("ClientRpc call on un-spawned object"); }
|
Debug.LogWarning("ClientRpc call on un-spawned object");
|
||||||
return;
|
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.
|
// This cannot use NetworkServer.active, as that is not specific to this object.
|
||||||
if (!isServer)
|
if (!isServer)
|
||||||
{
|
{
|
||||||
if (LogFilter.logWarn) { Debug.LogWarning("TargetRpc call on un-spawned object"); }
|
Debug.LogWarning("TargetRpc call on un-spawned object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ protected void SendEventInternal(int eventHash, NetworkWriter writer, string eve
|
|||||||
{
|
{
|
||||||
if (!NetworkServer.active)
|
if (!NetworkServer.active)
|
||||||
{
|
{
|
||||||
if (LogFilter.logWarn) { Debug.LogWarning("SendEvent no server?"); }
|
Debug.LogWarning("SendEvent no server?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ protected static void RegisterCommandDelegate(Type invokeClass, int cmdHash, Cmd
|
|||||||
inv.invokeClass = invokeClass;
|
inv.invokeClass = invokeClass;
|
||||||
inv.invokeFunction = func;
|
inv.invokeFunction = func;
|
||||||
s_CmdHandlerDelegates[cmdHash] = inv;
|
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)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
@ -214,7 +214,7 @@ protected static void RegisterRpcDelegate(Type invokeClass, int cmdHash, CmdDele
|
|||||||
inv.invokeClass = invokeClass;
|
inv.invokeClass = invokeClass;
|
||||||
inv.invokeFunction = func;
|
inv.invokeFunction = func;
|
||||||
s_CmdHandlerDelegates[cmdHash] = inv;
|
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)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
@ -229,7 +229,7 @@ protected static void RegisterEventDelegate(Type invokeClass, int cmdHash, CmdDe
|
|||||||
inv.invokeClass = invokeClass;
|
inv.invokeClass = invokeClass;
|
||||||
inv.invokeFunction = func;
|
inv.invokeFunction = func;
|
||||||
s_CmdHandlerDelegates[cmdHash] = inv;
|
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)
|
internal static string GetInvoker(int cmdHash)
|
||||||
@ -264,7 +264,7 @@ static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out Type i
|
|||||||
Invoker invoker = null;
|
Invoker invoker = null;
|
||||||
if (!s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker))
|
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;
|
invokeClass = null;
|
||||||
invokeFunction = null;
|
invokeFunction = null;
|
||||||
return false;
|
return false;
|
||||||
@ -272,7 +272,7 @@ static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out Type i
|
|||||||
|
|
||||||
if (invoker == null)
|
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;
|
invokeClass = null;
|
||||||
invokeFunction = null;
|
invokeFunction = null;
|
||||||
return false;
|
return false;
|
||||||
@ -280,7 +280,7 @@ static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out Type i
|
|||||||
|
|
||||||
if (invoker.invokeType != invokeType)
|
if (invoker.invokeType != invokeType)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("GetInvokerForHash hash:" + cmdHash + " mismatched invokeType"); }
|
Debug.LogError("GetInvokerForHash hash:" + cmdHash + " mismatched invokeType");
|
||||||
invokeClass = null;
|
invokeClass = null;
|
||||||
invokeFunction = null;
|
invokeFunction = null;
|
||||||
return false;
|
return false;
|
||||||
@ -416,7 +416,7 @@ protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gam
|
|||||||
newGameObjectNetId = uv.netId;
|
newGameObjectNetId = uv.netId;
|
||||||
if (newGameObjectNetId == 0)
|
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 (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);
|
SetDirtyBit(dirtyBit);
|
||||||
gameObjectField = newGameObject;
|
gameObjectField = newGameObject;
|
||||||
netIdField = newGameObjectNetId;
|
netIdField = newGameObjectNetId;
|
||||||
@ -443,7 +443,7 @@ protected void SetSyncVar<T>(T value, ref T fieldValue, ulong dirtyBit)
|
|||||||
if ((value == null && fieldValue != null) ||
|
if ((value == null && fieldValue != null) ||
|
||||||
(value != null && !value.Equals(fieldValue)))
|
(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);
|
SetDirtyBit(dirtyBit);
|
||||||
fieldValue = value;
|
fieldValue = value;
|
||||||
}
|
}
|
||||||
|
@ -80,13 +80,13 @@ public void SetNetworkConnectionClass<T>() where T : NetworkConnection
|
|||||||
|
|
||||||
public NetworkClient()
|
public NetworkClient()
|
||||||
{
|
{
|
||||||
if (LogFilter.logDev) { Debug.Log("Client created version " + Version.Current); }
|
if (LogFilter.Debug) { Debug.Log("Client created version " + Version.Current); }
|
||||||
AddClient(this);
|
AddClient(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkClient(NetworkConnection conn)
|
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);
|
AddClient(this);
|
||||||
|
|
||||||
SetActive(true);
|
SetActive(true);
|
||||||
@ -100,7 +100,7 @@ public void Connect(string serverIp, int serverPort)
|
|||||||
{
|
{
|
||||||
PrepareForConnect();
|
PrepareForConnect();
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("Client Connect: " + serverIp + ":" + serverPort); }
|
if (LogFilter.Debug) { Debug.Log("Client Connect: " + serverIp + ":" + serverPort); }
|
||||||
|
|
||||||
string hostnameOrIp = serverIp;
|
string hostnameOrIp = serverIp;
|
||||||
m_ServerPort = serverPort;
|
m_ServerPort = serverPort;
|
||||||
@ -141,18 +141,18 @@ public bool Send(short msgType, MessageBase msg)
|
|||||||
{
|
{
|
||||||
if (connectState != ConnectState.Connected)
|
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 false;
|
||||||
}
|
}
|
||||||
return m_Connection.Send(msgType, msg);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Shutdown()
|
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;
|
m_ClientId = -1;
|
||||||
RemoveClient(this);
|
RemoveClient(this);
|
||||||
if (s_Clients.Count == 0)
|
if (s_Clients.Count == 0)
|
||||||
@ -253,7 +253,7 @@ internal virtual void Update()
|
|||||||
|
|
||||||
void GenerateConnectError(byte error)
|
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);
|
GenerateError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,14 +261,14 @@ void GenerateConnectError(byte error)
|
|||||||
void GenerateDataError(byte error)
|
void GenerateDataError(byte error)
|
||||||
{
|
{
|
||||||
NetworkError dataError = (NetworkError)error;
|
NetworkError dataError = (NetworkError)error;
|
||||||
if (LogFilter.logError) { Debug.LogError("UNet Client Data Error: " + dataError); }
|
Debug.LogError("UNet Client Data Error: " + dataError);
|
||||||
GenerateError(error);
|
GenerateError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateDisconnectError(byte error)
|
void GenerateDisconnectError(byte error)
|
||||||
{
|
{
|
||||||
NetworkError disconnectError = (NetworkError)error;
|
NetworkError disconnectError = (NetworkError)error;
|
||||||
if (LogFilter.logError) { Debug.LogError("UNet Client Disconnect Error: " + disconnectError); }
|
Debug.LogError("UNet Client Disconnect Error: " + disconnectError);
|
||||||
GenerateError(error);
|
GenerateError(error);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@ -308,7 +308,7 @@ public void RegisterHandler(short msgType, NetworkMessageDelegate handler)
|
|||||||
{
|
{
|
||||||
if (m_MessageHandlers.ContainsKey(msgType))
|
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;
|
m_MessageHandlers[msgType] = handler;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public bool InvokeHandler(short msgType, NetworkReader reader)
|
|||||||
msgDelegate(message);
|
msgDelegate(message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (LogFilter.logError) { Debug.LogError("NetworkConnection InvokeHandler no handler for " + msgType); }
|
Debug.LogError("NetworkConnection InvokeHandler no handler for " + msgType);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ public void RegisterHandler(short msgType, NetworkMessageDelegate handler)
|
|||||||
{
|
{
|
||||||
if (m_MessageHandlers.ContainsKey(msgType))
|
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;
|
m_MessageHandlers[msgType] = handler;
|
||||||
}
|
}
|
||||||
@ -176,14 +176,14 @@ protected virtual bool SendBytes(byte[] bytes)
|
|||||||
|
|
||||||
if (bytes.Length > Transport.MaxPacketSize)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes.Length == 0)
|
if (bytes.Length == 0)
|
||||||
{
|
{
|
||||||
// zero length packets getting into the packet queues are bad.
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,12 +222,12 @@ protected void HandleBytes(byte[] buffer)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//NOTE: this throws away the rest of the buffer. Need moar error codes
|
//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
|
else
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("HandleBytes UnpackMessage failed for: " + BitConverter.ToString(buffer)); }
|
Debug.LogError("HandleBytes UnpackMessage failed for: " + BitConverter.ToString(buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ internal void SetDynamicAssetId(Guid newAssetId)
|
|||||||
}
|
}
|
||||||
else
|
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 (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 = conn;
|
||||||
m_ClientAuthorityOwner.AddOwnedObject(this);
|
m_ClientAuthorityOwner.AddOwnedObject(this);
|
||||||
@ -195,7 +195,7 @@ void OnValidate()
|
|||||||
{
|
{
|
||||||
if (m_ServerOnly && m_LocalPlayerAuthority)
|
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;
|
m_LocalPlayerAuthority = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ bool ThisIsASceneObjectWithPrefabParent(out GameObject prefab)
|
|||||||
prefab = (GameObject)PrefabUtility.GetPrefabParent(gameObject);
|
prefab = (GameObject)PrefabUtility.GetPrefabParent(gameObject);
|
||||||
if (prefab == null)
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -279,12 +279,12 @@ internal void OnStartServer(bool allowNonZeroNetId)
|
|||||||
{
|
{
|
||||||
if (!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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LogFilter.logDev) { Debug.Log("OnStartServer " + gameObject + " GUID:" + netId); }
|
if (LogFilter.logDebug) { Debug.Log("OnStartServer " + gameObject + " GUID:" + netId); }
|
||||||
NetworkServer.SetLocalObjectOnServer(netId, gameObject);
|
NetworkServer.SetLocalObjectOnServer(netId, gameObject);
|
||||||
|
|
||||||
for (int i = 0; i < m_NetworkBehaviours.Length; i++)
|
for (int i = 0; i < m_NetworkBehaviours.Length; i++)
|
||||||
@ -318,7 +318,7 @@ internal void OnStartClient()
|
|||||||
m_IsClient = true;
|
m_IsClient = true;
|
||||||
CacheBehaviours();
|
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++)
|
for (int i = 0; i < m_NetworkBehaviours.Length; i++)
|
||||||
{
|
{
|
||||||
NetworkBehaviour comp = m_NetworkBehaviours[i];
|
NetworkBehaviour comp = m_NetworkBehaviours[i];
|
||||||
@ -336,7 +336,7 @@ internal void OnStartClient()
|
|||||||
|
|
||||||
internal void OnStartAuthority()
|
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);
|
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;
|
return;
|
||||||
@ -434,7 +434,7 @@ internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, boo
|
|||||||
// be useful for debugging.
|
// be useful for debugging.
|
||||||
if (bytes.Length > Transport.MaxPacketSize)
|
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
|
// 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 (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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +546,7 @@ internal void HandleClientAuthority(bool authority)
|
|||||||
{
|
{
|
||||||
if (!localPlayerAuthority)
|
if (!localPlayerAuthority)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("HandleClientAuthority " + gameObject + " does not have localPlayerAuthority"); }
|
Debug.LogError("HandleClientAuthority " + gameObject + " does not have localPlayerAuthority");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +563,7 @@ bool GetInvokeComponent(int cmdHash, Type invokeClass, out NetworkBehaviour invo
|
|||||||
if (invokeComponent == null)
|
if (invokeComponent == null)
|
||||||
{
|
{
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -578,7 +578,7 @@ internal void HandleSyncEvent(int cmdHash, NetworkReader reader)
|
|||||||
if (gameObject == null)
|
if (gameObject == null)
|
||||||
{
|
{
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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;
|
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...
|
// We don't get a valid lookup of the command name when it doesn't exist...
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,7 +599,7 @@ internal void HandleSyncEvent(int cmdHash, NetworkReader reader)
|
|||||||
if (!GetInvokeComponent(cmdHash, invokeClass, out invokeComponent))
|
if (!GetInvokeComponent(cmdHash, invokeClass, out invokeComponent))
|
||||||
{
|
{
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,7 +615,7 @@ internal void HandleCommand(int cmdHash, NetworkReader reader)
|
|||||||
if (gameObject == null)
|
if (gameObject == null)
|
||||||
{
|
{
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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;
|
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...
|
// We don't get a valid lookup of the command name when it doesn't exist...
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,7 +636,7 @@ internal void HandleCommand(int cmdHash, NetworkReader reader)
|
|||||||
if (!GetInvokeComponent(cmdHash, invokeClass, out invokeComponent))
|
if (!GetInvokeComponent(cmdHash, invokeClass, out invokeComponent))
|
||||||
{
|
{
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,7 +652,7 @@ internal void HandleRPC(int cmdHash, NetworkReader reader)
|
|||||||
if (gameObject == null)
|
if (gameObject == null)
|
||||||
{
|
{
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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;
|
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...
|
// We don't get a valid lookup of the command name when it doesn't exist...
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,7 +673,7 @@ internal void HandleRPC(int cmdHash, NetworkReader reader)
|
|||||||
if (!GetInvokeComponent(cmdHash, invokeClass, out invokeComponent))
|
if (!GetInvokeComponent(cmdHash, invokeClass, out invokeComponent))
|
||||||
{
|
{
|
||||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -767,7 +767,7 @@ internal void AddObserver(NetworkConnection conn)
|
|||||||
{
|
{
|
||||||
if (m_Observers == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -778,7 +778,7 @@ internal void AddObserver(NetworkConnection conn)
|
|||||||
return;
|
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;
|
m_Observers[conn.connectionId] = conn;
|
||||||
conn.AddToVisList(this);
|
conn.AddToVisList(this);
|
||||||
@ -838,7 +838,7 @@ public void RebuildObservers(bool initialize)
|
|||||||
|
|
||||||
if (!conn.isReady)
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,25 +881,25 @@ public bool RemoveClientAuthority(NetworkConnection conn)
|
|||||||
{
|
{
|
||||||
if (!isServer)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connectionToClient != null)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_ClientAuthorityOwner == null)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_ClientAuthorityOwner != conn)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -926,24 +926,24 @@ public bool AssignClientAuthority(NetworkConnection conn)
|
|||||||
{
|
{
|
||||||
if (!isServer)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (!localPlayerAuthority)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_ClientAuthorityOwner != null && conn != m_ClientAuthorityOwner)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn == null)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class NetworkManager : MonoBehaviour
|
|||||||
[SerializeField] string m_NetworkAddress = "localhost";
|
[SerializeField] string m_NetworkAddress = "localhost";
|
||||||
[SerializeField] bool m_DontDestroyOnLoad = true;
|
[SerializeField] bool m_DontDestroyOnLoad = true;
|
||||||
[SerializeField] bool m_RunInBackground = true;
|
[SerializeField] bool m_RunInBackground = true;
|
||||||
[SerializeField] LogFilter.FilterLevel m_LogLevel = LogFilter.FilterLevel.Info;
|
[SerializeField] bool m_ShowDebugMessages;
|
||||||
[SerializeField] GameObject m_PlayerPrefab;
|
[SerializeField] GameObject m_PlayerPrefab;
|
||||||
[SerializeField] bool m_AutoCreatePlayer = true;
|
[SerializeField] bool m_AutoCreatePlayer = true;
|
||||||
[SerializeField] PlayerSpawnMethod m_PlayerSpawnMethod;
|
[SerializeField] PlayerSpawnMethod m_PlayerSpawnMethod;
|
||||||
@ -43,7 +43,7 @@ public class NetworkManager : MonoBehaviour
|
|||||||
public string networkAddress { get { return m_NetworkAddress; } set { m_NetworkAddress = value; } }
|
public string networkAddress { get { return m_NetworkAddress; } set { m_NetworkAddress = value; } }
|
||||||
public bool dontDestroyOnLoad { get { return m_DontDestroyOnLoad; } set { m_DontDestroyOnLoad = value; } }
|
public bool dontDestroyOnLoad { get { return m_DontDestroyOnLoad; } set { m_DontDestroyOnLoad = value; } }
|
||||||
public bool runInBackground { get { return m_RunInBackground; } set { m_RunInBackground = 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 GameObject playerPrefab { get { return m_PlayerPrefab; } set { m_PlayerPrefab = value; } }
|
||||||
public bool autoCreatePlayer { get { return m_AutoCreatePlayer; } set { m_AutoCreatePlayer = value; } }
|
public bool autoCreatePlayer { get { return m_AutoCreatePlayer; } set { m_AutoCreatePlayer = value; } }
|
||||||
public PlayerSpawnMethod playerSpawnMethod { get { return m_PlayerSpawnMethod; } set { m_PlayerSpawnMethod = value; } }
|
public PlayerSpawnMethod playerSpawnMethod { get { return m_PlayerSpawnMethod; } set { m_PlayerSpawnMethod = value; } }
|
||||||
@ -108,26 +108,23 @@ void InitializeSingleton()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do this early
|
// do this early
|
||||||
if (logLevel != LogFilter.FilterLevel.SetInScripting)
|
LogFilter.Debug = showDebugMessages;
|
||||||
{
|
|
||||||
LogFilter.currentLogLevel = logLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_DontDestroyOnLoad)
|
if (m_DontDestroyOnLoad)
|
||||||
{
|
{
|
||||||
if (singleton != null)
|
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);
|
Destroy(gameObject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (LogFilter.logDev) { Debug.Log("NetworkManager created singleton (DontDestroyOnLoad)"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager created singleton (DontDestroyOnLoad)"); }
|
||||||
singleton = this;
|
singleton = this;
|
||||||
if (Application.isPlaying) DontDestroyOnLoad(gameObject);
|
if (Application.isPlaying) DontDestroyOnLoad(gameObject);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (LogFilter.logDev) { Debug.Log("NetworkManager created singleton (ForScene)"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager created singleton (ForScene)"); }
|
||||||
singleton = this;
|
singleton = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +178,7 @@ protected void OnValidate()
|
|||||||
|
|
||||||
if (m_PlayerPrefab != null && m_PlayerPrefab.GetComponent<NetworkIdentity>() == null)
|
if (m_PlayerPrefab != null && m_PlayerPrefab.GetComponent<NetworkIdentity>() == null)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("NetworkManager - playerPrefab must have a NetworkIdentity."); }
|
Debug.LogError("NetworkManager - playerPrefab must have a NetworkIdentity.");
|
||||||
m_PlayerPrefab = null;
|
m_PlayerPrefab = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,7 +206,7 @@ public bool StartServer()
|
|||||||
{
|
{
|
||||||
if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort, m_MaxConnections))
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +214,7 @@ public bool StartServer()
|
|||||||
{
|
{
|
||||||
if (!NetworkServer.Listen(m_NetworkPort, m_MaxConnections))
|
if (!NetworkServer.Listen(m_NetworkPort, m_MaxConnections))
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("StartServer listen failed."); }
|
Debug.LogError("StartServer listen failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,7 +232,7 @@ public bool StartServer()
|
|||||||
// this must be after Listen(), since that registers the default message handlers
|
// this must be after Listen(), since that registers the default message handlers
|
||||||
RegisterServerMessages();
|
RegisterServerMessages();
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager StartServer port:" + m_NetworkPort); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager StartServer port:" + m_NetworkPort); }
|
||||||
isNetworkActive = true;
|
isNetworkActive = true;
|
||||||
|
|
||||||
// Only change scene if the requested online scene is not blank, and is not already loaded
|
// 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 (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;
|
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);
|
client.Connect(m_NetworkAddress, m_NetworkPort);
|
||||||
|
|
||||||
@ -315,7 +312,7 @@ public virtual NetworkClient StartHost()
|
|||||||
|
|
||||||
NetworkClient ConnectLocalClient()
|
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";
|
m_NetworkAddress = "localhost";
|
||||||
client = ClientScene.ConnectLocalServer();
|
client = ClientScene.ConnectLocalServer();
|
||||||
RegisterClientMessages(client);
|
RegisterClientMessages(client);
|
||||||
@ -337,7 +334,7 @@ public void StopServer()
|
|||||||
|
|
||||||
OnStopServer();
|
OnStopServer();
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager StopServer"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager StopServer"); }
|
||||||
isNetworkActive = false;
|
isNetworkActive = false;
|
||||||
NetworkServer.Shutdown();
|
NetworkServer.Shutdown();
|
||||||
if (!string.IsNullOrEmpty(m_OfflineScene))
|
if (!string.IsNullOrEmpty(m_OfflineScene))
|
||||||
@ -351,7 +348,7 @@ public void StopClient()
|
|||||||
{
|
{
|
||||||
OnStopClient();
|
OnStopClient();
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager StopClient"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager StopClient"); }
|
||||||
isNetworkActive = false;
|
isNetworkActive = false;
|
||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
@ -373,11 +370,11 @@ public virtual void ServerChangeScene(string newSceneName)
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(newSceneName))
|
if (string.IsNullOrEmpty(newSceneName))
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("ServerChangeScene empty scene name"); }
|
Debug.LogError("ServerChangeScene empty scene name");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("ServerChangeScene " + newSceneName); }
|
if (LogFilter.Debug) { Debug.Log("ServerChangeScene " + newSceneName); }
|
||||||
NetworkServer.SetAllClientsNotReady();
|
NetworkServer.SetAllClientsNotReady();
|
||||||
networkSceneName = newSceneName;
|
networkSceneName = newSceneName;
|
||||||
|
|
||||||
@ -402,11 +399,11 @@ internal void ClientChangeScene(string newSceneName, bool forceReload)
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(newSceneName))
|
if (string.IsNullOrEmpty(newSceneName))
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("ClientChangeScene empty scene name"); }
|
Debug.LogError("ClientChangeScene empty scene name");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("ClientChangeScene newSceneName:" + newSceneName + " networkSceneName:" + networkSceneName); }
|
if (LogFilter.Debug) { Debug.Log("ClientChangeScene newSceneName:" + newSceneName + " networkSceneName:" + networkSceneName); }
|
||||||
|
|
||||||
if (newSceneName == networkSceneName)
|
if (newSceneName == networkSceneName)
|
||||||
{
|
{
|
||||||
@ -422,7 +419,7 @@ internal void ClientChangeScene(string newSceneName, bool forceReload)
|
|||||||
// (client may be null after StopClient etc.)
|
// (client may be null after StopClient etc.)
|
||||||
if (client != null)
|
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;
|
NetworkClient.pauseMessageHandling = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +434,7 @@ void FinishLoadScene()
|
|||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
// process queued messages that we received while loading the scene
|
// 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;
|
NetworkClient.pauseMessageHandling = false;
|
||||||
|
|
||||||
if (s_ClientReadyConnection != null)
|
if (s_ClientReadyConnection != null)
|
||||||
@ -449,7 +446,7 @@ void FinishLoadScene()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (LogFilter.logDev) { Debug.Log("FinishLoadScene client is null"); }
|
if (LogFilter.Debug) { Debug.Log("FinishLoadScene client is null"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NetworkServer.active)
|
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.
|
// 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 (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_DomainReload = false;
|
||||||
s_PendingSingleton.InitializeSingleton();
|
s_PendingSingleton.InitializeSingleton();
|
||||||
@ -500,7 +497,7 @@ internal static void UpdateScene()
|
|||||||
if (!s_LoadingSceneAsync.isDone)
|
if (!s_LoadingSceneAsync.isDone)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("ClientChangeScene done readyCon:" + s_ClientReadyConnection); }
|
if (LogFilter.Debug) { Debug.Log("ClientChangeScene done readyCon:" + s_ClientReadyConnection); }
|
||||||
singleton.FinishLoadScene();
|
singleton.FinishLoadScene();
|
||||||
s_LoadingSceneAsync.allowSceneActivation = true;
|
s_LoadingSceneAsync.allowSceneActivation = true;
|
||||||
s_LoadingSceneAsync = null;
|
s_LoadingSceneAsync = null;
|
||||||
@ -509,18 +506,18 @@ internal static void UpdateScene()
|
|||||||
// protected so that inheriting classes' OnDestroy() can call base.OnDestroy() too
|
// protected so that inheriting classes' OnDestroy() can call base.OnDestroy() too
|
||||||
protected void OnDestroy()
|
protected void OnDestroy()
|
||||||
{
|
{
|
||||||
if (LogFilter.logDev) { Debug.Log("NetworkManager destroyed"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager destroyed"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterStartPosition(Transform start)
|
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);
|
s_StartPositions.Add(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UnRegisterStartPosition(Transform 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);
|
s_StartPositions.Remove(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,7 +544,7 @@ public static void Shutdown()
|
|||||||
|
|
||||||
internal void OnServerConnectInternal(NetworkMessage netMsg)
|
internal void OnServerConnectInternal(NetworkMessage netMsg)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerConnectInternal"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerConnectInternal"); }
|
||||||
|
|
||||||
if (networkSceneName != "" && networkSceneName != m_OfflineScene)
|
if (networkSceneName != "" && networkSceneName != m_OfflineScene)
|
||||||
{
|
{
|
||||||
@ -560,19 +557,19 @@ internal void OnServerConnectInternal(NetworkMessage netMsg)
|
|||||||
|
|
||||||
internal void OnServerDisconnectInternal(NetworkMessage netMsg)
|
internal void OnServerDisconnectInternal(NetworkMessage netMsg)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerDisconnectInternal"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerDisconnectInternal"); }
|
||||||
OnServerDisconnect(netMsg.conn);
|
OnServerDisconnect(netMsg.conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void OnServerReadyMessageInternal(NetworkMessage netMsg)
|
internal void OnServerReadyMessageInternal(NetworkMessage netMsg)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerReadyMessageInternal"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerReadyMessageInternal"); }
|
||||||
OnServerReady(netMsg.conn);
|
OnServerReady(netMsg.conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void OnServerAddPlayerMessageInternal(NetworkMessage netMsg)
|
internal void OnServerAddPlayerMessageInternal(NetworkMessage netMsg)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerAddPlayerMessageInternal"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager:OnServerAddPlayerMessageInternal"); }
|
||||||
|
|
||||||
AddPlayerMessage msg = new AddPlayerMessage();
|
AddPlayerMessage msg = new AddPlayerMessage();
|
||||||
netMsg.ReadMessage(msg);
|
netMsg.ReadMessage(msg);
|
||||||
@ -590,7 +587,7 @@ internal void OnServerAddPlayerMessageInternal(NetworkMessage netMsg)
|
|||||||
|
|
||||||
internal void OnServerRemovePlayerMessageInternal(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();
|
RemovePlayerMessage msg = new RemovePlayerMessage();
|
||||||
netMsg.ReadMessage(msg);
|
netMsg.ReadMessage(msg);
|
||||||
@ -604,7 +601,7 @@ internal void OnServerRemovePlayerMessageInternal(NetworkMessage netMsg)
|
|||||||
|
|
||||||
internal void OnServerErrorInternal(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();
|
ErrorMessage msg = new ErrorMessage();
|
||||||
netMsg.ReadMessage(msg);
|
netMsg.ReadMessage(msg);
|
||||||
@ -615,7 +612,7 @@ internal void OnServerErrorInternal(NetworkMessage netMsg)
|
|||||||
|
|
||||||
internal void OnClientConnectInternal(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;
|
string loadedSceneName = SceneManager.GetSceneAt(0).name;
|
||||||
if (string.IsNullOrEmpty(m_OnlineScene) || (m_OnlineScene == m_OfflineScene) || (loadedSceneName == m_OnlineScene))
|
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)
|
internal void OnClientDisconnectInternal(NetworkMessage netMsg)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnClientDisconnectInternal"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager:OnClientDisconnectInternal"); }
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(m_OfflineScene))
|
if (!string.IsNullOrEmpty(m_OfflineScene))
|
||||||
{
|
{
|
||||||
@ -644,7 +641,7 @@ internal void OnClientDisconnectInternal(NetworkMessage netMsg)
|
|||||||
|
|
||||||
internal void OnClientNotReadyMessageInternal(NetworkMessage netMsg)
|
internal void OnClientNotReadyMessageInternal(NetworkMessage netMsg)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnClientNotReadyMessageInternal"); }
|
if (LogFilter.Debug) { Debug.Log("NetworkManager:OnClientNotReadyMessageInternal"); }
|
||||||
|
|
||||||
ClientScene.SetNotReady();
|
ClientScene.SetNotReady();
|
||||||
OnClientNotReady(netMsg.conn);
|
OnClientNotReady(netMsg.conn);
|
||||||
@ -654,7 +651,7 @@ internal void OnClientNotReadyMessageInternal(NetworkMessage netMsg)
|
|||||||
|
|
||||||
internal void OnClientErrorInternal(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();
|
ErrorMessage msg = new ErrorMessage();
|
||||||
netMsg.ReadMessage(msg);
|
netMsg.ReadMessage(msg);
|
||||||
@ -663,7 +660,7 @@ internal void OnClientErrorInternal(NetworkMessage netMsg)
|
|||||||
|
|
||||||
internal void OnClientSceneInternal(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();
|
string newSceneName = netMsg.reader.ReadString();
|
||||||
|
|
||||||
@ -682,7 +679,7 @@ public virtual void OnServerConnect(NetworkConnection conn)
|
|||||||
public virtual void OnServerDisconnect(NetworkConnection conn)
|
public virtual void OnServerDisconnect(NetworkConnection conn)
|
||||||
{
|
{
|
||||||
NetworkServer.DestroyPlayerForConnection(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)
|
public virtual void OnServerReady(NetworkConnection conn)
|
||||||
@ -690,7 +687,7 @@ public virtual void OnServerReady(NetworkConnection conn)
|
|||||||
if (conn.playerController == null)
|
if (conn.playerController == null)
|
||||||
{
|
{
|
||||||
// this is now allowed (was not for a while)
|
// 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);
|
NetworkServer.SetClientReady(conn);
|
||||||
}
|
}
|
||||||
@ -709,19 +706,19 @@ void OnServerAddPlayerInternal(NetworkConnection conn)
|
|||||||
{
|
{
|
||||||
if (m_PlayerPrefab == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_PlayerPrefab.GetComponent<NetworkIdentity>() == null)
|
if (m_PlayerPrefab.GetComponent<NetworkIdentity>() == 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn.playerController != null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ public Transform ReadTransform()
|
|||||||
GameObject go = ClientScene.FindLocalObject(netId);
|
GameObject go = ClientScene.FindLocalObject(netId);
|
||||||
if (go == null)
|
if (go == null)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDebug) { Debug.Log("ReadTransform netId:" + netId); }
|
if (LogFilter.Debug) { Debug.Log("ReadTransform netId:" + netId); }
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ public GameObject ReadGameObject()
|
|||||||
}
|
}
|
||||||
if (go == null)
|
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;
|
return go;
|
||||||
@ -258,7 +258,7 @@ public NetworkIdentity ReadNetworkIdentity()
|
|||||||
}
|
}
|
||||||
if (go == null)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ internal void Shutdown()
|
|||||||
|
|
||||||
internal void SetLocalObject(uint netId, GameObject obj, bool isClient, bool isServer)
|
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)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
@ -100,12 +100,12 @@ internal static void RegisterPrefab(GameObject prefab, Guid newAssetId)
|
|||||||
{
|
{
|
||||||
view.SetDynamicAssetId(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;
|
s_GuidToPrefab[view.assetId] = prefab;
|
||||||
}
|
}
|
||||||
else
|
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<NetworkIdentity>();
|
NetworkIdentity view = prefab.GetComponent<NetworkIdentity>();
|
||||||
if (view)
|
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;
|
s_GuidToPrefab[view.assetId] = prefab;
|
||||||
|
|
||||||
var uvs = prefab.GetComponentsInChildren<NetworkIdentity>();
|
var uvs = prefab.GetComponentsInChildren<NetworkIdentity>();
|
||||||
if (uvs.Length > 1)
|
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
|
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 (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;
|
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_SpawnHandlers[assetId] = spawnHandler;
|
||||||
s_UnspawnHandlers[assetId] = unspawnHandler;
|
s_UnspawnHandlers[assetId] = unspawnHandler;
|
||||||
@ -176,7 +173,7 @@ internal static void UnregisterPrefab(GameObject prefab)
|
|||||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||||
if (identity == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
s_SpawnHandlers.Remove(identity.assetId);
|
s_SpawnHandlers.Remove(identity.assetId);
|
||||||
@ -188,23 +185,23 @@ internal static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandle
|
|||||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||||
if (identity == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawnHandler == null || unspawnHandler == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (identity.assetId == Guid.Empty)
|
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;
|
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_SpawnHandlers[identity.assetId] = spawnHandler;
|
||||||
s_UnspawnHandlers[identity.assetId] = unspawnHandler;
|
s_UnspawnHandlers[identity.assetId] = unspawnHandler;
|
||||||
|
@ -83,9 +83,7 @@ public static void Initialize()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
s_Initialized = true;
|
s_Initialized = true;
|
||||||
if (LogFilter.logDev) { Debug.Log("NetworkServer Created version " + Version.Current); }
|
if (LogFilter.logDebug) { Debug.Log("NetworkServer Created version " + Version.Current); }
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkServer initialize."); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void RegisterMessageHandlers()
|
internal static void RegisterMessageHandlers()
|
||||||
@ -194,7 +192,7 @@ internal static void RemoveLocalClient(NetworkConnection localClientConnection)
|
|||||||
|
|
||||||
internal static void SetLocalObjectOnServer(uint netId, GameObject obj)
|
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);
|
s_NetworkScene.SetLocalObject(netId, obj, false, true);
|
||||||
}
|
}
|
||||||
@ -210,7 +208,7 @@ internal static void ActivateLocalClientScene()
|
|||||||
{
|
{
|
||||||
if (!uv.isClient)
|
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);
|
ClientScene.SetLocalObject(uv.netId, uv.gameObject);
|
||||||
uv.OnStartClient();
|
uv.OnStartClient();
|
||||||
@ -222,7 +220,7 @@ internal static void ActivateLocalClientScene()
|
|||||||
// this is used for ObjectDestroy messages.
|
// this is used for ObjectDestroy messages.
|
||||||
static bool SendToObservers(GameObject contextObj, short msgType, MessageBase msg)
|
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<NetworkIdentity>();
|
NetworkIdentity uv = contextObj.GetComponent<NetworkIdentity>();
|
||||||
if (uv != null && uv.observers != null)
|
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)
|
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;
|
bool result = true;
|
||||||
foreach (KeyValuePair<int, NetworkConnection> kvp in connections)
|
foreach (KeyValuePair<int, NetworkConnection> 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)
|
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)
|
if (contextObj == null)
|
||||||
{
|
{
|
||||||
@ -423,7 +421,7 @@ static void OnDisconnected(NetworkConnection conn)
|
|||||||
if (conn.playerController != null)
|
if (conn.playerController != null)
|
||||||
{
|
{
|
||||||
//NOTE: should there be default behaviour here to destroy the associated player?
|
//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); }
|
if (LogFilter.logDebug) { Debug.Log("Server lost client:" + conn.connectionId); }
|
||||||
@ -440,7 +438,7 @@ static void HandleData(int connectionId, byte[] data, byte error)
|
|||||||
}
|
}
|
||||||
else
|
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)
|
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);
|
GenerateError(null, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,14 +457,14 @@ static void GenerateConnectError(byte error)
|
|||||||
static void GenerateDataError(NetworkConnection conn, byte error)
|
static void GenerateDataError(NetworkConnection conn, byte error)
|
||||||
{
|
{
|
||||||
NetworkError dataError = (NetworkError)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);
|
GenerateError(conn, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GenerateDisconnectError(NetworkConnection conn, byte error)
|
static void GenerateDisconnectError(NetworkConnection conn, byte error)
|
||||||
{
|
{
|
||||||
NetworkError disconnectError = (NetworkError)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);
|
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)
|
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);
|
conn.Send(msgType, msg);
|
||||||
return;
|
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)
|
public static bool ReplacePlayerForConnection(NetworkConnection conn, GameObject player, Guid assetId)
|
||||||
@ -585,7 +583,7 @@ internal static bool InternalAddPlayerForConnection(NetworkConnection conn, Game
|
|||||||
NetworkIdentity playerNetworkIdentity;
|
NetworkIdentity playerNetworkIdentity;
|
||||||
if (!GetNetworkIdentity(playerGameObject, out 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;
|
return false;
|
||||||
}
|
}
|
||||||
playerNetworkIdentity.Reset();
|
playerNetworkIdentity.Reset();
|
||||||
@ -593,7 +591,7 @@ internal static bool InternalAddPlayerForConnection(NetworkConnection conn, Game
|
|||||||
// cannot have a player object in "Add" version
|
// cannot have a player object in "Add" version
|
||||||
if (conn.playerController != null)
|
if (conn.playerController != null)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.Log("AddPlayer: player object already exists"); }
|
Debug.Log("AddPlayer: player object already exists");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,12 +619,12 @@ internal static bool InternalAddPlayerForConnection(NetworkConnection conn, Game
|
|||||||
|
|
||||||
static bool SetupLocalPlayerForConnection(NetworkConnection conn, NetworkIdentity uv)
|
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;
|
var localConnection = conn as ULocalConnectionToClient;
|
||||||
if (localConnection != null)
|
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:
|
// Spawn this player for other players, instead of SpawnObject:
|
||||||
if (uv.netId == 0)
|
if (uv.netId == 0)
|
||||||
@ -671,12 +669,12 @@ internal static bool InternalReplacePlayerForConnection(NetworkConnection conn,
|
|||||||
NetworkIdentity playerNetworkIdentity;
|
NetworkIdentity playerNetworkIdentity;
|
||||||
if (!GetNetworkIdentity(playerGameObject, out 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//NOTE: there can be an existing player
|
//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??
|
// is there already an owner that is a different object??
|
||||||
if (conn.playerController != null)
|
if (conn.playerController != null)
|
||||||
@ -692,7 +690,7 @@ internal static bool InternalReplacePlayerForConnection(NetworkConnection conn,
|
|||||||
|
|
||||||
//NOTE: DONT set connection ready.
|
//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))
|
if (SetupLocalPlayerForConnection(conn, playerNetworkIdentity))
|
||||||
{
|
{
|
||||||
@ -714,7 +712,7 @@ static bool GetNetworkIdentity(GameObject go, out NetworkIdentity view)
|
|||||||
view = go.GetComponent<NetworkIdentity>();
|
view = go.GetComponent<NetworkIdentity>();
|
||||||
if (view == null)
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -746,7 +744,7 @@ internal static void SetClientReadyInternal(NetworkConnection conn)
|
|||||||
var localConnection = conn as ULocalConnectionToClient;
|
var localConnection = conn as ULocalConnectionToClient;
|
||||||
if (localConnection != null)
|
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
|
// 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)
|
// 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 (!uv.isClient)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDev) { Debug.Log("LocalClient.SetSpawnObject calling OnStartClient"); }
|
if (LogFilter.logDebug) { Debug.Log("LocalClient.SetSpawnObject calling OnStartClient"); }
|
||||||
uv.OnStartClient();
|
uv.OnStartClient();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -783,7 +781,7 @@ internal static void SetClientReadyInternal(NetworkConnection conn)
|
|||||||
{
|
{
|
||||||
if (uv == null)
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (!uv.gameObject.activeSelf)
|
if (!uv.gameObject.activeSelf)
|
||||||
@ -868,7 +866,7 @@ static void OnRemovePlayerMessage(NetworkMessage netMsg)
|
|||||||
}
|
}
|
||||||
else
|
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);
|
var cmdObject = FindLocalObject(message.netId);
|
||||||
if (cmdObject == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var uv = cmdObject.GetComponent<NetworkIdentity>();
|
var uv = cmdObject.GetComponent<NetworkIdentity>();
|
||||||
if (uv == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -898,12 +896,12 @@ static void OnCommandMessage(NetworkMessage netMsg)
|
|||||||
{
|
{
|
||||||
if (uv.clientAuthorityOwner != netMsg.conn)
|
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;
|
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));
|
uv.HandleCommand(message.cmdHash, new NetworkReader(message.payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -911,14 +909,14 @@ internal static void SpawnObject(GameObject obj)
|
|||||||
{
|
{
|
||||||
if (!NetworkServer.active)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkIdentity objNetworkIdentity;
|
NetworkIdentity objNetworkIdentity;
|
||||||
if (!GetNetworkIdentity(obj, out 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;
|
return;
|
||||||
}
|
}
|
||||||
objNetworkIdentity.Reset();
|
objNetworkIdentity.Reset();
|
||||||
@ -1022,7 +1020,7 @@ static void UnSpawnObject(GameObject obj)
|
|||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDev) { Debug.Log("NetworkServer UnspawnObject is null"); }
|
if (LogFilter.logDebug) { Debug.Log("NetworkServer UnspawnObject is null"); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1041,7 +1039,7 @@ static void DestroyObject(GameObject obj)
|
|||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDev) { Debug.Log("NetworkServer DestroyObject is null"); }
|
if (LogFilter.logDebug) { Debug.Log("NetworkServer DestroyObject is null"); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1204,7 +1202,7 @@ internal static bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer)
|
|||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
namespace Mirror
|
namespace Mirror
|
||||||
{
|
{
|
||||||
// calculates synchronized time and rtt
|
// calculates synchronized time and rtt
|
||||||
public static class NetworkTime
|
public static class NetworkTime
|
||||||
{
|
{
|
||||||
// Date and time when the application started
|
// Date and time when the application started
|
||||||
static readonly DateTime epoch = DateTime.Now;
|
static readonly DateTime epoch = DateTime.Now;
|
||||||
@ -27,7 +27,7 @@ public static void Reset(int windowSize)
|
|||||||
|
|
||||||
internal static NetworkPingMessage GetPing()
|
internal static NetworkPingMessage GetPing()
|
||||||
{
|
{
|
||||||
return new NetworkPingMessage(LocalTime());
|
return new NetworkPingMessage(LocalTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
// executed at the server when we receive a ping message
|
// executed at the server when we receive a ping message
|
||||||
@ -38,7 +38,7 @@ internal static void OnServerPing(NetworkMessage netMsg)
|
|||||||
var pingMsg = new NetworkPingMessage();
|
var pingMsg = new NetworkPingMessage();
|
||||||
netMsg.ReadMessage(pingMsg);
|
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
|
var pongMsg = new NetworkPongMessage
|
||||||
{
|
{
|
||||||
@ -70,29 +70,29 @@ internal static void OnClientPong(NetworkMessage netMsg)
|
|||||||
|
|
||||||
// returns the same time in both client and server
|
// returns the same time in both client and server
|
||||||
// time should be a double because after a while
|
// 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:
|
// a few days. I measured the accuracy of float and I got this:
|
||||||
// for the same day, accuracy is better than 1 ms
|
// for the same day, accuracy is better than 1 ms
|
||||||
// after 1 day, accuracy goes down to 7 ms
|
// after 1 day, accuracy goes down to 7 ms
|
||||||
// after 10 days, accuracy is 61 ms
|
// after 10 days, accuracy is 61 ms
|
||||||
// after 30 days , accuracy is 238 ms
|
// after 30 days , accuracy is 238 ms
|
||||||
// after 60 days, accuracy is 454 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.
|
// and you cast down to float, then the time will jump in 0.4s intervals.
|
||||||
public static double time
|
public static double time
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// Notice _offset is 0 at the server
|
// Notice _offset is 0 at the server
|
||||||
return LocalTime() - _offset.Value;
|
return LocalTime() - _offset.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// measure volatility of time.
|
// measure volatility of time.
|
||||||
// the higher the number, the less accurate the time is
|
// the higher the number, the less accurate the time is
|
||||||
public static double timeVar
|
public static double timeVar
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _offset.Var;
|
return _offset.Var;
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ public static double timeVar
|
|||||||
// standard deviation of time
|
// standard deviation of time
|
||||||
public static double timeSd
|
public static double timeSd
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return Math.Sqrt(timeVar);
|
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
|
// to the server and come back
|
||||||
public static double rtt
|
public static double rtt
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _rtt.Value;
|
return _rtt.Value;
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ public static double rtt
|
|||||||
// the higher the number, the less accurate rtt is
|
// the higher the number, the less accurate rtt is
|
||||||
public static double rttVar
|
public static double rttVar
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _rtt.Var;
|
return _rtt.Var;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ void OnValidate()
|
|||||||
Transform parent = m_Target.parent;
|
Transform parent = m_Target.parent;
|
||||||
if (parent == null)
|
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;
|
m_Target = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ void OnValidate()
|
|||||||
m_Root = parent.gameObject.GetComponent<NetworkTransform>();
|
m_Root = parent.gameObject.GetComponent<NetworkTransform>();
|
||||||
if (m_Root == null)
|
if (m_Root == null)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("NetworkTransformChild root must have NetworkTransform"); }
|
Debug.LogError("NetworkTransformChild root must have NetworkTransform");
|
||||||
m_Target = null;
|
m_Target = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ void OnValidate()
|
|||||||
}
|
}
|
||||||
if (m_ChildIndex == UInt32.MaxValue)
|
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;
|
m_Target = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -397,36 +397,36 @@ internal static void HandleChildTransform(NetworkMessage netMsg)
|
|||||||
GameObject foundObj = NetworkServer.FindLocalObject(message.netId);
|
GameObject foundObj = NetworkServer.FindLocalObject(message.netId);
|
||||||
if (foundObj == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
var children = foundObj.GetComponents<NetworkTransformChild>();
|
var children = foundObj.GetComponents<NetworkTransformChild>();
|
||||||
if (children == null || children.Length == 0)
|
if (children == null || children.Length == 0)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("HandleChildTransform no children"); }
|
Debug.LogError("HandleChildTransform no children");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (message.childIndex >= children.Length)
|
if (message.childIndex >= children.Length)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("HandleChildTransform childIndex invalid"); }
|
Debug.LogError("HandleChildTransform childIndex invalid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkTransformChild foundSync = children[message.childIndex];
|
NetworkTransformChild foundSync = children[message.childIndex];
|
||||||
if (foundSync == null)
|
if (foundSync == null)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("HandleChildTransform null target"); }
|
Debug.LogError("HandleChildTransform null target");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!foundSync.localPlayerAuthority)
|
if (!foundSync.localPlayerAuthority)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("HandleChildTransform no localPlayerAuthority"); }
|
Debug.LogError("HandleChildTransform no localPlayerAuthority");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!netMsg.conn.clientOwnedObjects.Contains(message.netId))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ void VerifySerializeComponentExists()
|
|||||||
m_CharacterController = m_CharacterController ?? GetComponent<CharacterController>();
|
m_CharacterController = m_CharacterController ?? GetComponent<CharacterController>();
|
||||||
if (!m_CharacterController)
|
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;
|
break;
|
||||||
|
|
||||||
@ -1162,23 +1162,23 @@ public static void HandleTransform(NetworkMessage netMsg)
|
|||||||
GameObject foundObj = NetworkServer.FindLocalObject(message.netId);
|
GameObject foundObj = NetworkServer.FindLocalObject(message.netId);
|
||||||
if (foundObj == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
NetworkTransform foundSync = foundObj.GetComponent<NetworkTransform>();
|
NetworkTransform foundSync = foundObj.GetComponent<NetworkTransform>();
|
||||||
if (foundSync == null)
|
if (foundSync == null)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("HandleTransform null target"); }
|
Debug.LogError("HandleTransform null target");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!foundSync.localPlayerAuthority)
|
if (!foundSync.localPlayerAuthority)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("HandleTransform no localPlayerAuthority"); }
|
Debug.LogError("HandleTransform no localPlayerAuthority");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (netMsg.conn.clientOwnedObjects == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1206,7 +1206,7 @@ public static void HandleTransform(NetworkMessage netMsg)
|
|||||||
return;
|
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 ------------------------
|
// --------------------- Compression Helper functions ------------------------
|
||||||
|
@ -74,13 +74,13 @@ public void WriteBytesAndSize(byte[] buffer, int offset, int count)
|
|||||||
}
|
}
|
||||||
if (count > Transport.MaxPacketSize)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count < 0)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ public void Write(Transform value)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (LogFilter.logWarn) { Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity"); }
|
Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity");
|
||||||
WritePackedUInt32(0);
|
WritePackedUInt32(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,7 +323,7 @@ public void Write(GameObject value)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (LogFilter.logWarn) { Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity"); }
|
Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity");
|
||||||
WritePackedUInt32(0);
|
WritePackedUInt32(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user