protected override void InvokeMethod(MightyMethod mightyMethod, T attribute) { var methodInfo = mightyMethod.MemberInfo; if (!m_methodCache.Contains(mightyMethod)) { EnableDrawer(mightyMethod, attribute); } if (m_methodCache[mightyMethod]) { var label = attribute.Label; var buttonText = string.IsNullOrEmpty(label) ? methodInfo.Name.GetPrettyName() : label; var enabled = GUI.enabled; GUI.enabled = enabled && (attribute.ExecuteInPlayMode || !EditorApplication.isPlaying); if (DrawButton(attribute, buttonText, methodInfo.Name)) { methodInfo.Invoke(mightyMethod.Context.Target, null); OnFunctionHasBeenCalled(); } GUI.enabled = enabled; } else { MightyGUIUtilities.DrawHelpBox($"{attribute.GetType().Name} works only on methods with no parameters"); } }
public static bool GetMightyMethod <T>(this BaseMightyMember mightyMember, object target, string memberName, CallbackSignature callbackSignature, out MightyMethod <T> method) { if (string.IsNullOrWhiteSpace(memberName)) { method = null; return(false); } if (target is BaseWrapperAttribute wrapper && GetCallbackName(target, memberName, out var callbackName)) { return(mightyMember.GetMightyMethod(mightyMember.GetWrapperTarget(wrapper), callbackName, callbackSignature, out method)); } if (InternalGetMightyMethod(target, memberName, callbackSignature, out method)) { return(true); } if (!(mightyMember is MightySerializedField serializedField)) { return(false); } target = serializedField.Property.GetPropertyTargetReference(); return(target.GetType().GetCustomAttributes(typeof(SerializableAttribute), true).Length > 0 && InternalGetMightyMethod(target, memberName, callbackSignature, out method)); }
protected override void OnInspectorGUI(bool canDraw, MightyMethod mightyMethod, T attribute) { if (canDraw) { InvokeMethod(mightyMethod, attribute); } }
private object InvokeDrawer(Rect position, MightyMethod <object> drawerMethod, string signature, params object[] parameters) { if (drawerMethod != null) { return(drawerMethod.Invoke(parameters)); } MightyGUIUtilities.DrawHelpBox(position, $"The drawer callback is invalid, it should be like this: \"{signature}\""); return(null); }
private object InvokeDrawer(MightyMethod <object> drawerMethod, string signature, params object[] parameters) { if (drawerMethod != null) { return(drawerMethod.Invoke(parameters)); } EditorDrawUtility.DrawHelpBox($"Callback is invalid, it should be like this: \"{signature}\""); return(null); }
public static void CacheMethodDrawerForMethod(this MightyMethod method, MethodInfo methodInfo, IEnumerable <BaseMightyAttribute> wrappedAttributes) { if (method.CacheSingleAttribute <BaseMethodAttribute>(methodInfo.GetCustomAttributes <BaseMethodAttribute>(true))) { return; } method.CacheSingleAttribute <BaseMethodAttribute>(wrappedAttributes); }
private static bool InternalGetMightyMethod <T>(object target, string memberName, CallbackSignature callbackSignature, out MightyMethod <T> method) { var methodInfo = ReflectionUtilities.GetMethod(target.GetType(), memberName); if (callbackSignature.IsMethodValid(methodInfo)) { method = new MightyMethod <T>(target, methodInfo); return(true); } method = null; return(false); }
protected virtual void InvokeMethod(MightyMethod mightyMethod, T attribute) { if (!m_methodCache.Contains(mightyMethod)) { EnableDrawer(mightyMethod, attribute); } if (m_methodCache[mightyMethod]) { var methodInfo = mightyMethod.MemberInfo; if (attribute.ExecuteInPlayMode || !EditorApplication.isPlaying) { methodInfo.Invoke(mightyMethod.Context.Target, null); } } else { MightyGUIUtilities.DrawHelpBox($"{typeof(T).Name} works only on methods with no parameters"); } }
protected abstract void OnInspectorGUI(bool canDraw, MightyMethod mightyMethod, T attribute);
protected abstract void OnModifiedProperties(bool modified, MightyMethod mightyMethod, T attribute);
protected abstract void OnEnable(MightyMethod mightyMethod, T attribute);
public void OnModifiedProperties(bool modified, MightyMethod mightyMethod, BaseMethodAttribute baseAttribute) => OnModifiedProperties(modified, mightyMethod, (T)baseAttribute);
public void OnEnable(MightyMethod mightyMethod, BaseMethodAttribute baseAttribute) => OnEnable(mightyMethod, (T)baseAttribute);
protected override void OnModifiedProperties(bool modified, MightyMethod mightyMethod, T attribute) { }
protected override void OnEnable(MightyMethod mightyMethod, T attribute) { }
private bool GetDrawerForMember(BaseMightyMember member, CallbackSignature signature, out MightyMethod <object> drawerMethod, BasePropertyDrawerAttribute attribute) { if (GetDrawerForMember(member.ID, signature, out drawerMethod)) { return(true); } EnableDrawer(member, attribute); return(GetDrawerForMember(member.ID, signature, out drawerMethod)); }
private bool GetDrawerForMember(long id, CallbackSignature signature, out MightyMethod <object> drawerMethod) => m_customDrawerCache.TryGetValue(id, signature, out drawerMethod);
public void OnInspectorGUI(bool canDraw, MightyMethod mightyMethod, BaseMethodAttribute baseAttribute) => OnInspectorGUI(canDraw, mightyMethod, (T)baseAttribute);