Пример #1
0
        private static void BuildDrawerTypeForTypeDictionary()
        {
            s_DrawerTypeForType = new Dictionary <Type, DrawerKeySet>();
            Type[] source = AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly x) => Reflection.GetTypesFromAssembly(x)).ToArray();
            foreach (Type item in SubclassesOf(typeof(GUIDrawer)))
            {
                object[] customAttributes = item.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
                object[] array            = customAttributes;
                for (int i = 0; i < array.Length; i++)
                {
                    CustomPropertyDrawer editor = (CustomPropertyDrawer)array[i];
                    Type editorType             = editor.GetHiddenType();

                    s_DrawerTypeForType[editorType] = new DrawerKeySet
                    {
                        drawer = item,
                        type   = editorType
                    };
                    if (editor.GetUseForChildren())
                    {
                        IEnumerable <Type> enumerable = from x in source
                                                        where x.IsSubclassOf(editorType)
                                                        select x;
                        foreach (Type item2 in enumerable)
                        {
                            if (s_DrawerTypeForType.ContainsKey(item2))
                            {
                                Type         type         = editorType;
                                DrawerKeySet drawerKeySet = s_DrawerTypeForType[item2];
                                if (!type.IsAssignableFrom(drawerKeySet.type))
                                {
                                    // Was in unity's decompiled source, so not touching for now
                                    goto IL_0158;
                                }
                                continue;
                            }
                            goto IL_0158;
IL_0158:
                            s_DrawerTypeForType[item2] = new DrawerKeySet
                            {
                                drawer = item,
                                type   = editorType
                            };
                        }
                    }
                }
            }
        }
        // Called on demand
        public static void BuildDrawerTypeForTypeDictionary()
        {
            s_DrawerTypeForType = new Dictionary <Type, DrawerKeySet>();

            var loadedTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => AssemblyHelper.GetTypesFromAssembly(x)).ToArray();

            foreach (Type type in EditorAssembliesHelper.SubclassesOf(typeof(GUIDrawer)))
            {
                object[] attrs = type.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
                foreach (CustomPropertyDrawer editor in attrs)
                {
                    var  editorType     = CustomPropertyDrawerHelper.GetType(editor);
                    bool useForChildren = CustomPropertyDrawerHelper.UseForChildren(editor);
                    //Debug.Log("Base type: " + editorType);
                    s_DrawerTypeForType[editorType] = new DrawerKeySet()
                    {
                        Drawer = type,
                        Type   = editorType
                    };

                    if (!useForChildren)
                    {
                        continue;
                    }

                    var candidateTypes = loadedTypes.Where(x => x.IsSubclassOf(editorType));
                    foreach (var candidateType in candidateTypes)
                    {
                        //Debug.Log("Candidate Type: "+ candidateType);
                        if (s_DrawerTypeForType.ContainsKey(candidateType) &&
                            (editorType.IsAssignableFrom(s_DrawerTypeForType[candidateType].Type)))
                        {
                            //  Debug.Log("skipping");
                            continue;
                        }

                        //Debug.Log("Setting");
                        s_DrawerTypeForType[candidateType] = new DrawerKeySet()
                        {
                            Drawer = type,
                            Type   = editorType
                        };
                    }
                }
            }
        }
        // Called on demand
        private static void BuildDrawerTypeForTypeDictionary()
        {
            s_DrawerTypeForType = new Dictionary <Type, DrawerKeySet>();

            foreach (var type in TypeCache.GetTypesDerivedFrom <GUIDrawer>())
            {
                //Debug.Log("Drawer: " + type);
                object[] attrs = type.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
                foreach (CustomPropertyDrawer editor in attrs)
                {
                    //Debug.Log("Base type: " + editor.type);
                    s_DrawerTypeForType[editor.m_Type] = new DrawerKeySet()
                    {
                        drawer = type,
                        type   = editor.m_Type
                    };

                    if (!editor.m_UseForChildren)
                    {
                        continue;
                    }

                    var candidateTypes = TypeCache.GetTypesDerivedFrom(editor.m_Type);
                    foreach (var candidateType in candidateTypes)
                    {
                        //Debug.Log("Candidate Type: "+ candidateType);
                        if (s_DrawerTypeForType.ContainsKey(candidateType) &&
                            (editor.m_Type.IsAssignableFrom(s_DrawerTypeForType[candidateType].type)))
                        {
                            //  Debug.Log("skipping");
                            continue;
                        }

                        //Debug.Log("Setting");
                        s_DrawerTypeForType[candidateType] = new DrawerKeySet()
                        {
                            drawer = type,
                            type   = editor.m_Type
                        };
                    }
                }
            }
        }
Пример #4
0
        internal static Type GetDrawerTypeForType(Type type)
        {
            if (s_DrawerTypeForType == null)
            {
                BuildDrawerTypeForTypeDictionary();
            }
            DrawerKeySet drawerKeySet = default(DrawerKeySet);

            s_DrawerTypeForType.TryGetValue(type, out drawerKeySet);
            if (drawerKeySet.drawer != null)
            {
                return(drawerKeySet.drawer);
            }
            if (type.IsGenericType)
            {
                s_DrawerTypeForType.TryGetValue(type.GetGenericTypeDefinition(), out drawerKeySet);
            }
            return(drawerKeySet.drawer);
        }