-
Notifications
You must be signed in to change notification settings - Fork 460
fix: Remove "Script" fields from Netcode components in the inspector [MTT-2947] #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e44352d
21a5fd6
cf31912
ca62e87
2244781
9055ffb
afcc4e0
f57429f
6926754
23b2179
274673d
fee2b52
27dd28d
e74ff11
c940ec8
6dc626d
b02493f
4b9e33d
d39b139
2b51600
14e7d1f
6c34462
602a74a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| using Unity.Netcode.Components; | ||
| using Unity.Netcode.Transports.UNET; | ||
| using Unity.Netcode.Transports.UTP; | ||
| using UnityEditor; | ||
|
|
||
| namespace Unity.Netcode.Editor | ||
| { | ||
| /// <summary> | ||
| /// Internal use. Hides the script field for the given component. | ||
| /// </summary> | ||
| public class HiddenScriptEditor : UnityEditor.Editor | ||
| { | ||
| private static readonly string[] k_HiddenFields = { "m_Script" }; | ||
| public override void OnInspectorGUI() | ||
| { | ||
| EditorGUI.BeginChangeCheck(); | ||
| serializedObject.UpdateIfRequiredOrScript(); | ||
| DrawPropertiesExcluding(serializedObject, k_HiddenFields); | ||
| serializedObject.ApplyModifiedProperties(); | ||
| EditorGUI.EndChangeCheck(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Internal use. Hides the script field for UNetTransport. | ||
| /// </summary> | ||
| [CustomEditor(typeof(UNetTransport), true)] | ||
| public class UNetTransportEditor : HiddenScriptEditor | ||
| { | ||
|
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Internal use. Hides the script field for UnityTransport. | ||
| /// </summary> | ||
| [CustomEditor(typeof(UnityTransport), true)] | ||
| public class UnityTransportEditor : HiddenScriptEditor | ||
| { | ||
|
|
||
| } | ||
|
|
||
| #if COM_UNITY_MODULES_ANIMATION | ||
| /// <summary> | ||
| /// Internal use. Hides the script field for NetworkAnimator. | ||
| /// </summary> | ||
| [CustomEditor(typeof(NetworkAnimator), true)] | ||
| public class NetworkAnimatorEditor : HiddenScriptEditor | ||
| { | ||
|
|
||
| } | ||
| #endif | ||
|
|
||
| #if COM_UNITY_MODULES_PHYSICS | ||
| /// <summary> | ||
| /// Internal use. Hides the script field for NetworkRigidbody. | ||
| /// </summary> | ||
| [CustomEditor(typeof(NetworkRigidbody), true)] | ||
| public class NetworkRigidbodyEditor : HiddenScriptEditor | ||
| { | ||
|
|
||
| } | ||
| #endif | ||
|
|
||
| #if COM_UNITY_MODULES_PHYSICS2D | ||
| /// <summary> | ||
| /// Internal use. Hides the script field for NetworkRigidbody2D. | ||
| /// </summary> | ||
| [CustomEditor(typeof(NetworkRigidbody2D), true)] | ||
| public class NetworkRigidbody2DEditor : HiddenScriptEditor | ||
| { | ||
|
|
||
| } | ||
| #endif | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ public class NetworkObjectEditor : UnityEditor.Editor | |
| 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(); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated code... apparently one cannot add a class in between NetworkObjectEditor and Unity.Editor in the hierarchy without triggering a "public api change" error in the validator, so instead of being able to reuse this code, I have to copy/paste it... That's pretty silly IMO. |
||
| serializedObject.UpdateIfRequiredOrScript(); | ||
| DrawPropertiesExcluding(serializedObject, k_HiddenFields); | ||
| serializedObject.ApplyModifiedProperties(); | ||
| EditorGUI.EndChangeCheck(); | ||
|
|
||
| var guiEnabled = GUI.enabled; | ||
| GUI.enabled = false; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.