示例#1
0
        public static List <BaseDrawer> GetCompositeDrawers(EditorMember member, Attribute[] attributes, BaseGUI gui)
        {
            List <BaseDrawer> drawers;

            if (cachedCompositeDrawers.TryGetValue(member.Id, out drawers))
            {
                return(drawers);
            }

            drawers = new List <BaseDrawer>();

            var memberType = member.Type;

            // consider composition only if coreOnly was false, and the member type isn't a collection type,
            // or it is a collection type but it doesn't have any per attribute that signifies drawing per element
            // (in other words, the composition is applied on the collection itself, and not its elements)
            var considerComposition = !memberType.IsCollection() || !attributes.AnyDefined <DefinesElementDrawingAttribute>();

            if (considerComposition)
            {
                var compositeAttributes = attributes.OfType <CompositeAttribute>()
                                          .OrderBy(x => x.id)
                                          .ToList();

                for (int i = 0; i < compositeAttributes.Count; i++)
                {
                    drawers.AddIfNotNull(GetCompositeDrawer(memberType, compositeAttributes[i].GetType()));
                }
            }

            cachedCompositeDrawers.Add(member.Id, drawers);
            return(drawers);
        }
示例#2
0
        public static BaseDrawer GetMemberDrawer(EditorMember member, Attribute[] attributes)
        {
            BaseDrawer drawer;

            if (cachedMemberDrawers.TryGetValue(member.Id, out drawer))
            {
                return(drawer);
            }

            var memberType = member.Type;

            // check attribute drawer first
            var drawingAttribute = attributes.GetAttribute <DrawnAttribute>();

            if (drawingAttribute != null)
            {
                drawer = GetAttributeDrawer(memberType, drawingAttribute.GetType());
            }

            // if still null get an object drawer
            if (drawer == null)
            {
                drawer = GetObjectDrawer(memberType);
            }

            cachedMemberDrawers.Add(member.Id, drawer);

            return(drawer);
        }
示例#3
0
        public static List <BaseDrawer> GetCompositeDrawers(EditorMember member, Attribute[] attributes)
        {
            List <BaseDrawer> drawers;

            if (_cachedCompositeDrawers.TryGetValue(member.Id, out drawers))
            {
                return(drawers);
            }

            drawers = new List <BaseDrawer>();

            var applied = GetAppliedAttributes(member.Type, attributes);

            if (applied != null)
            {
                var compositeAttributes = applied.OfType <CompositeAttribute>()
                                          .OrderBy(x => x.id)
                                          .ToList();

                for (int i = 0; i < compositeAttributes.Count; i++)
                {
                    var drawer = NewCompositeDrawer(compositeAttributes[i].GetType());
                    if (!drawer.CanHandle(member.Type))
                    {
                        Debug.LogError("Drawer {0} can't seem to handle type {1}. Make sure you're not applying attributes on the wrong members"
                                       .FormatWith(drawer.GetType().GetNiceName(), member.TypeNiceName));
                        continue;
                    }
                    drawers.Add(drawer);
                }
            }

            _cachedCompositeDrawers.Add(member.Id, drawers);
            return(drawers);
        }
示例#4
0
        public static BaseDrawer GetMemberDrawer(EditorMember member, Attribute[] attributes, bool ignoreAttributes)
        {
            BaseDrawer drawer;

            if (_cachedMemberDrawers.TryGetValue(member.Id, out drawer))
            {
                return(drawer);
            }

            if (!ignoreAttributes)
            {
                var applied = GetAppliedAttributes(member.Type, attributes);
                if (applied != null)
                {
                    var drawingAttribute = applied.GetAttribute <DrawnAttribute>();
                    if (drawingAttribute != null)
                    {
                        drawer = NewDrawer(drawingAttribute.GetType());
                    }
                }
            }

            if (drawer == null)
            {
                drawer = NewObjectDrawer(member.Type);
            }

            if (!drawer.CanHandle(member.Type))
            {
                Debug.LogError("Drawer `{0}` can't seem to handle type `{1}`. Make sure you're not applying attributes on the wrong members"
                               .FormatWith(drawer.GetType().GetNiceName(), member.TypeNiceName));

                drawer = Mapper.GetDrawer(member.Type);
            }

            _cachedMemberDrawers.Add(member.Id, drawer);

            return(drawer);
        }
        public static List <BaseDrawer> GetCompositeDrawers(EditorMember member, Attribute[] attributes)
        {
            List <BaseDrawer> drawers;

            if (_cachedCompositeDrawers.TryGetValue(member.Id, out drawers))
            {
                return(drawers);
            }

            drawers = new List <BaseDrawer>();

            // consider composition only if the member type isn't a collection type,
            // or it is a collection type but it doesn't have any per attribute that signifies drawing per element
            // (in other words, the composition is applied on the collection itself, and not its elements)
            var considerComposition = !member.Type.IsCollection() || !attributes.Any(x => _definesElementDrawingAttributes.Contains(x.GetType()));

            if (considerComposition)
            {
                var compositeAttributes = attributes.OfType <CompositeAttribute>()
                                          .OrderBy(x => x.id)
                                          .ToList();

                for (int i = 0; i < compositeAttributes.Count; i++)
                {
                    var drawer = NewCompositeDrawer(compositeAttributes[i].GetType());
                    if (!drawer.CanHandle(member.Type))
                    {
                        Debug.LogError("Drawer {0} can't seem to handle type {1}. Make sure you're not applying attributes on the wrong members"
                                       .FormatWith(drawer.GetType().GetNiceName(), member.TypeNiceName));
                        continue;
                    }
                    drawers.Add(drawer);
                }
            }

            _cachedCompositeDrawers.Add(member.Id, drawers);
            return(drawers);
        }
        public static BaseDrawer GetMemberDrawer(EditorMember member, Attribute[] attributes, bool ignoreAttributes)
        {
            BaseDrawer drawer;

            if (_cachedMemberDrawers.TryGetValue(member.Id, out drawer))
            {
                return(drawer);
            }

            var canApplyDrawer = !member.Type.IsCollection() || !attributes.Any(x => _definesElementDrawingAttributes.Contains(x.GetType()));

            if (canApplyDrawer && !ignoreAttributes)
            {
                var drawingAttribute = attributes.GetAttribute <DrawnAttribute>();
                if (drawingAttribute != null)
                {
                    drawer = NewDrawer(drawingAttribute.GetType());
                }
            }

            if (drawer == null)
            {
                drawer = NewObjectDrawer(member.Type);
            }

            if (!drawer.CanHandle(member.Type))
            {
                Debug.LogError("Drawer `{0}` can't seem to handle type `{1}`. Make sure you're not applying attributes on the wrong members"
                               .FormatWith(drawer.GetType().GetNiceName(), member.TypeNiceName));

                drawer = Mapper.GetDrawer(member.Type);
            }

            _cachedMemberDrawers.Add(member.Id, drawer);

            return(drawer);
        }
        public static bool IsNull(this EditorMember member)
        {
            object value;

            return((member == null || member.Equals(null)) || ((value = member.Value) == null || value.Equals(null)));
        }