5 namespace AVR.Core.Attributes {
6 [CustomPropertyDrawer(typeof(
ReadOnly))]
9 public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
10 return EditorGUI.GetPropertyHeight(property, label,
true);
13 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
15 EditorGUI.PropertyField(position, property, label,
true);
20 [CustomPropertyDrawer(typeof(FoldoutGroup))]
22 private static bool last_foldout =
false;
26 private static string? last_group = null;
29 private static string? prop_reference = null;
33 private static Object obj_reference = null;
35 private bool foldout =
false;
42 private void NewGroup(
string group_name, SerializedProperty prop) {
43 last_group = group_name;
46 foldout = EditorGUILayout.Foldout(foldout, group_name);
47 EditorGUI.indentLevel++;
48 if (foldout) EditorGUILayout.PropertyField(prop,
new GUIContent(prop.displayName));
49 EditorGUI.indentLevel--;
51 last_foldout = foldout;
57 EditorGUI.indentLevel++;
58 EditorGUILayout.PropertyField(prop,
new GUIContent(prop.displayName));
59 EditorGUI.indentLevel--;
61 foldout = last_foldout;
64 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
68 if(obj_reference==null) obj_reference = property.serializedObject.targetObject;
69 else if(obj_reference!=property.serializedObject.targetObject) {
70 prop_reference = null;
72 obj_reference = property.serializedObject.targetObject;
77 if(prop_reference==null) prop_reference = property.name;
78 else if(prop_reference==property.name) {
89 ContinuationGroup(property);
94 [CustomPropertyDrawer(typeof(ConditionalHideInInspector))]
108 return propertyHeight;
111 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
117 SerializedProperty prop = property.serializedObject.FindProperty(attr.hideConditionPropertyName);
122 if(prop.type==
"bool") {
123 val = prop.boolValue;
125 else if(prop.type==
"float") {
127 attr.ctype == ct.BIGGEREQUAL && prop.floatValue >= attr.compareValue ||
128 attr.ctype == ct.BIGGER && prop.floatValue > attr.compareValue ||
129 attr.ctype == ct.SMALLEREQUAL && prop.floatValue <= attr.compareValue ||
130 attr.ctype == ct.SMALLER && prop.floatValue < attr.compareValue ||
131 attr.ctype == ct.EQUAL && prop.floatValue == attr.compareValue ||
132 attr.ctype == ct.UNEQUAL && prop.floatValue != attr.compareValue;
134 else if (prop.type ==
"int") {
136 attr.ctype == ct.BIGGEREQUAL && prop.intValue >= attr.compareValue ||
137 attr.ctype == ct.BIGGER && prop.intValue > attr.compareValue ||
138 attr.ctype == ct.SMALLEREQUAL && prop.intValue <= attr.compareValue ||
139 attr.ctype == ct.SMALLER && prop.intValue < attr.compareValue ||
140 attr.ctype == ct.EQUAL && prop.intValue == attr.compareValue ||
141 attr.ctype == ct.UNEQUAL && prop.intValue != attr.compareValue;
143 else if (prop.type ==
"double") {
145 attr.ctype == ct.BIGGEREQUAL && prop.doubleValue >= attr.compareValue ||
146 attr.ctype == ct.BIGGER && prop.doubleValue > attr.compareValue ||
147 attr.ctype == ct.SMALLEREQUAL && prop.doubleValue <= attr.compareValue ||
148 attr.ctype == ct.SMALLER && prop.doubleValue < attr.compareValue ||
149 attr.ctype == ct.EQUAL && prop.doubleValue == attr.compareValue ||
150 attr.ctype == ct.UNEQUAL && prop.doubleValue != attr.compareValue;
152 else if (prop.type ==
"long") {
154 attr.ctype == ct.BIGGEREQUAL && prop.longValue >= attr.compareValue ||
155 attr.ctype == ct.BIGGER && prop.longValue > attr.compareValue ||
156 attr.ctype == ct.SMALLEREQUAL && prop.longValue <= attr.compareValue ||
157 attr.ctype == ct.SMALLER && prop.longValue < attr.compareValue ||
158 attr.ctype == ct.EQUAL && prop.longValue == attr.compareValue ||
159 attr.ctype == ct.UNEQUAL && prop.longValue != attr.compareValue;
161 else if (prop.type ==
"Enum") {
163 attr.ctype == ct.BIGGEREQUAL && prop.enumValueIndex >= attr.compareValue ||
164 attr.ctype == ct.BIGGER && prop.enumValueIndex > attr.compareValue ||
165 attr.ctype == ct.SMALLEREQUAL && prop.enumValueIndex <= attr.compareValue ||
166 attr.ctype == ct.SMALLER && prop.enumValueIndex < attr.compareValue ||
167 attr.ctype == ct.EQUAL && prop.enumValueIndex == attr.compareValue ||
168 attr.ctype == ct.UNEQUAL && prop.enumValueIndex != attr.compareValue;
171 val = prop.objectReferenceValue != null;
174 val ^= attr.invertCondition;
185 propertyHeight = base.GetPropertyHeight(property, label);
186 EditorGUI.PropertyField(position, property,
new GUIContent(property.displayName));
void ContinuationGroup(SerializedProperty prop)
SerializedProperty hideConditionProperty
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
override float GetPropertyHeight(SerializedProperty property, GUIContent label)
Makes a field read-only in the inspector
Assigns given attributes to a foldout group in the inspector. The way these are drawn is determined b...
ConditionalHideInInspector attr
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
Allows for simple hiding of properties in the UnityEditor depending on certain conditions. For instance, in the following example the "type" field will only be displayed in the inspector if the "tracking" field is set to true:
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
override float GetPropertyHeight(SerializedProperty property, GUIContent label)
void NewGroup(string group_name, SerializedProperty prop)
override float GetPropertyHeight(SerializedProperty property, GUIContent label)