private object GetMaxValue(SerializedProperty property, ProgressBarAttribute progressBarAttribute) { if (string.IsNullOrEmpty(progressBarAttribute.MaxValueName)) { return(progressBarAttribute.MaxValue); } else { object target = PropertyUtility.GetTargetObjectWithProperty(property); FieldInfo valuesFieldInfo = ReflectionUtility.GetField(target, progressBarAttribute.MaxValueName); if (valuesFieldInfo != null) { return(valuesFieldInfo.GetValue(target)); } PropertyInfo valuesPropertyInfo = ReflectionUtility.GetProperty(target, progressBarAttribute.MaxValueName); if (valuesPropertyInfo != null) { return(valuesPropertyInfo.GetValue(target)); } MethodInfo methodValuesInfo = ReflectionUtility.GetMethod(target, progressBarAttribute.MaxValueName); if (methodValuesInfo != null && (methodValuesInfo.ReturnType == typeof(float) || methodValuesInfo.ReturnType == typeof(int)) && methodValuesInfo.GetParameters().Length == 0) { return(methodValuesInfo.Invoke(target, null)); } return(null); } }
/// <summary> /// Gets an enum value from reflection. /// </summary> /// <param name="target">The target object.</param> /// <param name="enumName">Name of a field, property, or method that returns an enum.</param> /// <returns>Null if can't find an enum value.</returns> internal static Enum GetEnumValue(object target, string enumName) { FieldInfo enumField = ReflectionUtility.GetField(target, enumName); if (enumField != null && enumField.FieldType.IsSubclassOf(typeof(Enum))) { return((Enum)enumField.GetValue(target)); } PropertyInfo enumProperty = ReflectionUtility.GetProperty(target, enumName); if (enumProperty != null && enumProperty.PropertyType.IsSubclassOf(typeof(Enum))) { return((Enum)enumProperty.GetValue(target)); } MethodInfo enumMethod = ReflectionUtility.GetMethod(target, enumName); if (enumMethod != null && enumMethod.ReturnType.IsSubclassOf(typeof(Enum))) { return((Enum)enumMethod.Invoke(target, null)); } return(null); }
internal static List <bool> GetConditionValues(object target, string[] conditions) { List <bool> conditionValues = new List <bool>(); foreach (var condition in conditions) { FieldInfo conditionField = ReflectionUtility.GetField(target, condition); if (conditionField != null && conditionField.FieldType == typeof(bool)) { conditionValues.Add((bool)conditionField.GetValue(target)); } PropertyInfo conditionProperty = ReflectionUtility.GetProperty(target, condition); if (conditionProperty != null && conditionProperty.PropertyType == typeof(bool)) { conditionValues.Add((bool)conditionProperty.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)); } } return(conditionValues); }
private object GetValues(SerializedProperty property, string valuesName) { object target = PropertyUtility.GetTargetObjectWithProperty(property); FieldInfo valuesFieldInfo = ReflectionUtility.GetField(target, valuesName); if (valuesFieldInfo != null) { return(valuesFieldInfo.GetValue(target)); } PropertyInfo valuesPropertyInfo = ReflectionUtility.GetProperty(target, valuesName); if (valuesPropertyInfo != null) { return(valuesPropertyInfo.GetValue(target)); } MethodInfo methodValuesInfo = ReflectionUtility.GetMethod(target, valuesName); if (methodValuesInfo != null && methodValuesInfo.ReturnType != typeof(void) && methodValuesInfo.GetParameters().Length == 0) { return(methodValuesInfo.Invoke(target, null)); } return(null); }
private static AnimatorController GetAnimatorController(SerializedProperty property, string animatorName) { object target = PropertyUtility.GetTargetObjectWithProperty(property); FieldInfo animatorFieldInfo = ReflectionUtility.GetField(target, animatorName); if (animatorFieldInfo != null && animatorFieldInfo.FieldType == typeof(Animator)) { Animator animator = animatorFieldInfo.GetValue(target) as Animator; if (animator != null) { AnimatorController animatorController = animator.runtimeAnimatorController as AnimatorController; return(animatorController); } } PropertyInfo animatorPropertyInfo = ReflectionUtility.GetProperty(target, animatorName); if (animatorPropertyInfo != null && animatorPropertyInfo.PropertyType == typeof(Animator)) { Animator animator = animatorPropertyInfo.GetValue(target) as Animator; if (animator != null) { AnimatorController animatorController = animator.runtimeAnimatorController as AnimatorController; return(animatorController); } } MethodInfo animatorGetterMethodInfo = ReflectionUtility.GetMethod(target, animatorName); if (animatorGetterMethodInfo != null && animatorGetterMethodInfo.ReturnType == typeof(Animator) && animatorGetterMethodInfo.GetParameters().Length == 0) { Animator animator = animatorGetterMethodInfo.Invoke(target, null) as Animator; if (animator != null) { AnimatorController animatorController = animator.runtimeAnimatorController as AnimatorController; return(animatorController); } } return(null); }