From 0b69c9890d2a7de1f3a341d40a080fab55dc897e Mon Sep 17 00:00:00 2001 From: Alexander Filippov Date: Tue, 24 May 2022 20:08:16 +0200 Subject: [PATCH] Hide script field of netcode objects. --- Runtime/DefaultNetworkBehaviourEditor.cs | 37 +++++++++++++++++++ Runtime/DefaultNetworkBehaviourEditor.cs.meta | 11 ++++++ 2 files changed, 48 insertions(+) create mode 100644 Runtime/DefaultNetworkBehaviourEditor.cs create mode 100644 Runtime/DefaultNetworkBehaviourEditor.cs.meta diff --git a/Runtime/DefaultNetworkBehaviourEditor.cs b/Runtime/DefaultNetworkBehaviourEditor.cs new file mode 100644 index 0000000..0fe54e0 --- /dev/null +++ b/Runtime/DefaultNetworkBehaviourEditor.cs @@ -0,0 +1,37 @@ +#if UNITY_EDITOR && ENABLE_NETCODE +using Unity.Netcode; +using UnityEditor; +using UnityEngine; + +namespace Utils +{ + [CustomEditor(typeof(NetworkBehaviour), true)] + public class DefaultNetworkBehaviourEditor : Editor + { + private bool hideScriptField; + + private void OnEnable() + { + hideScriptField = target.GetType().GetCustomAttributes(typeof(HideScriptField), false).Length > 0; + } + + public override void OnInspectorGUI() + { + if (hideScriptField) + { + serializedObject.Update(); + EditorGUI.BeginChangeCheck(); + DrawPropertiesExcluding(serializedObject, "m_Script"); + if (EditorGUI.EndChangeCheck()) + { + serializedObject.ApplyModifiedProperties(); + } + } + else + { + base.OnInspectorGUI(); + } + } + } +} +#endif \ No newline at end of file diff --git a/Runtime/DefaultNetworkBehaviourEditor.cs.meta b/Runtime/DefaultNetworkBehaviourEditor.cs.meta new file mode 100644 index 0000000..90531b0 --- /dev/null +++ b/Runtime/DefaultNetworkBehaviourEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 759b9908922d8dc8caa70463cd752b98 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: