Skip to content

Instantly share code, notes, and snippets.

@hiyorin hiyorin/Example.cs
Last active Oct 19, 2015

Embed
What would you like to do?
ReadOnlyAttribute
using UnityEngine;
public class Example : MonoBehaviour
{
[SerializeFiled, ReadOnlyAttribute]
private int value = 0;
[SerializeFiled, ReadOnlyAttribute]
private string[] array = null;
}
using UnityEngine;
public class ReadOnlyAttribute : PropertyAttribute
{
}
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
You can’t perform that action at this time.