-
-
Save Kuuo/7efcc8e4038cbf44816588ad2e19b292 to your computer and use it in GitHub Desktop.
ReadOnly property drawer for Unity~ Add a [ReadOnly] attribute to a property to make it show up as read only in the inspector
This file contains hidden or 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
| // NOTE DONT put in an editor folder | |
| using UnityEngine; | |
| public class ReadOnlyAttribute : PropertyAttribute { } |
This file contains hidden or 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
| // NOTE put in a Editor folder | |
| using UnityEngine; | |
| using UnityEditor; | |
| using System.Collections; | |
| [CustomPropertyDrawer(typeof(ReadOnlyAttribute))] | |
| public class ReadOnlyPropertyDrawer : PropertyDrawer | |
| { | |
| public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | |
| { | |
| GUI.enabled = false; | |
| EditorGUI.PropertyField(position, property, label); | |
| GUI.enabled = true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment