Example #1
0
        private static MethodInfo GetEditorMethod(Type type)
        /// Using original (non-editor) type get gui action delegate
        {
            if (methodsCaches.TryGetValue(type, out MethodInfo editorMethod))
            {
                return(editorMethod);
            }

            SpecialEditorAttribute customEditorAttribute = Attribute.GetCustomAttribute(type, typeof(SpecialEditorAttribute)) as SpecialEditorAttribute;

            if (customEditorAttribute != null)
            {
                Type editorType = GetEditorType(type, customEditorAttribute.className);
                if (editorType != null)
                {
                    editorMethod = editorType.GetMethod(customEditorAttribute.actionName);
                    if (editorMethod == null)
                    {
                        throw new Exception("Could not find method " + customEditorAttribute.actionName + " in " + customEditorAttribute.className);
                    }
                }
            }

            methodsCaches.Add(type, editorMethod);
            return(editorMethod);
        }
Example #2
0
        public static void Draw <TO, T1, T2, T3> (TO obj, T1 t1, T2 t2, T3 t3)
        {
            Type type = obj.GetType();
            SpecialEditorAttribute customEditorAttribute = Attribute.GetCustomAttribute(type, typeof(SpecialEditorAttribute)) as SpecialEditorAttribute;

            if (customEditorAttribute == null)
            {
                return;
            }

            Type       editorType   = GetEditorType(type, customEditorAttribute.className);
            MethodInfo editorMethod = editorType.GetMethod(customEditorAttribute.actionName);

            if (editorMethod == null)
            {
                throw new Exception("Special Editor: Could not find method " + customEditorAttribute.actionName + " in " + customEditorAttribute.className);
            }

            Action <TO, T1, T2, T3> editorAction;

            if (actionsCache.ContainsKey(type))
            {
                editorAction = actionsCache[type] as Action <TO, T1, T2, T3>;
            }
            else
            {
                ParameterInfo[] args = editorMethod.GetParameters();
                if (args.Length != 4)
                {
                    throw new Exception("Special Editor: Number of method arguments (" + args.Length + ") doesn't match called count (4)");
                }
                if (args[0].ParameterType != typeof(TO) || args[1].ParameterType != typeof(T1) || args[2].ParameterType != typeof(T2) || args[3].ParameterType != typeof(T3))
                {
                    throw new Exception("Special Editor: Arguments don't match: \n" +
                                        "\t" + args[0].ParameterType + " vs " + typeof(TO) + "\n" +
                                        "\t" + args[1].ParameterType + " vs " + typeof(T1) + "\n" +
                                        "\t" + args[2].ParameterType + " vs " + typeof(T2) + "\n" +
                                        "\t" + args[3].ParameterType + " vs " + typeof(T3));
                }

                editorAction = Delegate.CreateDelegate(typeof(Action <TO, T1, T2, T3>), editorMethod) as Action <TO, T1, T2, T3>;
                actionsCache.Add(type, editorAction);
            }
            editorAction(obj, t1, t2, t3);
        }