public override void ValidateProperty(SerializedProperty property) { ValidateInputAttribute validateInputAttribute = PropertyUtility.GetAttribute <ValidateInputAttribute>(property); UnityEngine.Object target = PropertyUtility.GetTargetObject(property); MethodInfo validationCallback = ReflectionUtility.GetMethod(target, validateInputAttribute.CallbackName); if (validationCallback != null && validationCallback.ReturnType == typeof(bool) && validationCallback.GetParameters().Length == 1) { FieldInfo fieldInfo = ReflectionUtility.GetField(target, property.name); Type fieldType = fieldInfo.FieldType; Type parameterType = validationCallback.GetParameters()[0].ParameterType; if (fieldType == parameterType) { if (!(bool)validationCallback.Invoke(target, new object[] { fieldInfo.GetValue(target) })) { if (string.IsNullOrEmpty(validateInputAttribute.Message)) { EditorDrawUtility.DrawHelpBox(property.name + " is not valid", MessageType.Error, logToConsole: true, context: target); } else { EditorDrawUtility.DrawHelpBox(validateInputAttribute.Message, MessageType.Error, logToConsole: true, context: target); } } } else { string warning = "The field type is not the same as the callback's parameter type"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: target); } } else { string warning = validateInputAttribute.GetType().Name + " needs a callback with boolean return type and a single parameter of the same type as the field"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: target); } }
public override void DrawField(UnityEngine.Object target, FieldInfo field) { object value = field.GetValue(target); if (value == null) { GUI.enabled = false; EditorGUILayout.ObjectField(field.Name, (Object)value, field.FieldType, true); GUI.enabled = true; //string warning = string.Format("{0} doesn't support {1} types", typeof(ShowNonSerializedFieldFieldDrawer).Name, "Reference"); //EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: target); } else if (!EditorDrawUtility.DrawLayoutField(value, field.Name)) { string warning = string.Format("{0} doesn't support {1} types", typeof(ShowNonSerializedFieldFieldDrawer).Name, field.FieldType.Name); EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: target); } }
public override void DrawMethod(UnityEngine.Object target, MethodInfo methodInfo) { if (methodInfo.GetParameters().Length == 0) { ButtonAttribute buttonAttribute = (ButtonAttribute)methodInfo.GetCustomAttributes(typeof(ButtonAttribute), true)[0]; string buttonText = string.IsNullOrEmpty(buttonAttribute.Text) ? methodInfo.Name : buttonAttribute.Text; if (GUILayout.Button(buttonText)) { methodInfo.Invoke(target, null); } } else { string warning = typeof(ButtonAttribute).Name + " works only on methods with no parameters"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: target); } }
public override void ApplyPropertyMeta(SerializedProperty property, MetaAttribute metaAttribute) { var infoBoxAttribute = (InfoBoxAttribute)metaAttribute; var target = PropertyUtility.GetTargetObject(property); if (!string.IsNullOrEmpty(infoBoxAttribute.VisibleIf)) { var conditionField = ReflectionUtility.GetField(target, infoBoxAttribute.VisibleIf); if (conditionField != null && conditionField.FieldType == typeof(bool)) { if ((bool)conditionField.GetValue(target)) { DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type); } return; } var conditionMethod = ReflectionUtility.GetMethod(target, infoBoxAttribute.VisibleIf); if (conditionMethod != null && conditionMethod.ReturnType == typeof(bool) && conditionMethod.GetParameters().Length == 0) { if ((bool)conditionMethod.Invoke(target, null)) { DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type); } return; } var warning = infoBoxAttribute.GetType().Name + " needs a valid boolean condition field or method name to work"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, PropertyUtility.GetTargetObject(property)); } else { DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type); } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); if (property.isArray) { var key = GetPropertyKeyName(property); if (!this.reorderableListsByPropertyName.ContainsKey(key)) { ReorderableList reorderableList = new ReorderableList(property.serializedObject, property, true, true, true, true) { drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, string.Format("{0}: {1}", property.displayName, property.arraySize), EditorStyles.label); }, drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var element = property.GetArrayElementAtIndex(index); rect.y += 1.0f; rect.x += 10.0f; rect.width -= 10.0f; EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, 0.0f), element, true); }, elementHeightCallback = (int index) => { return(EditorGUI.GetPropertyHeight(property.GetArrayElementAtIndex(index)) + 4.0f); } }; this.reorderableListsByPropertyName[key] = reorderableList; } this.reorderableListsByPropertyName[key].DoLayoutList(); } else { string warning = typeof(ReorderableListAttribute).Name + " can be used only on arrays or lists"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }
public override void DrawField(Object target, FieldInfo field) { var value = field.GetValue(target); if (value == null) { var warning = string.Format("{0} doesn't support {1} types", typeof(ShowNonSerializedFieldFieldDrawer).Name, "Reference"); EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, target); } else if (!EditorDrawUtility.DrawLayoutField(value, field.Name)) { var warning = string.Format("{0} doesn't support {1} types", typeof(ShowNonSerializedFieldFieldDrawer).Name, field.FieldType.Name); EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, target); } }
public override void ApplyPropertyMeta(SerializedProperty property, MetaAttribute metaAttribute, bool drawField) { InfoBoxAttribute infoBoxAttribute = (InfoBoxAttribute)metaAttribute; UnityEngine.Object target = PropertyUtility.GetTargetObject(property); if (!string.IsNullOrEmpty(infoBoxAttribute.VisibleIf)) { FieldInfo conditionField = ReflectionUtility.GetField(target, infoBoxAttribute.VisibleIf); if (conditionField != null && conditionField.FieldType == typeof(bool)) { if ((bool)conditionField.GetValue(target)) { this.DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type); } return; } MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, infoBoxAttribute.VisibleIf); if (conditionMethod != null && conditionMethod.ReturnType == typeof(bool) && conditionMethod.GetParameters().Length == 0) { if ((bool)conditionMethod.Invoke(target, null)) { this.DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type); } return; } string warning = infoBoxAttribute.GetType().Name + " needs a valid boolean condition field or method name to work"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: PropertyUtility.GetTargetObject(property)); } else if (!infoBoxAttribute.HideWithField || (drawField && infoBoxAttribute.HideWithField)) { this.DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type); } }
public override bool CanDrawProperty(SerializedProperty property) { HideIfAnyAttribute[] hideIfAnyAttributes = PropertyUtility.GetAttributes <HideIfAnyAttribute>(property); UnityEngine.Object target = PropertyUtility.GetTargetObject(property); foreach (var attribute in hideIfAnyAttributes) { FieldInfo conditionField = ReflectionUtility.GetField(target, attribute.ConditionName); if (conditionField != null && conditionField.FieldType == typeof(bool)) { if ((bool)conditionField.GetValue(target) == attribute.ConditionValue) { return(false); } else { continue; } } MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, attribute.ConditionName); if (conditionMethod != null && conditionMethod.ReturnType == typeof(bool) && conditionMethod.GetParameters().Length == 0) { if ((bool)conditionMethod.Invoke(target, null) == attribute.ConditionValue) { return(false); } else { continue; } } string warning = attribute.GetType().Name + " needs a valid boolean condition field or method name to work"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: target); } return(true); }
public override void DrawNativeProperty(UnityEngine.Object target, PropertyInfo property) { try { object value = property.GetValue(target, null); if (!EditorDrawUtility.DrawLayoutField(value, ObjectNames.NicifyVariableName(property.Name), property.PropertyType)) { string warning = string.Format("{0} doesn't support {1} types", typeof(ShowNativePropertyNativePropertyDrawer).Name, property.PropertyType.Name); EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: target); } } catch (Exception e) { EditorDrawUtility.DrawHelpBox("Error: " + e, MessageType.Error, logToConsole: true, context: target); } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); var sliderAttribute = PropertyUtility.GetAttribute <SliderAttribute>(property); if (property.propertyType == SerializedPropertyType.Integer) { EditorGUILayout.IntSlider(property, (int)sliderAttribute.MinValue, (int)sliderAttribute.MaxValue); } else if (property.propertyType == SerializedPropertyType.Float) { EditorGUILayout.Slider(property, sliderAttribute.MinValue, sliderAttribute.MaxValue); } else { var warning = sliderAttribute.GetType().Name + " can be used only on int or float fields"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }
public override void DrawNativeProperty(Object target, PropertyInfo property) { var value = property.GetValue(target, null); if (value == null) { var warning = string.Format("{0} doesn't support {1} types", typeof(ShowNativePropertyNativePropertyDrawer).Name, "Reference"); EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, target); } else if (!EditorDrawUtility.DrawLayoutField(value, property.Name)) { var warning = string.Format("{0} doesn't support {1} types", typeof(ShowNativePropertyNativePropertyDrawer).Name, property.PropertyType.Name); EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, target); } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); if (property.isArray) { var key = GetPropertyKeyName(property); if (!reorderableListsByPropertyName.ContainsKey(key)) { var reorderableList = new ReorderableList(property.serializedObject, property, true, true, true, true) { drawHeaderCallback = rect => { EditorGUI.LabelField( rect, string.Format("{0}: {1}", property.displayName, property.arraySize), EditorStyles.label); }, drawElementCallback = (rect, index, isActive, isFocused) => { var element = property.GetArrayElementAtIndex(index); rect.y += 2f; EditorGUI.PropertyField( new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element); } }; reorderableListsByPropertyName[key] = reorderableList; } reorderableListsByPropertyName[key].DoLayoutList(); } else { var warning = typeof(ReorderableListAttribute).Name + " can be used only on arrays or lists"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }
public override void DrawProperty(SerializedProperty property) { bool drawDisabled = false; bool validCondition = false; DisableIfAttribute disableIfAttribute = PropertyUtility.GetAttribute <DisableIfAttribute>(property); UnityEngine.Object target = PropertyUtility.GetTargetObject(property); FieldInfo conditionField = ReflectionUtility.GetField(target, disableIfAttribute.ConditionName); if (conditionField != null && conditionField.FieldType == typeof(bool)) { drawDisabled = (bool)conditionField.GetValue(target); validCondition = true; } MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, disableIfAttribute.ConditionName); if (conditionMethod != null && conditionMethod.ReturnType == typeof(bool) && conditionMethod.GetParameters().Length == 0) { drawDisabled = (bool)conditionMethod.Invoke(target, null); validCondition = true; } if (validCondition) { GUI.enabled = !drawDisabled; EditorDrawUtility.DrawPropertyField(property); GUI.enabled = true; } else { string warning = disableIfAttribute.GetType().Name + " needs a valid boolean condition field or method name to work"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: target); } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); var attr = PropertyUtility.GetAttribute <SceneReferenceOnlyAttribute>(property); var type = this.FieldInfo.FieldType; var target = property.serializedObject.targetObject; if (target is Component) { var targetGo = (target as Component).gameObject; if (typeof(GameObject).IsAssignableFrom(type)) { var obj = (GameObject)EditorGUILayout.ObjectField(property.displayName, property.objectReferenceValue, this.FieldInfo.FieldType, true); if (obj == null || obj.scene == targetGo.scene) { property.objectReferenceValue = obj; } else { Debug.LogWarning($"{obj.name} is not in the same scene[{targetGo.scene.name}] with {targetGo.name}", obj); } return; } else if (typeof(Component).IsAssignableFrom(type)) { var obj = (Component)EditorGUILayout.ObjectField(property.displayName, property.objectReferenceValue, this.FieldInfo.FieldType, true); if (obj == null || obj.gameObject.scene == targetGo.scene) { property.objectReferenceValue = obj; } else { Debug.LogWarning($"{obj.name} is not in the same scene[{targetGo.scene.name}] with {targetGo.name}", obj); } return; } } EditorDrawUtility.DrawHelpBox($"Field={this.FieldInfo.Name} Type={this.FieldInfo.FieldType.Name} {nameof(SceneReferenceOnlyAttribute)} can only be used on GameObject or Component fields of UnityEngine.Component", MessageType.Warning, context: PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); var attr = PropertyUtility.GetAttribute <PrefabOnlyAttribute>(property); var type = this.FieldInfo.FieldType; var target = property.serializedObject.targetObject; if (target is Component) { var parent = (target as Component).transform; if (typeof(GameObject).IsAssignableFrom(type)) { var obj = (GameObject)EditorGUILayout.ObjectField(property.displayName, property.objectReferenceValue, this.FieldInfo.FieldType, true); if (obj == null || obj.transform.IsChildOf(parent)) { property.objectReferenceValue = obj; } else { Debug.LogWarning($"{obj.name} is not child of {parent.name} thus can not be used", obj); } return; } else if (typeof(Component).IsAssignableFrom(type)) { var obj = (Component)EditorGUILayout.ObjectField(property.displayName, property.objectReferenceValue, this.FieldInfo.FieldType, true); if (obj == null || obj.transform.IsChildOf(parent)) { property.objectReferenceValue = obj; } else { Debug.LogWarning($"{obj.name} is not child of {parent.name} thus can not be used", obj); } return; } } EditorDrawUtility.DrawHelpBox($"Field={this.FieldInfo.Name} Type={this.FieldInfo.FieldType.Name} {nameof(TranformChildOnlyAttribute)} can only be used on GameObject or Component fields of UnityEngine.Component", MessageType.Warning, context: PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); }
public override void ValidateProperty(SerializedProperty property) { RequiredAttribute requiredAttribute = PropertyUtility.GetAttribute <RequiredAttribute>(property); if (property.propertyType == SerializedPropertyType.ObjectReference) { if (property.objectReferenceValue == null) { string errorMessage = property.name + " is required"; if (!string.IsNullOrEmpty(requiredAttribute.Message)) { errorMessage = requiredAttribute.Message; } EditorDrawUtility.DrawHelpBox(errorMessage, MessageType.Error, context: PropertyUtility.GetTargetObject(property)); } } else { string warning = requiredAttribute.GetType().Name + " works only on reference types"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: PropertyUtility.GetTargetObject(property)); } }
public override void ValidateProperty(SerializedProperty property) { MaxValueAttribute maxValueAttribute = PropertyUtility.GetAttribute <MaxValueAttribute>(property); if (property.propertyType == SerializedPropertyType.Integer) { if (property.intValue > maxValueAttribute.MaxValue) { property.intValue = (int)maxValueAttribute.MaxValue; } } else if (property.propertyType == SerializedPropertyType.Float) { if (property.floatValue > maxValueAttribute.MaxValue) { property.floatValue = maxValueAttribute.MaxValue; } } else { string warning = maxValueAttribute.GetType().Name + " can be used only on int or float fields"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: PropertyUtility.GetTargetObject(property)); } }
public override bool CanDrawProperty(SerializedProperty property) { ShowIfAttribute showIfAttribute = PropertyUtility.GetAttribute <ShowIfAttribute>(property); UnityEngine.Object target = PropertyUtility.GetTargetObject(property); List <bool> conditionValues = new List <bool>(); foreach (var condition in showIfAttribute.Conditions) { FieldInfo conditionField = ReflectionUtility.GetField(target, condition); if (conditionField != null && conditionField.FieldType == typeof(bool)) { conditionValues.Add((bool)conditionField.GetValue(target)); } MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, condition); if (conditionMethod != null && conditionMethod.ReturnType == typeof(bool) && conditionMethod.GetParameters().Length == 0) { conditionValues.Add((bool)conditionMethod.Invoke(target, null)); } } if (conditionValues.Count > 0) { bool draw; if (showIfAttribute.ConditionOperator == ConditionOperator.And) { draw = true; foreach (var value in conditionValues) { draw = draw && value; } } else { draw = false; foreach (var value in conditionValues) { draw = draw || value; } } if (showIfAttribute.Reversed) { draw = !draw; } return(draw); } else { string warning = showIfAttribute.GetType().Name + " needs a valid boolean condition field or method name to work"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: target); return(true); } }
public override void DrawMethod(UnityEngine.Object target, MethodInfo methodInfo) { ButtonIfAttribute buttonIfAttribute = (ButtonIfAttribute)methodInfo.GetCustomAttributes(typeof(ButtonIfAttribute), true)[0]; List <bool> conditionValues = new List <bool>(); foreach (var condition in buttonIfAttribute.Conditions) { //Debug.Log("condition: " + condition); FieldInfo conditionField = ReflectionUtility.GetField(target, condition); if (conditionField != null && conditionField.FieldType == typeof(bool)) { conditionValues.Add((bool)conditionField.GetValue(target)); } MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, condition); if (conditionMethod != null && conditionMethod.ReturnType == typeof(bool) && conditionMethod.GetParameters().Length == 0) { //Debug.Log("method found: " + condition); conditionValues.Add((bool)conditionMethod.Invoke(target, null)); } } bool enabled = false; if (conditionValues.Count > 0) { if (buttonIfAttribute.ConditionOperator == ConditionOperator.And) { enabled = true; foreach (var value in conditionValues) { enabled = enabled && value; } } else { enabled = false; foreach (var value in conditionValues) { enabled = enabled || value; } } if (buttonIfAttribute.Reversed) { enabled = !enabled; } } else { string warning = buttonIfAttribute.GetType().Name + " needs a valid boolean condition field or method name to work"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: target); return; } if (methodInfo.GetParameters().Length == 0) { string buttonText = string.IsNullOrEmpty(buttonIfAttribute.Text) ? methodInfo.Name : buttonIfAttribute.Text; GUI.enabled = enabled; if (GUILayout.Button(buttonText)) { methodInfo.Invoke(target, null); } GUI.enabled = true; if (!enabled) { string infoText = "Preconditions for " + buttonText + ":"; for (int ix = 0; ix < conditionValues.Count; ix++) { infoText += "\n "; if (ix > 0) { infoText += buttonIfAttribute.ConditionOperator + " "; } infoText += buttonIfAttribute.Conditions[ix]; infoText += " (" + conditionValues[ix] + ")"; } EditorGUILayout.HelpBox(infoText, MessageType.Info); } } else { string warning = typeof(ButtonIfAttribute).Name + " works only on methods with no parameters"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: target); } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); var minMaxSliderAttribute = PropertyUtility.GetAttribute <MinMaxSliderAttribute>(property); if (property.propertyType == SerializedPropertyType.Vector2) { var controlRect = EditorGUILayout.GetControlRect(); var labelWidth = EditorGUIUtility.labelWidth; var floatFieldWidth = EditorGUIUtility.fieldWidth; var sliderWidth = controlRect.width - labelWidth - 2f * floatFieldWidth; var sliderPadding = 5f; var labelRect = new Rect( controlRect.x, controlRect.y, labelWidth, controlRect.height); var sliderRect = new Rect( controlRect.x + labelWidth + floatFieldWidth + sliderPadding, controlRect.y, sliderWidth - 2f * sliderPadding, controlRect.height); var minFloatFieldRect = new Rect( controlRect.x + labelWidth, controlRect.y, floatFieldWidth, controlRect.height); var maxFloatFieldRect = new Rect( controlRect.x + labelWidth + floatFieldWidth + sliderWidth, controlRect.y, floatFieldWidth, controlRect.height); // Draw the label EditorGUI.LabelField(labelRect, property.displayName); // Draw the slider EditorGUI.BeginChangeCheck(); var sliderValue = property.vector2Value; EditorGUI.MinMaxSlider(sliderRect, ref sliderValue.x, ref sliderValue.y, minMaxSliderAttribute.MinValue, minMaxSliderAttribute.MaxValue); sliderValue.x = EditorGUI.FloatField(minFloatFieldRect, sliderValue.x); sliderValue.x = Mathf.Clamp(sliderValue.x, minMaxSliderAttribute.MinValue, Mathf.Min(minMaxSliderAttribute.MaxValue, sliderValue.y)); sliderValue.y = EditorGUI.FloatField(maxFloatFieldRect, sliderValue.y); sliderValue.y = Mathf.Clamp(sliderValue.y, Mathf.Max(minMaxSliderAttribute.MinValue, sliderValue.x), minMaxSliderAttribute.MaxValue); if (EditorGUI.EndChangeCheck()) { property.vector2Value = sliderValue; } } else { var warning = minMaxSliderAttribute.GetType().Name + " can be used only on Vector2 fields"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }
private void DisplayWarning(string message) { EditorDrawUtility.DrawHelpBox(message, MessageType.Error, logToConsole: true, context: PropertyUtility.GetTargetObject(property)); }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); if (property.isArray) { if (!this.reorderableListsByPropertyName.ContainsKey(property.name)) { ReorderableList reorderableList = new ReorderableList(property.serializedObject, property, true, true, true, true) { drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var element = property.GetArrayElementAtIndex(index); rect.y += 2f; EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element); } }; reorderableList.drawHeaderCallback = (Rect rect) => { property.isExpanded = EditorGUI.Foldout(rect, property.isExpanded, string.Format("{0} [{1}]", property.displayName, property.arraySize)); Rect rect2 = rect; if (reorderableList.count == 0) { rect2.height = (rect2.height * 3f); } Event current = Event.current; EventType type = current.type; if (type != EventType.DragExited) { if (type == EventType.DragUpdated || type == EventType.DragPerform) { if (rect2.Contains(current.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (current.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); Object[] objectReferences = DragAndDrop.objectReferences; for (int i = 0; i < objectReferences.Length; i++) { Object obj = objectReferences[i]; AddElement(property, obj); } } } } } else { DragAndDrop.PrepareStartDrag(); } // EditorGUI.LabelField(rect, string.Format("{0}: {1}", property.displayName, property.arraySize), EditorStyles.label); }; this.reorderableListsByPropertyName[property.name] = reorderableList; } if (property.isExpanded) { this.reorderableListsByPropertyName[property.name].DoLayoutList(); } else { property.isExpanded = (EditorGUILayout.Foldout(property.isExpanded, new GUIContent(string.Format("{0} [{1}]", property.displayName, property.arraySize), property.tooltip))); } } else { string warning = typeof(ReorderableListAttribute).Name + " can be used only on arrays or lists"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }
public override void DrawProperty(SerializedProperty property) { EnableIfAttribute enableIfAttribute = PropertyUtility.GetAttribute <EnableIfAttribute>(property); UnityEngine.Object target = PropertyUtility.GetTargetObject(property); List <bool> conditionValues = new List <bool>(); foreach (var condition in enableIfAttribute.Conditions) { FieldInfo conditionField = ReflectionUtility.GetField(target, condition); if (conditionField?.FieldType == typeof(bool)) { conditionValues.Add((bool)conditionField.GetValue(target)); } MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, condition); if (conditionMethod?.ReturnType == typeof(bool) && conditionMethod.GetParameters().Length == 0) { conditionValues.Add((bool)conditionMethod.Invoke(target, null)); } PropertyInfo conditionProperty = ReflectionUtility.GetProperty(target, condition); if (conditionProperty?.PropertyType == typeof(bool)) { conditionValues.Add((bool)conditionProperty.GetValue(target)); } } if (conditionValues.Count > 0) { bool enabled; if (enableIfAttribute.ConditionOperator == ConditionOperator.And) { enabled = true; foreach (var value in conditionValues) { enabled = enabled && value; } } else { enabled = false; foreach (var value in conditionValues) { enabled = enabled || value; } } if (enableIfAttribute.Reversed) { enabled = !enabled; } GUI.enabled = enabled; EditorDrawUtility.DrawPropertyField(property); GUI.enabled = true; } else { string warning = enableIfAttribute.GetType().Name + " needs a valid boolean condition field or method name to work"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: target); } }