/// <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); } } } } }
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); }
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); }
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 }; } } } } }
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); }
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); } } } }
public static bool IsForChildren(this CustomPropertyDrawer drawer) { return((bool)typeof(CustomPropertyDrawer) .GetField("m_UseForChildren", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(drawer)); }
public static Type GetTargetType(this CustomPropertyDrawer drawer) { return(typeof(CustomPropertyDrawer) .GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(drawer) as Type); }
static public bool DoesHandleChildTypes(this CustomPropertyDrawer item) { return(DOES_HANDLE_CHILD_TYPES_GETTER.Fetch()(item)); }
static public Type GetHandledType(this CustomPropertyDrawer item) { return(GET_HANDLED_TYPE_GETTER.Fetch()(item)); }
public static bool GetUseForChildren(this CustomPropertyDrawer prop) { return(StratusReflection.GetField <bool>("m_UseForChildren", typeof(CustomPropertyDrawer), false, prop)); }
public static Type GetHiddenType(this CustomPropertyDrawer prop) { return(StratusReflection.GetField <Type>("m_Type", typeof(CustomPropertyDrawer), false, prop)); }