예제 #1
0
        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");
            }
        }
예제 #2
0
        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));
        }
예제 #3
0
 protected override void OnInspectorGUI(bool canDraw, MightyMethod mightyMethod, T attribute)
 {
     if (canDraw)
     {
         InvokeMethod(mightyMethod, attribute);
     }
 }
예제 #4
0
 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);
 }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
 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");
     }
 }
예제 #9
0
 protected abstract void OnInspectorGUI(bool canDraw, MightyMethod mightyMethod, T attribute);
예제 #10
0
 protected abstract void OnModifiedProperties(bool modified, MightyMethod mightyMethod, T attribute);
예제 #11
0
 protected abstract void OnEnable(MightyMethod mightyMethod, T attribute);
예제 #12
0
 public void OnModifiedProperties(bool modified, MightyMethod mightyMethod, BaseMethodAttribute baseAttribute) =>
 OnModifiedProperties(modified, mightyMethod, (T)baseAttribute);
예제 #13
0
 public void OnEnable(MightyMethod mightyMethod, BaseMethodAttribute baseAttribute) => OnEnable(mightyMethod, (T)baseAttribute);
예제 #14
0
 protected override void OnModifiedProperties(bool modified, MightyMethod mightyMethod, T attribute)
 {
 }
예제 #15
0
 protected override void OnEnable(MightyMethod mightyMethod, T attribute)
 {
 }
예제 #16
0
 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));
 }
예제 #17
0
 private bool GetDrawerForMember(long id, CallbackSignature signature, out MightyMethod <object> drawerMethod) =>
 m_customDrawerCache.TryGetValue(id, signature, out drawerMethod);
예제 #18
0
 public void OnInspectorGUI(bool canDraw, MightyMethod mightyMethod, BaseMethodAttribute baseAttribute) =>
 OnInspectorGUI(canDraw, mightyMethod, (T)baseAttribute);