Skip to content

Instantly share code, notes, and snippets.

@CapitanLiteral
Last active January 22, 2019 15:48
Show Gist options
  • Save CapitanLiteral/ae9c6a1e6bfcf4b10222774657ab1e77 to your computer and use it in GitHub Desktop.
Save CapitanLiteral/ae9c6a1e6bfcf4b10222774657ab1e77 to your computer and use it in GitHub Desktop.
[ReadOnly] field;
using UnityEngine;
public class ReadOnlyAttribute : PropertyAttribute
{
}
// Put it inside Editor folder
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyDrawer : 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)
{
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