예제 #1
0
    /// <summary>
    /// Returns custom property drawer for type if one could be found, or null if
    /// no custom property drawer could be found. Does not use cached values, so it's resource intensive.
    /// </summary>
    public static PropertyDrawer Find(Type propertyType)
    {
        foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
        {
            foreach (Type candidate in assem.GetTypes())
            {
                FieldInfo typeField  = typeof(CustomPropertyDrawer).GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance);
                FieldInfo childField = typeof(CustomPropertyDrawer).GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance);
                foreach (Attribute a in candidate.GetCustomAttributes(typeof(CustomPropertyDrawer)))
                {
                    if (a.GetType().IsSubclassOf(typeof(CustomPropertyDrawer)) || a.GetType() == typeof(CustomPropertyDrawer))
                    {
                        CustomPropertyDrawer drawerAttribute = (CustomPropertyDrawer)a;
                        Type drawerType = (Type)typeField.GetValue(drawerAttribute);
                        if (drawerType == propertyType ||
                            ((bool)childField.GetValue(drawerAttribute) && propertyType.IsSubclassOf(drawerType)) ||
                            ((bool)childField.GetValue(drawerAttribute) && IsGenericSubclass(drawerType, propertyType)))
                        {
                            if (candidate.IsSubclassOf(typeof(PropertyDrawer)))
                            {
                                return((PropertyDrawer)Activator.CreateInstance(candidate));
                            }
                        }
                    }
                }
            }
        }



        return(null);
    }
            public void CreateGraph(Assembly assembly)
            {
                if (_checkedAssemblies.Contains(assembly))
                {
                    return;
                }

                _checkedAssemblies.Add(assembly);

                foreach (Type type in assembly.GetTypes())
                {
                    object[] attributes = type.GetCustomAttributes(typeof(CustomPropertyDrawer), false);

                    foreach (object attribute in attributes)
                    {
                        if (attribute is CustomPropertyDrawer)
                        {
                            CustomPropertyDrawer drawerData = attribute as CustomPropertyDrawer;

                            bool useForChildren = (bool)typeof(CustomPropertyDrawer).GetField("m_UseForChildren", _fieldBindingsFlag).GetValue(drawerData);
                            Type targetType     = (Type)typeof(CustomPropertyDrawer).GetField("m_Type", _fieldBindingsFlag).GetValue(drawerData);

                            if (useForChildren)
                            {
                                _supportedInheritedTypes.Add(targetType);
                            }
                            else
                            {
                                _supportedTypes.Add(targetType);
                            }
                        }
                    }
                }
            }
예제 #3
0
 public static bool UseForChildren(CustomPropertyDrawer drawer)
 {
     if (useForChildrenFieldInfo == null)
     {
         useForChildrenFieldInfo = typeof(CustomPropertyDrawer).GetField("m_UseForChildren", BindingFlags.Instance | BindingFlags.NonPublic);
     }
     if (useForChildrenFieldInfo != null)
     {
         return((bool)useForChildrenFieldInfo.GetValue(drawer));
     }
     return(false);
 }
예제 #4
0
 public static Type GetType(CustomPropertyDrawer drawer)
 {
     if (typeFieldInfo == null)
     {
         typeFieldInfo = typeof(CustomPropertyDrawer).GetField("m_Type", BindingFlags.Instance | BindingFlags.NonPublic);
     }
     if (typeFieldInfo != null)
     {
         return((Type)typeFieldInfo.GetValue(drawer));
     }
     return(null);
 }
예제 #5
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
                            };
                        }
                    }
                }
            }
        }
예제 #6
0
        static public bool CanHandleType(this CustomPropertyDrawer item, Type type)
        {
            Type handled_type = item.GetHandledType();

            if (handled_type.EqualsEX(type))
            {
                return(true);
            }

            if (item.DoesHandleChildTypes())
            {
                if (type.CanBeTreatedAs(handled_type))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #7
0
    private static void LoadDrawers()
    {
        _drawers = new Dictionary <Type, PropertyDrawer>();

        IEnumerable <PropertyDrawer> allDrawers = typeof(PatternLoader).Assembly.GetTypes()
                                                  .Where(x => typeof(PropertyDrawer).IsAssignableFrom(x))
                                                  .Select(x => Activator.CreateInstance(x) as PropertyDrawer);

        foreach (PropertyDrawer drawer in allDrawers)
        {
            object[] attributes = drawer.GetType().GetCustomAttributes(typeof(CustomPropertyDrawer), false);

            if (attributes.Length != 0)
            {
                CustomPropertyDrawer drawerAttribute = attributes[0] as CustomPropertyDrawer;
                Type targetType = (Type)typeof(CustomPropertyDrawer).GetField("m_Type", FieldFlags).GetValue(drawerAttribute);

                if (targetType.IsAbstract == false)
                {
                    _drawers.Add(targetType, drawer);
                }
            }
        }
    }
예제 #8
0
 public static bool IsForChildren(this CustomPropertyDrawer drawer)
 {
     return((bool)typeof(CustomPropertyDrawer)
            .GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance)
            .GetValue(drawer));
 }
예제 #9
0
 public static Type GetTargetType(this CustomPropertyDrawer drawer)
 {
     return(typeof(CustomPropertyDrawer)
            .GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance)
            .GetValue(drawer) as Type);
 }
예제 #10
0
 static public bool DoesHandleChildTypes(this CustomPropertyDrawer item)
 {
     return(DOES_HANDLE_CHILD_TYPES_GETTER.Fetch()(item));
 }
예제 #11
0
 static public Type GetHandledType(this CustomPropertyDrawer item)
 {
     return(GET_HANDLED_TYPE_GETTER.Fetch()(item));
 }
예제 #12
0
 public static bool GetUseForChildren(this CustomPropertyDrawer prop)
 {
     return(StratusReflection.GetField <bool>("m_UseForChildren", typeof(CustomPropertyDrawer), false, prop));
 }
예제 #13
0
 public static Type GetHiddenType(this CustomPropertyDrawer prop)
 {
     return(StratusReflection.GetField <Type>("m_Type", typeof(CustomPropertyDrawer), false, prop));
 }