diff --git a/Assets/Mirage/Editor/Inspectors/NetworkIdentityInspector.cs b/Assets/Mirage/Editor/Inspectors/NetworkIdentityInspector.cs new file mode 100644 index 0000000000..3ce8051e9d --- /dev/null +++ b/Assets/Mirage/Editor/Inspectors/NetworkIdentityInspector.cs @@ -0,0 +1,91 @@ +using UnityEditor; +using UnityEngine; + +namespace Mirage +{ + [CustomEditor(typeof(NetworkIdentity), true)] + public partial class NetworkIdentityInspector : Editor + { + public override void OnInspectorGUI() + { + DrawDefaultInspector(); + + var target = (NetworkIdentity)this.target; + + GUILayout.Space(12); + EditorGUILayout.LabelField("Spawn Ids", EditorStyles.boldLabel); + using (new EditorGUI.DisabledGroupScope(true)) + { + EditorGUILayout.LabelField("Scene Id", target.SceneId != 0 + ? target.SceneId.ToString("X") + : ""); + EditorGUILayout.LabelField("Prefab Hash", target.PrefabHash != 0 + ? target.PrefabHash.ToString("X") + : ""); + } + + if (Application.isPlaying) + RuntimeInfo(target); + } + + private void RuntimeInfo(NetworkIdentity target) + { + + + GUILayout.Space(12); + EditorGUILayout.LabelField("Runtime Values", EditorStyles.boldLabel); + using (new EditorGUI.DisabledGroupScope(true)) + { + EditorGUILayout.LabelField("Spawned", target.IsSpawned ? "Yes" : "No"); + EditorGUILayout.FloatField("Net Id", target.NetId); + } + + GUILayout.Space(12); + EditorGUILayout.LabelField("Server Values", EditorStyles.boldLabel); + using (new EditorGUI.DisabledGroupScope(true)) + { + EditorGUILayout.LabelField("Is Server", target.IsServer ? "Yes" : "No"); + EditorGUILayout.ObjectField("Server Object Manager", target.ServerObjectManager, typeof(ServerObjectManager), false); + EditorGUILayout.TextField("Owner", (target.Owner != null) + ? "Client Authority: " + target.Owner + : "NULL"); + } + + GUILayout.Space(12); + EditorGUILayout.LabelField("Client Values", EditorStyles.boldLabel); + using (new EditorGUI.DisabledGroupScope(true)) + { + EditorGUILayout.ObjectField("Client Object Manager", target.ClientObjectManager, typeof(ClientObjectManager), false); + EditorGUILayout.LabelField("Is Client", target.IsClient ? "Yes" : "No"); + EditorGUILayout.LabelField("Is Local Player", target.IsLocalPlayer ? "Yes" : "No"); + EditorGUILayout.LabelField("Has Authority", target.HasAuthority ? "Yes" : "No"); + } + + GUILayout.Space(12); + GUILayout.Label("Network Visibility", EditorStyles.boldLabel); + using (new EditorGUI.DisabledGroupScope(true)) + { + if (target.TryGetComponent(out var behaviour)) + EditorGUILayout.ObjectField("Visibility", behaviour, typeof(MonoBehaviour), false); + else + EditorGUILayout.TextField("Visibility", "Default ServerObjectManager"); + } + + GUILayout.Space(12); + GUILayout.Label("Behaviours", EditorStyles.boldLabel); + using (new EditorGUI.DisabledGroupScope(true)) + { + EditorGUI.indentLevel++; + foreach (var behaviour in target.NetworkBehaviours) + { + if (behaviour == null) + // could be the case in the editor after existing play mode. + continue; + + EditorGUILayout.ObjectField("Visibility", behaviour, typeof(MonoBehaviour), false); + } + EditorGUI.indentLevel--; + } + } + } +} diff --git a/Assets/Mirage/Editor/Inspectors/NetworkIdentityInspector.cs.meta b/Assets/Mirage/Editor/Inspectors/NetworkIdentityInspector.cs.meta new file mode 100644 index 0000000000..018f5b7967 --- /dev/null +++ b/Assets/Mirage/Editor/Inspectors/NetworkIdentityInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9761ac68a5a38e741b9f4ba584985089 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mirage/Runtime/NetworkIdentity.cs b/Assets/Mirage/Runtime/NetworkIdentity.cs index e9a3ea1321..56a88b2233 100644 --- a/Assets/Mirage/Runtime/NetworkIdentity.cs +++ b/Assets/Mirage/Runtime/NetworkIdentity.cs @@ -162,6 +162,8 @@ public sealed class NetworkIdentity : MonoBehaviour [FormerlySerializedAs("m_SceneId"), FormerlySerializedAs("sceneId")] [SerializeField, HideInInspector] private ulong _sceneId = 0; + [SerializeField, HideInInspector] + private int _prefabHash; public ulong SceneId => _sceneId; @@ -209,12 +211,10 @@ public void ClearSceneId() /// public bool InitialState { get; private set; } - [Header("Runtime References")] - /// /// The ServerObjectManager is present only for server/host instances. /// - [ReadOnlyInspector] + [HideInInspector] [Tooltip("Reference to Server set after the object is spawned. Used when debugging to see which server this object belongs to.")] public ServerObjectManager ServerObjectManager; @@ -226,9 +226,10 @@ public void ClearSceneId() /// /// The ClientObjectManager is present only for client instances. /// - [ReadOnlyInspector] + [HideInInspector] [Tooltip("Reference to Client set after the object is spawned. Used when debugging to see which client this object belongs to.")] public ClientObjectManager ClientObjectManager; + private INetworkPlayer _owner; /// @@ -366,8 +367,6 @@ public INetworkVisibility Visibility } } - [SerializeField, HideInInspector] private int _prefabHash; - public int PrefabHash { get