Last active
December 21, 2016 07:56
-
-
Save jringrose/0f1d41f511c8baf272d8 to your computer and use it in GitHub Desktop.
Use this InspectorReadOnly attribute for public fields that you want to easily inspect in the editor without allowing modifications. InspectorReadOnlyDrawer needs to be inside an Editor folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
// Usage: | |
// | |
// [InspectorReadOnly] | |
// public float someValue = 5f; | |
// | |
public class InspectorReadOnly : PropertyAttribute { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
using UnityEditor; | |
[CustomPropertyDrawer(typeof(InspectorReadOnly))] | |
public class InspectorReadOnlyDrawer : PropertyDrawer { | |
override public float GetPropertyHeight(SerializedProperty property, GUIContent label){ | |
return EditorGUI.GetPropertyHeight(property, label, true); | |
} | |
override public void OnGUI(Rect position, SerializedProperty property, GUIContent label){ | |
GUI.enabled = false; | |
EditorGUI.PropertyField(position, property, label, true); | |
GUI.enabled = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment