Created
December 12, 2018 06:16
-
-
Save samizzo/9a691209cf2c997523fd8ba18db3579e to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
public class ReadOnlyAttribute : PropertyAttribute | |
{ | |
} | |
#if UNITY_EDITOR | |
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))] | |
public class ReadOnlyFieldDrawer : PropertyDrawer | |
{ | |
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) | |
{ | |
return EditorGUI.GetPropertyHeight(property, label, true); | |
} | |
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | |
{ | |
var guiEnabled = GUI.enabled; | |
GUI.enabled = false; | |
EditorGUI.PropertyField(position, property, label, true); | |
GUI.enabled = guiEnabled; | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example: