Namespace: | Sirenix.OdinInspector |
Assembly: | Sirenix.OdinInspector.Attributes |
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = false, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class ReadOnlyAttribute : Attribute, _Attribute
ReadOnly is used on any property, and prevents the property from being changed in the inspector.
Use this for when you want to see the value of a property in the inspector, but don't want it to be changed.
This attribute only affects the inspector! Values can still be changed by script.
The following example shows how a field can be displayed in the editor, but not be editable.
public class Health : MonoBehaviour
{
public int MaxHealth;
[ReadOnly]
public int CurrentHealth;
}
ReadOnly can also be combined with ShowInInspectorAttribute.
public class Health : MonoBehaviour
{
public int MaxHealth;
[ShowInInspector, ReadOnly]
private int currentHealth;
}
public ReadOnlyAttribute()