public static bool GetArrayInfoFromMember(this BaseMightyMember mightyMember, object target, string memberName, out MightyInfo <object[]> mightyInfo) { if (string.IsNullOrEmpty(memberName)) { mightyInfo = null; return(false); } if (target is BaseWrapperAttribute wrapper && GetCallbackName(target, memberName, out var callbackName)) { return(GetArrayInfoFromMember(mightyMember, mightyMember.GetWrapperTarget(wrapper), callbackName, out mightyInfo)); } if (InternalGetArrayInfoFromMember(target, memberName, out mightyInfo)) { return(true); } if (!(mightyMember is MightySerializedField serializedField)) { return(false); } target = serializedField.Property.GetPropertyTargetReference(); return(target.GetType().GetCustomAttributes(typeof(SerializableAttribute), true).Length > 0 && InternalGetArrayInfoFromMember(target, memberName, out mightyInfo)); }
public override void InitDrawer(BaseMightyMember mightyMember, BaseMightyAttribute mightyAttribute) { var property = (MightyMember <PropertyInfo>)mightyMember; m_showNativeCache[mightyMember] = new MightyInfo <object>(property.Target, property.MemberInfo, property.MemberInfo.GetValue(mightyMember.Target)); }
protected override void Enable(BaseMightyMember mightyMember, ShowPropertyAttribute attribute) { var property = (MightyMember <PropertyInfo>)mightyMember; var target = attribute.Target; m_showPropertyCache[mightyMember] = new MightyInfo <object>(target, property.MemberInfo, property.MemberInfo.GetValue(target)); }
internal static bool InternalGetInfoFromMember <T>(object target, string memberName, bool checkElementType, out MightyInfo <T> info) { var callbackSignature = new CallbackSignature(typeof(T), checkElementType); var fieldInfo = ReflectionUtilities.GetField(target.GetType(), memberName); if (callbackSignature.IsFieldValid(fieldInfo)) { info = new MightyInfo <T>(target, fieldInfo, (T)fieldInfo.GetValue(target)); return(true); } var propertyInfo = ReflectionUtilities.GetProperty(target.GetType(), memberName); if (callbackSignature.IsPropertyValid(propertyInfo)) { info = new MightyInfo <T>(target, propertyInfo, (T)propertyInfo.GetValue(target)); return(true); } var methodInfo = ReflectionUtilities.GetMethod(target.GetType(), memberName); if (callbackSignature.IsMethodValid(methodInfo)) { info = new MightyInfo <T>(target, methodInfo, (T)methodInfo.Invoke(target, null)); return(true); } info = null; return(false); }
protected override void Enable(BaseMightyMember mightyMember, ShowNonSerializedAttribute attribute) { var field = (MightyMember <FieldInfo>)mightyMember; var target = attribute.Target; m_showNonSerializedCache[mightyMember] = new MightyInfo <object>(target, field.MemberInfo, field.MemberInfo.GetValue(target)); }
protected override void Enable(BaseMightyMember mightyMember, T attribute) { if (!mightyMember.GetInfoFromMember <ArrayDecoratorPosition>(attribute.Target, attribute.PositionCallback, out var positionInfo, Enum.TryParse)) { positionInfo = new MightyInfo <ArrayDecoratorPosition>(attribute.Position); } m_positionCache[mightyMember] = positionInfo; }
public override void InitDrawer(BaseMightyMember mightyMember, BaseMightyAttribute mightyAttribute) { var attribute = (InfoBoxAttribute)mightyAttribute; var target = mightyMember.InitAttributeTarget <InfoBoxAttribute>(); if (!mightyMember.Property.GetBoolInfo(target, attribute.VisibleIf, out var visibleInfo)) { visibleInfo = new MightyInfo <bool>(true); } m_infoBoxCache[mightyMember] = visibleInfo; }
public static bool GetInfoFromMember <T>(this BaseMightyMember mightyMember, object target, string memberName, out MightyInfo <T> info, GetValuePredicate <T> predicate = null, bool neverInWrapper = false) { if (string.IsNullOrWhiteSpace(memberName)) { info = null; return(false); } if (predicate != null && predicate(memberName, out var outValue)) { info = new MightyInfo <T>(null, null, outValue); return(true); } if (target is BaseWrapperAttribute wrapper) { if (neverInWrapper) { return(mightyMember.GetInfoFromMember(mightyMember.GetWrapperTarget(wrapper), memberName, out info, predicate)); } if (GetCallbackName(target, memberName, out var callbackName)) { return(mightyMember.GetInfoFromMember(mightyMember.GetWrapperTarget(wrapper), callbackName, out info, predicate)); } } if (InternalGetInfoFromMember(target, memberName, true, out info)) { return(true); } if (!(mightyMember is MightySerializedField serializedField)) { return(false); } target = serializedField.Property.GetPropertyTargetReference(); if (target.GetType().GetCustomAttributes(typeof(SerializableAttribute), true).Length > 0 && InternalGetInfoFromMember(target, memberName, true, out info)) { return(true); } if (!TypeUtilities.TryConvertStringToType(memberName, out T value)) { return(false); } info = new MightyInfo <T>(target, null, value); return(true); }
public override void InitDrawer(BaseMightyMember mightyMember, BaseMightyAttribute mightyAttribute) { var attribute = (LayoutSpaceAttribute)mightyAttribute; var target = mightyMember.InitAttributeTarget <LayoutSpaceAttribute>(); var property = mightyMember.Property; if (!property.GetInfoFromMember <DecoratorPosition>(target, attribute.PositionName, out var positionInfo, Enum.TryParse)) { positionInfo = new MightyInfo <DecoratorPosition>(attribute.Position); } m_flexibleSpaceCache[mightyMember] = positionInfo; }
public override void InitDrawer(BaseMightyMember mightyMember, BaseMightyAttribute mightyAttribute) { var buttonAttribute = (ButtonAttribute)mightyAttribute; if (mightyMember.Target.GetBoolInfo(buttonAttribute.EnabledCallback, out var enabledInfo)) { enabledInfo.Value = enabledInfo.Value; } else { enabledInfo = new MightyInfo <bool>(GUI.enabled && buttonAttribute.ExecuteInPlayMode || !EditorApplication.isPlaying); } m_buttonCache[mightyMember] = enabledInfo; }
protected override void EnableSerializeFieldDrawer(MightySerializedField serializedField, T attribute) { if (serializedField.Property.propertyType != SerializedPropertyType.String) { return; } if (!attribute.PathAsCallback || !serializedField.GetInfoFromMember <string>(attribute.Target, attribute.DefaultPath, out var pathInfo)) { pathInfo = new MightyInfo <string>(attribute.DefaultPath ?? Application.dataPath); } m_pathCache[serializedField] = pathInfo; }
protected override void EnableSerializeFieldDrawer(MightySerializedField serializedField, FilePanelAttribute attribute) { base.EnableSerializeFieldDrawer(serializedField, attribute); if (serializedField.Property.propertyType != SerializedPropertyType.String) { return; } var target = attribute.Target; if (!attribute.ExtensionAsCallback || !serializedField.GetInfoFromMember <string>(target, attribute.Extension, out var extensionInfo)) { extensionInfo = new MightyInfo <string>(attribute.Extension); } m_extensionCache[serializedField] = extensionInfo; }
protected override void Enable(BaseMightyMember mightyMember, T attribute) { if (!(mightyMember is MightyComponent mightyComponent)) { return; } var gameObject = mightyComponent.ComponentContext.GameObject; if (!mightyMember.GetInfoFromMember <int>(attribute.Target, attribute.PriorityCallback, out var priorityInfo)) { priorityInfo = new MightyInfo <int>(attribute.Priority); } if (m_priorityCache.TryGetValue(gameObject, out var priority) && priority.Value >= priorityInfo.Value) { return; } m_priorityCache[gameObject] = priorityInfo; EnableDrawerImpl(mightyComponent, attribute); }
internal static bool InternalGetArrayInfoFromMember(object target, string memberName, out MightyInfo <object[]> mightyInfo) { var fieldInfo = ReflectionUtilities.GetField(target.GetType(), memberName); if (fieldInfo != null) { if (typeof(IList).IsAssignableFrom(fieldInfo.FieldType)) { var list = (IList)fieldInfo.GetValue(target); mightyInfo = new MightyInfo <object[]>(target, fieldInfo, new object[list.Count]); for (var i = 0; i < list.Count; i++) { mightyInfo.Value[i] = list[i]; } return(true); } mightyInfo = null; return(false); } var propertyInfo = ReflectionUtilities.GetProperty(target.GetType(), memberName); if (propertyInfo != null) { if (typeof(IList).IsAssignableFrom(propertyInfo.PropertyType)) { var list = (IList)propertyInfo.GetValue(target); mightyInfo = new MightyInfo <object[]>(target, propertyInfo, new object[list.Count]); for (var i = 0; i < list.Count; i++) { mightyInfo.Value[i] = list[i]; } return(true); } mightyInfo = null; return(false); } var methodInfo = ReflectionUtilities.GetMethod(target.GetType(), memberName); if (methodInfo != null) { if (typeof(IList).IsAssignableFrom(methodInfo.ReturnType)) { var list = (IList)methodInfo.Invoke(target, null); mightyInfo = new MightyInfo <object[]>(target, methodInfo, new object[list.Count]); for (var i = 0; i < list.Count; i++) { mightyInfo.Value[i] = list[i]; } return(true); } mightyInfo = null; return(false); } mightyInfo = null; return(false); }
public static bool GetBoolInfo(this BaseMightyMember mightyMember, object target, string memberName, out MightyInfo <bool> info) => mightyMember.GetInfoFromMember(target, memberName, out info, (string name, out bool value) => bool.TryParse(name, out value));