From e44352d4eca6c8ec1cbcc3664f96b077f3a5447e Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Wed, 31 Aug 2022 15:25:08 -0500 Subject: [PATCH 1/9] fix: Remove "Script" fields from Netcode components in the inspector --- .../Components/NetworkRigidbody.cs | 1 + .../Components/NetworkRigidbody2D.cs | 1 + .../Editor/HiddenScriptEditor.cs | 50 +++++++++++++++++++ .../Editor/HiddenScriptEditor.cs.meta | 3 ++ .../Editor/NetworkManagerEditor.cs | 14 +----- .../Editor/NetworkObjectEditor.cs | 2 +- 6 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs create mode 100644 com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs.meta diff --git a/com.unity.netcode.gameobjects/Components/NetworkRigidbody.cs b/com.unity.netcode.gameobjects/Components/NetworkRigidbody.cs index 6515f7e2af..09fe12e6cd 100644 --- a/com.unity.netcode.gameobjects/Components/NetworkRigidbody.cs +++ b/com.unity.netcode.gameobjects/Components/NetworkRigidbody.cs @@ -7,6 +7,7 @@ namespace Unity.Netcode.Components /// NetworkRigidbody allows for the use of on network objects. By controlling the kinematic /// mode of the and disabling it on all peers but the authoritative one. /// + [AddComponentMenu("Netcode/" + nameof(NetworkRigidbody))] [RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(NetworkTransform))] public class NetworkRigidbody : NetworkBehaviour diff --git a/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs b/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs index 1ac82bbf30..3d43ebc924 100644 --- a/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs +++ b/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs @@ -7,6 +7,7 @@ namespace Unity.Netcode.Components /// NetworkRigidbody allows for the use of on network objects. By controlling the kinematic /// mode of the rigidbody and disabling it on all peers but the authoritative one. /// + [AddComponentMenu("Netcode/" + nameof(NetworkRigidbody2D))] [RequireComponent(typeof(Rigidbody2D))] [RequireComponent(typeof(NetworkTransform))] public class NetworkRigidbody2D : NetworkBehaviour diff --git a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs new file mode 100644 index 0000000000..a26cfc5a2b --- /dev/null +++ b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs @@ -0,0 +1,50 @@ +using Unity.Netcode.Components; +using Unity.Netcode.Transports.UNET; +using Unity.Netcode.Transports.UTP; +using UnityEditor; + +namespace Unity.Netcode.Editor +{ + public class HiddenScriptEditor : UnityEditor.Editor + { + private static readonly string[] s_HiddenFields = {"m_Script"}; + public override void OnInspectorGUI() + { + EditorGUI.BeginChangeCheck(); + serializedObject.UpdateIfRequiredOrScript(); + DrawPropertiesExcluding(serializedObject, s_HiddenFields); + serializedObject.ApplyModifiedProperties(); + EditorGUI.EndChangeCheck(); + } + } + + [CustomEditor(typeof(UNetTransport), true)] + public class UNetTransportEditor : HiddenScriptEditor + { + + } + + [CustomEditor(typeof(UnityTransport), true)] + public class UnityTransportEditor : HiddenScriptEditor + { + + } + + [CustomEditor(typeof(NetworkAnimator), true)] + public class NetworkAnimatorEditor : HiddenScriptEditor + { + + } + + [CustomEditor(typeof(NetworkRigidbody), true)] + public class NetworkRigidbodyEditor : HiddenScriptEditor + { + + } + + [CustomEditor(typeof(NetworkRigidbody2D), true)] + public class NetworkRigidbody2DEditor : HiddenScriptEditor + { + + } +} diff --git a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs.meta b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs.meta new file mode 100644 index 0000000000..f8dd8da119 --- /dev/null +++ b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ebf622cc80e94f488e59caf8b7419f50 +timeCreated: 1661959406 \ No newline at end of file diff --git a/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs b/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs index a788cb8f3e..ef675180b5 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs @@ -213,19 +213,7 @@ public override void OnInspectorGUI() #if !MULTIPLAYER_TOOLS DrawInstallMultiplayerToolsTip(); #endif - - { - var iterator = serializedObject.GetIterator(); - - for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) - { - using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath)) - { - EditorGUILayout.PropertyField(iterator, false); - } - } - } - + if (!m_NetworkManager.IsServer && !m_NetworkManager.IsClient) { serializedObject.Update(); diff --git a/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs b/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs index 5111e92fcc..fff81a5e56 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs @@ -9,7 +9,7 @@ namespace Unity.Netcode.Editor /// [CustomEditor(typeof(NetworkObject), true)] [CanEditMultipleObjects] - public class NetworkObjectEditor : UnityEditor.Editor + public class NetworkObjectEditor : HiddenScriptEditor { private bool m_Initialized; private NetworkObject m_NetworkObject; From 21a5fd6bc683f60d1dce9b00a6b2f6fb7ec4d25b Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Wed, 31 Aug 2022 15:34:42 -0500 Subject: [PATCH 2/9] Standards --- .../Editor/HiddenScriptEditor.cs | 14 +++++++------- .../Editor/NetworkManagerEditor.cs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs index a26cfc5a2b..2be741c51f 100644 --- a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs @@ -1,4 +1,4 @@ -using Unity.Netcode.Components; +using Unity.Netcode.Components; using Unity.Netcode.Transports.UNET; using Unity.Netcode.Transports.UTP; using UnityEditor; @@ -7,7 +7,7 @@ namespace Unity.Netcode.Editor { public class HiddenScriptEditor : UnityEditor.Editor { - private static readonly string[] s_HiddenFields = {"m_Script"}; + private static readonly string[] s_HiddenFields = { "m_Script" }; public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); @@ -21,30 +21,30 @@ public override void OnInspectorGUI() [CustomEditor(typeof(UNetTransport), true)] public class UNetTransportEditor : HiddenScriptEditor { - + } [CustomEditor(typeof(UnityTransport), true)] public class UnityTransportEditor : HiddenScriptEditor { - + } [CustomEditor(typeof(NetworkAnimator), true)] public class NetworkAnimatorEditor : HiddenScriptEditor { - + } [CustomEditor(typeof(NetworkRigidbody), true)] public class NetworkRigidbodyEditor : HiddenScriptEditor { - + } [CustomEditor(typeof(NetworkRigidbody2D), true)] public class NetworkRigidbody2DEditor : HiddenScriptEditor { - + } } diff --git a/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs b/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs index ef675180b5..debaca2e45 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs @@ -213,7 +213,7 @@ public override void OnInspectorGUI() #if !MULTIPLAYER_TOOLS DrawInstallMultiplayerToolsTip(); #endif - + if (!m_NetworkManager.IsServer && !m_NetworkManager.IsClient) { serializedObject.Update(); From cf31912391cb746c518911e869246fa09d91d342 Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Wed, 31 Aug 2022 15:55:13 -0500 Subject: [PATCH 3/9] standards again --- com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs index 2be741c51f..d9aeeef07c 100644 --- a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs @@ -7,12 +7,12 @@ namespace Unity.Netcode.Editor { public class HiddenScriptEditor : UnityEditor.Editor { - private static readonly string[] s_HiddenFields = { "m_Script" }; + private static readonly string[] k_HiddenFields = { "m_Script" }; public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); serializedObject.UpdateIfRequiredOrScript(); - DrawPropertiesExcluding(serializedObject, s_HiddenFields); + DrawPropertiesExcluding(serializedObject, k_HiddenFields); serializedObject.ApplyModifiedProperties(); EditorGUI.EndChangeCheck(); } From ca62e873e4abff38ce3d268e410e1a8d7f233a4b Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Wed, 7 Sep 2022 12:18:57 -0500 Subject: [PATCH 4/9] Fix compile errors in minimalproject --- com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs index d9aeeef07c..d3b33cd719 100644 --- a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs @@ -30,21 +30,27 @@ public class UnityTransportEditor : HiddenScriptEditor } +#if COM_UNITY_MODULES_ANIMATION [CustomEditor(typeof(NetworkAnimator), true)] public class NetworkAnimatorEditor : HiddenScriptEditor { } +#endif +#if COM_UNITY_MODULES_PHYSICS [CustomEditor(typeof(NetworkRigidbody), true)] public class NetworkRigidbodyEditor : HiddenScriptEditor { } +#endif +#if COM_UNITY_MODULES_PHYSICS2D [CustomEditor(typeof(NetworkRigidbody2D), true)] public class NetworkRigidbody2DEditor : HiddenScriptEditor { } +#endif } From 22447816c8453fe28958672d8f159c5177a31173 Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Wed, 7 Sep 2022 12:38:52 -0500 Subject: [PATCH 5/9] Whoops, those version defines were for the runtime, had to add them to editor too. --- .../Editor/com.unity.netcode.editor.asmdef | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Editor/com.unity.netcode.editor.asmdef b/com.unity.netcode.gameobjects/Editor/com.unity.netcode.editor.asmdef index ab1d2717e4..0648dd9341 100644 --- a/com.unity.netcode.gameobjects/Editor/com.unity.netcode.editor.asmdef +++ b/com.unity.netcode.gameobjects/Editor/com.unity.netcode.editor.asmdef @@ -13,6 +13,21 @@ "name": "com.unity.multiplayer.tools", "expression": "", "define": "MULTIPLAYER_TOOLS" + }, + { + "name": "com.unity.modules.animation", + "expression": "", + "define": "COM_UNITY_MODULES_ANIMATION" + }, + { + "name": "com.unity.modules.physics", + "expression": "", + "define": "COM_UNITY_MODULES_PHYSICS" + }, + { + "name": "com.unity.modules.physics2d", + "expression": "", + "define": "COM_UNITY_MODULES_PHYSICS2D" } ] -} \ No newline at end of file +} From afcc4e0f64f1e039e096e14d627289b787a0d16c Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Wed, 7 Sep 2022 14:26:13 -0500 Subject: [PATCH 6/9] validator... --- .../Editor/NetworkObjectEditor.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs b/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs index fff81a5e56..c63f9fc10e 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs @@ -9,12 +9,14 @@ namespace Unity.Netcode.Editor /// [CustomEditor(typeof(NetworkObject), true)] [CanEditMultipleObjects] - public class NetworkObjectEditor : HiddenScriptEditor + public class NetworkObjectEditor : UnityEditor.Editor { private bool m_Initialized; private NetworkObject m_NetworkObject; private bool m_ShowObservers; + private static readonly string[] k_HiddenFields = { "m_Script" }; + private void Initialize() { if (m_Initialized) @@ -95,7 +97,11 @@ public override void OnInspectorGUI() } else { - base.OnInspectorGUI(); + EditorGUI.BeginChangeCheck(); + serializedObject.UpdateIfRequiredOrScript(); + DrawPropertiesExcluding(serializedObject, k_HiddenFields); + serializedObject.ApplyModifiedProperties(); + EditorGUI.EndChangeCheck(); var guiEnabled = GUI.enabled; GUI.enabled = false; From 14e7d1f47baaed04a8fd7e9fb130473f1a83d089 Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Thu, 22 Sep 2022 11:10:19 -0500 Subject: [PATCH 7/9] Fix uncaught merge conflict/compile error --- com.unity.netcode.gameobjects/Components/NetworkRigidbody.cs | 1 - com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/Components/NetworkRigidbody.cs b/com.unity.netcode.gameobjects/Components/NetworkRigidbody.cs index 70d0cdacf2..0569aa97ed 100644 --- a/com.unity.netcode.gameobjects/Components/NetworkRigidbody.cs +++ b/com.unity.netcode.gameobjects/Components/NetworkRigidbody.cs @@ -7,7 +7,6 @@ namespace Unity.Netcode.Components /// NetworkRigidbody allows for the use of on network objects. By controlling the kinematic /// mode of the and disabling it on all peers but the authoritative one. /// - [AddComponentMenu("Netcode/" + nameof(NetworkRigidbody))] [RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(NetworkTransform))] [AddComponentMenu("Netcode/Network Rigidbody")] diff --git a/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs b/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs index 735793e71a..246519cf88 100644 --- a/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs +++ b/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs @@ -7,7 +7,6 @@ namespace Unity.Netcode.Components /// NetworkRigidbody allows for the use of on network objects. By controlling the kinematic /// mode of the rigidbody and disabling it on all peers but the authoritative one. /// - [AddComponentMenu("Netcode/" + nameof(NetworkRigidbody2D))] [RequireComponent(typeof(Rigidbody2D))] [RequireComponent(typeof(NetworkTransform))] [AddComponentMenu("Netcode/Network Rigidbody 2D")] From 6c34462d566035c4130157ffb6fb4fdf9dd23f91 Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Thu, 22 Sep 2022 11:21:47 -0500 Subject: [PATCH 8/9] Added some XMLDocs --- .../Editor/HiddenScriptEditor.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs index d3b33cd719..58000fd503 100644 --- a/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs @@ -5,6 +5,9 @@ namespace Unity.Netcode.Editor { + /// + /// Internal use. Hides the script field for the given component. + /// public class HiddenScriptEditor : UnityEditor.Editor { private static readonly string[] k_HiddenFields = { "m_Script" }; @@ -18,12 +21,18 @@ public override void OnInspectorGUI() } } + /// + /// Internal use. Hides the script field for UNetTransport. + /// [CustomEditor(typeof(UNetTransport), true)] public class UNetTransportEditor : HiddenScriptEditor { } + /// + /// Internal use. Hides the script field for UnityTransport. + /// [CustomEditor(typeof(UnityTransport), true)] public class UnityTransportEditor : HiddenScriptEditor { @@ -31,6 +40,9 @@ public class UnityTransportEditor : HiddenScriptEditor } #if COM_UNITY_MODULES_ANIMATION + /// + /// Internal use. Hides the script field for NetworkAnimator. + /// [CustomEditor(typeof(NetworkAnimator), true)] public class NetworkAnimatorEditor : HiddenScriptEditor { @@ -39,6 +51,9 @@ public class NetworkAnimatorEditor : HiddenScriptEditor #endif #if COM_UNITY_MODULES_PHYSICS + /// + /// Internal use. Hides the script field for NetworkRigidbody. + /// [CustomEditor(typeof(NetworkRigidbody), true)] public class NetworkRigidbodyEditor : HiddenScriptEditor { @@ -47,6 +62,9 @@ public class NetworkRigidbodyEditor : HiddenScriptEditor #endif #if COM_UNITY_MODULES_PHYSICS2D + /// + /// Internal use. Hides the script field for NetworkRigidbody2D. + /// [CustomEditor(typeof(NetworkRigidbody2D), true)] public class NetworkRigidbody2DEditor : HiddenScriptEditor { From 602a74acb6016b0477ad0908334e9cd83a6c7e08 Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Thu, 22 Sep 2022 12:55:52 -0500 Subject: [PATCH 9/9] Update package.json to 1.1.0 --- com.unity.netcode.gameobjects/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/package.json b/com.unity.netcode.gameobjects/package.json index 641a768117..75c3b561cb 100644 --- a/com.unity.netcode.gameobjects/package.json +++ b/com.unity.netcode.gameobjects/package.json @@ -2,7 +2,7 @@ "name": "com.unity.netcode.gameobjects", "displayName": "Netcode for GameObjects", "description": "Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.", - "version": "1.0.1", + "version": "1.1.0", "unity": "2020.3", "dependencies": { "com.unity.nuget.mono-cecil": "1.10.1",