Skip to content

Instantly share code, notes, and snippets.

@Trissiklikk
Last active March 4, 2024 05:45
Show Gist options
  • Save Trissiklikk/17a4b45d772604cfe854a396fd5a0f86 to your computer and use it in GitHub Desktop.
Save Trissiklikk/17a4b45d772604cfe854a396fd5a0f86 to your computer and use it in GitHub Desktop.
Unity : ReadOnlyAttribute
using UnityEngine;
public class ReadOnlyAttribute : PropertyAttribute
{
}
using UnityEditor;
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public sealed class ReadOnlyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = false;
EditorGUI.PropertyField(position, property, label, true);
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment