Meetes

Untitled

May 1st, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. /// <summary>
  5. ///
  6. /// </summary>
  7. /// <see>https://answers.unity.com/questions/489942/how-to-make-a-readonly-property-in-inspector.html</see>
  8.  public class ReadOnlyAttribute : PropertyAttribute
  9.  {
  10.  
  11.  }
  12.  
  13.  [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
  14.  public class ReadOnlyDrawer : PropertyDrawer
  15.  {
  16.      public override float GetPropertyHeight(SerializedProperty property,
  17.                                              GUIContent label)
  18.      {
  19.          return EditorGUI.GetPropertyHeight(property, label, true);
  20.      }
  21.  
  22.      public override void OnGUI(Rect position,
  23.                                 SerializedProperty property,
  24.                                 GUIContent label)
  25.      {
  26.          GUI.enabled = false;
  27.          EditorGUI.PropertyField(position, property, label, true);
  28.          GUI.enabled = true;
  29.      }
  30.  }
Add Comment
Please, Sign In to add comment