Read Only Attribute for Unity (just mark stuff as [ReadOnly] the same way you would use [HideInInspector])
using UnityEngine; | |
using System; | |
using System.Reflection; | |
using System.Text.RegularExpressions; | |
[AttributeUsage (AttributeTargets.Field,Inherited = true)] | |
public class ReadOnlyAttribute : PropertyAttribute {} | |
#if UNITY_EDITOR | |
[UnityEditor.CustomPropertyDrawer (typeof(ReadOnlyAttribute))] | |
public class ReadOnlyAttributeDrawer : UnityEditor.PropertyDrawer | |
{ | |
public override void OnGUI(Rect rect, UnityEditor.SerializedProperty prop, GUIContent label) | |
{ | |
bool wasEnabled = GUI.enabled; | |
GUI.enabled = false; | |
UnityEditor.EditorGUI.PropertyField(rect,prop); | |
GUI.enabled = wasEnabled; | |
} | |
} | |
#endif |
This comment has been minimized.
This comment has been minimized.
nico202
commented
Feb 18, 2019
Hi, what's the license of ReadOnlyAttribute.cs? Thanks, Nicolò |
This comment has been minimized.
This comment has been minimized.
Yolo-Jerome
commented
Apr 2, 2019
Unfortunately it doesn't fully work for Lists:
The most "dangerous" value to change is till available. And it especially doesn't work for nested elements: where the elements are of type
also if it is not in a list like
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Flavelius commentedMay 3, 2018
•
edited
UnityEditor.EditorGUI.PropertyField(rect,prop, true); //to include children