ReadOnlyDrawer.cs 559 B

123456789101112131415161718192021222324
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace HQFPSWeapons
  4. {
  5. [CustomPropertyDrawer(typeof(ReadOnly))]
  6. public class ReadOnlyDrawer : PropertyDrawer
  7. {
  8. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  9. {
  10. bool guiEnabled = GUI.enabled;
  11. GUI.enabled = false;
  12. EditorGUI.PropertyField(position, property, label);
  13. GUI.enabled = guiEnabled;
  14. }
  15. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  16. {
  17. return EditorGUI.GetPropertyHeight(property, true);
  18. }
  19. }
  20. }