Ejemplo n.º 1
0
 public static PropertyDrawer GetDefaultDrawer()
 {
     if (__drawerDefault == null)
     {
         __drawerDefault = new UnityDefaultPropertyDrawer();
     }
     return(__drawerDefault);
 }
Ejemplo n.º 2
0
        //
        // Static Methods
        //


        #region GetDrawer of type
        //TODO maybe use ScriptUtilityAttributeW for some
        /// <summary>
        /// Gets the drawer.
        /// </summary>
        /// <returns>The drawer.</returns>
        /// <param name="type">Type.</param>
        public static PropertyDrawer GetDrawer(Type type)
        {
            Type           typeDrawer;
            PropertyDrawer drawer = null;

            if (EditorUtilityEx.__drawers == null)
            {
                EditorUtilityEx.__drawers = new Dictionary <Type, PropertyDrawer> ();
                Type[] derivedTypes = ReflectionUtility.GetDerivedTypes(typeof(PropertyDrawer));
                CustomPropertyDrawer[] attributes;
                CustomPropertyDrawer   attribute;
                for (int i = 0; i < derivedTypes.Length; i++)
                {
                    typeDrawer = derivedTypes [i];

                    attributes = AttributeUtility.GetAttributes <CustomPropertyDrawer> (typeDrawer, false);

                    if (attributes != null)
                    {
                        for (int j = 0; j < attributes.Length; j++)
                        {
                            attribute = attributes [j];

                            if (attribute != null)
                            {
                                FieldInfo m_TypeFieldInfo = attribute.GetType().GetField("m_Type", BindingFlags.Instance | BindingFlags.NonPublic);



                                if (m_TypeFieldInfo != null)
                                {
                                    Type typeProperty = (Type)m_TypeFieldInfo.GetValue(attribute);



                                    if (typeProperty != null && typeProperty.BaseType != typeof(PropertyAttribute))
                                    {
                                        if (typeProperty.IsGenericType)
                                        {
                                            typeProperty = typeProperty.GetGenericTypeDefinition();
                                        }

                                        if (!EditorUtilityEx.__drawers.ContainsKey(typeProperty))
                                        {
                                            EditorUtilityEx.__drawers.Add(typeProperty, Activator.CreateInstance(typeDrawer) as PropertyDrawer);

//																				Debug.Log("  "+typeProperty.Name+" "+typeDrawer.Name+" "+typeProperty.BaseType);
                                        }
                                    }
                                }
                            }
                        }                                        //attributes
                    }
                }                                                //types in dll
            }

            if (type.IsGenericType)
            {
                type = type.GetGenericTypeDefinition();
            }


            EditorUtilityEx.__drawers.TryGetValue(type, out drawer);
            if (drawer != null)
            {
                return(drawer);
            }

            if (type.BaseType != null)
            {
                if (EditorUtilityEx.__drawers.TryGetValue(type.BaseType, out drawer))
                {
                    return(drawer);
                }
            }

            if (__drawerDefault == null)
            {
                __drawerDefault = new UnityDefaultPropertyDrawer();
            }


            return(__drawerDefault);
        }