Beispiel #1
0
        /// <summary>
        /// Handler function for <c>SerializMethodAttribute</c>
        /// </summary>
        /// <param name="methodInfo">The method</param>
        private void SerializeMethodAttributeHandler(MethodInfo methodInfo)
        {
            SerializeMethodAttribute attribute = methodInfo.GetCustomAttribute <SerializeMethodAttribute>();

            if (attribute == null)
            {
                return;
            }

            bool disableForEditMode = !EditorApplication.isPlaying && !attribute.mode.HasFlag(Mode.Edit);
            bool disableForPlayMode = EditorApplication.isPlaying && !attribute.mode.HasFlag(Mode.Play);

            if (disableForEditMode || disableForPlayMode)
            {
                return;
            }

            string name = "(" + methodInfo.ReturnType.Name + ") " + (attribute.name == null ? methodInfo.Name.Regular() : attribute.name);

            if (!GUILayout.Button(name))
            {
                return;
            }

            methodInfo.AutoInvoke(monoBehaviours, null).Log(false);
        }
Beispiel #2
0
        /// <summary>
        /// Handler function for method
        /// </summary>
        private void MethodHandler()
        {
            List <MethodInfo> methodInfoList = methodInfoDictionary[name];

            MethodInfo mostCompatibleMethod = null;

            object[] mostCompatibleBoxedArguments = null;
            int      minCompatibility             = int.MaxValue;

            foreach (MethodInfo methodInfo in methodInfoList)
            {
                ParameterInfo[] targetArguments = methodInfo.GetParameters();
                if (arguments.Length != targetArguments.Length)
                {
                    continue;
                }

                int      compatibility  = 0;
                object[] boxedArguments = new object[arguments.Length];

                for (int i = 0; i < arguments.Length; i++)
                {
                    int argumentCompatibility;
                    boxedArguments[i] = arguments[i].ChangeTypeWithCompatibility(targetArguments[i].ParameterType, out argumentCompatibility);

                    if (argumentCompatibility < 0)
                    {
                        compatibility = -1;
                        break;
                    }

                    compatibility += argumentCompatibility;
                }

                if (compatibility < 0)
                {
                    continue;
                }

                if (compatibility < minCompatibility)
                {
                    mostCompatibleMethod         = methodInfo;
                    mostCompatibleBoxedArguments = boxedArguments;
                    minCompatibility             = compatibility;
                }

                if (compatibility == 0)
                {
                    break;
                }
            }

            if (mostCompatibleMethod == null)
            {
                StringConstantInternal.methodMismatchArgumentTypeError.ReplacedBy(name).Color(Color.red).LogConsole();
                return;
            }

            mostCompatibleMethod.AutoInvoke(predicate, mostCompatibleBoxedArguments).LogConsole();
        }