Skip to content

Commit 566a410

Browse files
authored
fix: Remove "Script" fields from Netcode components in the inspector [MTT-2947] (#2172)
* fix: Remove "Script" fields from Netcode components in the inspector * Standards * standards again * Fix compile errors in minimalproject * Whoops, those version defines were for the runtime, had to add them to editor too. * validator...
1 parent 06f7302 commit 566a410

6 files changed

Lines changed: 101 additions & 15 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using Unity.Netcode.Components;
2+
using Unity.Netcode.Transports.UNET;
3+
using Unity.Netcode.Transports.UTP;
4+
using UnityEditor;
5+
6+
namespace Unity.Netcode.Editor
7+
{
8+
/// <summary>
9+
/// Internal use. Hides the script field for the given component.
10+
/// </summary>
11+
public class HiddenScriptEditor : UnityEditor.Editor
12+
{
13+
private static readonly string[] k_HiddenFields = { "m_Script" };
14+
public override void OnInspectorGUI()
15+
{
16+
EditorGUI.BeginChangeCheck();
17+
serializedObject.UpdateIfRequiredOrScript();
18+
DrawPropertiesExcluding(serializedObject, k_HiddenFields);
19+
serializedObject.ApplyModifiedProperties();
20+
EditorGUI.EndChangeCheck();
21+
}
22+
}
23+
24+
/// <summary>
25+
/// Internal use. Hides the script field for UNetTransport.
26+
/// </summary>
27+
[CustomEditor(typeof(UNetTransport), true)]
28+
public class UNetTransportEditor : HiddenScriptEditor
29+
{
30+
31+
}
32+
33+
/// <summary>
34+
/// Internal use. Hides the script field for UnityTransport.
35+
/// </summary>
36+
[CustomEditor(typeof(UnityTransport), true)]
37+
public class UnityTransportEditor : HiddenScriptEditor
38+
{
39+
40+
}
41+
42+
#if COM_UNITY_MODULES_ANIMATION
43+
/// <summary>
44+
/// Internal use. Hides the script field for NetworkAnimator.
45+
/// </summary>
46+
[CustomEditor(typeof(NetworkAnimator), true)]
47+
public class NetworkAnimatorEditor : HiddenScriptEditor
48+
{
49+
50+
}
51+
#endif
52+
53+
#if COM_UNITY_MODULES_PHYSICS
54+
/// <summary>
55+
/// Internal use. Hides the script field for NetworkRigidbody.
56+
/// </summary>
57+
[CustomEditor(typeof(NetworkRigidbody), true)]
58+
public class NetworkRigidbodyEditor : HiddenScriptEditor
59+
{
60+
61+
}
62+
#endif
63+
64+
#if COM_UNITY_MODULES_PHYSICS2D
65+
/// <summary>
66+
/// Internal use. Hides the script field for NetworkRigidbody2D.
67+
/// </summary>
68+
[CustomEditor(typeof(NetworkRigidbody2D), true)]
69+
public class NetworkRigidbody2DEditor : HiddenScriptEditor
70+
{
71+
72+
}
73+
#endif
74+
}

com.unity.netcode.gameobjects/Editor/HiddenScriptEditor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,6 @@ public override void OnInspectorGUI()
214214
DrawInstallMultiplayerToolsTip();
215215
#endif
216216

217-
{
218-
var iterator = serializedObject.GetIterator();
219-
220-
for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
221-
{
222-
using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath))
223-
{
224-
EditorGUILayout.PropertyField(iterator, false);
225-
}
226-
}
227-
}
228-
229217
if (!m_NetworkManager.IsServer && !m_NetworkManager.IsClient)
230218
{
231219
serializedObject.Update();

com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class NetworkObjectEditor : UnityEditor.Editor
1515
private NetworkObject m_NetworkObject;
1616
private bool m_ShowObservers;
1717

18+
private static readonly string[] k_HiddenFields = { "m_Script" };
19+
1820
private void Initialize()
1921
{
2022
if (m_Initialized)
@@ -95,7 +97,11 @@ public override void OnInspectorGUI()
9597
}
9698
else
9799
{
98-
base.OnInspectorGUI();
100+
EditorGUI.BeginChangeCheck();
101+
serializedObject.UpdateIfRequiredOrScript();
102+
DrawPropertiesExcluding(serializedObject, k_HiddenFields);
103+
serializedObject.ApplyModifiedProperties();
104+
EditorGUI.EndChangeCheck();
99105

100106
var guiEnabled = GUI.enabled;
101107
GUI.enabled = false;

com.unity.netcode.gameobjects/Editor/com.unity.netcode.editor.asmdef

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
"name": "com.unity.multiplayer.tools",
1414
"expression": "",
1515
"define": "MULTIPLAYER_TOOLS"
16+
},
17+
{
18+
"name": "com.unity.modules.animation",
19+
"expression": "",
20+
"define": "COM_UNITY_MODULES_ANIMATION"
21+
},
22+
{
23+
"name": "com.unity.modules.physics",
24+
"expression": "",
25+
"define": "COM_UNITY_MODULES_PHYSICS"
26+
},
27+
{
28+
"name": "com.unity.modules.physics2d",
29+
"expression": "",
30+
"define": "COM_UNITY_MODULES_PHYSICS2D"
1631
}
1732
]
18-
}
33+
}

com.unity.netcode.gameobjects/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.unity.netcode.gameobjects",
33
"displayName": "Netcode for GameObjects",
44
"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.",
5-
"version": "1.0.1",
5+
"version": "1.1.0",
66
"unity": "2020.3",
77
"dependencies": {
88
"com.unity.nuget.mono-cecil": "1.10.1",

0 commit comments

Comments
 (0)