Skip to content

Instantly share code, notes, and snippets.

@capnslipp
Last active April 12, 2022 09:39
Show Gist options
  • Save capnslipp/8138106 to your computer and use it in GitHub Desktop.
Save capnslipp/8138106 to your computer and use it in GitHub Desktop.
Unity HideInNormalInspector attribute
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: HideInNormalInspector attribute, to hide fields in the normal Inspector but let them show in the debug Inspector.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Add `[HideInNormalInspector]` as an attribute to public fields you'd like hidden when Unity's Inspector is in “Normal” mode, but visible when in “Debug” mode.
/// @intended project path: Assets/Plugins/EditorUtils/HideInNormalInspectorAttribute.cs
/// @interwebsouce: https://gist.github.com/capnslipp/8138106
using UnityEngine;
public class HideInNormalInspectorAttribute : PropertyAttribute {}
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: HideInNormalInspector attribute, to hide fields in the normal Inspector but let them show in the debug Inspector.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Add `[HideInNormalInspector]` as an attribute to public fields you'd like hidden when Unity's Inspector is in “Normal” mode, but visible when in “Debug” mode.
/// @intended project path: Assets/Plugins/Editor/EditorUtils/HideInNormalInspectorDrawer.cs
/// @interwebsouce: https://gist.github.com/capnslipp/8138106
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(HideInNormalInspectorAttribute))]
class HideInNormalInspectorDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
return 0f;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {}
}
@mikelortega
Copy link

That's very interesting, but caution, it won't show elements in the editor with SerializedProperty serializedObject PropertyField, which is interesting to use with the new prefab workflow. Do you have any idea for a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment