Ejemplo n.º 1
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        public DrawerInfo(Type drawerType, Type drawnValueType, Type drawnAttributeType, OdinDrawerAttribute odinDrawerAttribute)
        {
            this.DrawerType          = drawerType;
            this.DrawnValueType      = drawnValueType;
            this.DrawnAttributeType  = drawnAttributeType;
            this.OdinDrawerAttribute = odinDrawerAttribute;

            //
            // Figure out the drawer's priority
            //

            DrawerPriorityAttribute priorityAttribute = null;

            if (drawerType.IsGenericType)
            {
                //
                // Special case for Unity property drawers;
                // Allow them to specify their priority if they
                // want, and if they haven't, assign them
                // downgraded priorities so ODIN drawers always
                // override them by default.
                //

                Type unityDrawer = null;

                if (drawerType.GetGenericTypeDefinition() == typeof(UnityPropertyDrawer <,>) || drawerType.GetGenericTypeDefinition() == typeof(UnityDecoratorAttributeDrawer <, ,>) || drawerType.GetGenericTypeDefinition() == typeof(UnityPropertyAttributeDrawer <, ,>) || drawerType.GetGenericTypeDefinition() == typeof(AbstractTypeUnityPropertyDrawer <, ,>))
                {
                    unityDrawer = drawerType.GetGenericArguments()[0];
                }

                if (unityDrawer != null)
                {
                    priorityAttribute = unityDrawer.GetCustomAttribute <DrawerPriorityAttribute>();
                }
            }

            if (priorityAttribute == null)
            {
                priorityAttribute = drawerType.GetCustomAttribute <DrawerPriorityAttribute>();
            }

            if (priorityAttribute != null)
            {
                this.Priority = priorityAttribute.Priority;
            }

            if (this.Priority == DrawerPriority.AutoPriority)
            {
                if (this.DrawnAttributeType != null)
                {
                    this.Priority = DrawerPriority.AttributePriority;
                }
                else
                {
                    this.Priority = DrawerPriority.ValuePriority;
                }
            }
        }
Ejemplo n.º 2
0
        private static DrawerPriority CalculateDrawerPriority(Type drawerType)
        {
            DrawerPriority priority = DrawerPriority.AutoPriority;

            // Find a DrawerPriorityAttribute if there is one anywhere and use the priority from that
            {
                DrawerPriorityAttribute priorityAttribute = null;

                if (DrawerIsUnityAlias(drawerType))
                {
                    // Special case for Unity property alias drawers;
                    // We should check if their assigned Unity drawer type
                    // itself declares a DrawerPriorityAttribute.

                    priorityAttribute = drawerType.GetGenericArguments()[0].GetCustomAttribute <DrawerPriorityAttribute>();
                }

                if (priorityAttribute == null)
                {
                    priorityAttribute = drawerType.GetCustomAttribute <DrawerPriorityAttribute>();
                }

                if (priorityAttribute != null)
                {
                    priority = priorityAttribute.Priority;
                }
            }

            // Figure out the drawer's actual priority if it's auto priority
            if (priority == DrawerPriority.AutoPriority)
            {
                if (drawerType.ImplementsOpenGenericClass(typeof(OdinAttributeDrawer <>)))
                {
                    priority = DrawerPriority.AttributePriority;
                }
                else
                {
                    priority = DrawerPriority.ValuePriority;
                }

                // All Odin drawers are slightly lower priority, so
                // that user-defined default-priority drawers always
                // override default-priority Odin drawers.
                if (drawerType.Assembly == typeof(OdinEditor).Assembly)
                {
                    priority.Value -= 0.001;
                }
            }

            return(priority);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the priority of a given drawer type.
        /// </summary>
        public static DrawerPriority GetDrawerPriority(Type drawerType)
        {
            DrawerPriority result;

            if (DrawerTypePriorityLookup.TryGetValue(drawerType, out result))
            {
                return(result);
            }
            else if (drawerType.IsGenericType && DrawerTypePriorityLookup.TryGetValue(drawerType.GetGenericTypeDefinition(), out result))
            {
                return(result);
            }

            bool hasResult = false;

            if (!hasResult)
            {
                for (int i = 0; i < PropertyDrawerInfos.Count; i++)
                {
                    if (PropertyDrawerInfos[i].DrawerType == drawerType)
                    {
                        result    = PropertyDrawerInfos[i].Priority;
                        hasResult = true;
                        break;
                    }
                }
            }

            if (!hasResult)
            {
                if (drawerType == typeof(InvalidTypeForAttributeDrawer))
                {
                    result    = typeof(InvalidTypeForAttributeDrawer).GetAttribute <DrawerPriorityAttribute>().Priority;
                    hasResult = true;
                }
            }

            if (!hasResult)
            {
                for (int i = 0; i < AttributeDrawerInfos.Count; i++)
                {
                    if (AttributeDrawerInfos[i].DrawerType == drawerType)
                    {
                        result    = AttributeDrawerInfos[i].Priority;
                        hasResult = true;
                        break;
                    }
                }
            }

            if (!hasResult)
            {
                for (int i = 0; i < GroupDrawerInfos.Count; i++)
                {
                    if (GroupDrawerInfos[i].DrawerType == drawerType)
                    {
                        result    = GroupDrawerInfos[i].Priority;
                        hasResult = true;
                        break;
                    }
                }
            }

            {
                DrawerPriorityAttribute attr = drawerType.GetAttribute <DrawerPriorityAttribute>();

                if (attr != null)
                {
                    result    = attr.Priority;
                    hasResult = true;
                }
            }

            if (!hasResult)
            {
                result = DrawerPriority.ValuePriority;
            }

            DrawerTypePriorityLookup.Add(drawerType, result);

            return(result);
        }