/// <summary>
        /// Initializes a new instance of the <see cref="ComplexTypePropertyChildren"/> class.
        /// </summary>
        /// <param name="property">The property to handle children for.</param>
        /// <exception cref="System.ArgumentException">
        /// Property to create complex type children for has no value entry.
        /// or
        /// Property must be either a reference type or a value type property.
        /// </exception>
        public ComplexTypePropertyChildren(InspectorProperty property) : base(property)
        {
            if (property.ValueEntry == null)
            {
                throw new ArgumentException("Property to create complex type children for has no value entry.");
            }

            if (property.Info.PropertyType != PropertyType.ReferenceType && property.Info.PropertyType != PropertyType.ValueType)
            {
                throw new ArgumentException("Property must be either a reference type or a value type property.");
            }

            this.ComplexType = property.ValueEntry.TypeOfValue;
            this.infos       = InspectorPropertyInfo.Get(this.ComplexType, property.Tree.IncludesSpeciallySerializedMembers && property.ValueEntry.SerializationBackend != SerializationBackend.Unity);
        }
Ejemplo n.º 2
0
        private static OdinDrawer[] GetAllDrawers(Type valueType, Type attributeType, List <DrawerInfo> drawers, bool forceUniqueDrawerInstances = false)
        {
            List <DrawerInfo> results = new List <DrawerInfo>();

            if (valueType == typeof(NoType))
            {
                valueType = null;
            }

            if (valueType != null)
            {
                // First, look for drawers which draw this exact type and/or attribute
                results.AddRange(GetExactTypeDrawerInfos(valueType, attributeType, drawers));

                // Then look for generic drawers where this type can fulfill the generic constraints
                results.AddRange(GetGenericTypeDrawerInfos(valueType, attributeType, drawers));
            }

            // Look for exact omni attribute drawers
            results.AddRange(GetExactTypeDrawerInfos(null, attributeType, drawers));

            // Look for generic omni attribute drawers
            results.AddRange(GetGenericTypeDrawerInfos(null, attributeType, drawers));

            foreach (var locator in CustomDrawerLocators)
            {
                results.AddRange(locator.GetDrawers(valueType, attributeType));
            }

            return(results.Distinct()
                   .OrderByDescending(info => info.Priority)
                   .ThenBy(info => info.DrawerType.Name)
                   .Select(info =>
            {
                try
                {
                    return GetDrawer(info.DrawerType, forceUniqueDrawerInstances);
                }
                catch (Exception ex)
                {
                    Debug.Log("Encountered the following exception when trying to instantiate a drawer of type " + info.DrawerType.GetNiceName());
                    Debug.LogException(ex);
                    return null;
                }
            })
                   .Where(drawer => drawer != null && (valueType == null || drawer.CanDrawTypeFilter(valueType)))
                   .Append(() =>
            {
                // Add composite drawer last, if it can be added - it is the final fallback for types with sub properties
                if (valueType != null && attributeType == null && !typeof(UnityEngine.Object).IsAssignableFrom(valueType) && InspectorPropertyInfo.Get(valueType, true).Length > 0)
                {
                    return CompositeDrawer;
                }

                return null;
            })
                   .Where(drawer => drawer != null)
                   .ToArray());
        }