Ejemplo n.º 1
0
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param>
        /// <param name="label"> The prefix label. </param>
        /// <param name="setReadOnly"> True if control should be read only. </param>
        /// <returns> The instance, ready to be used. </returns>
        public static CategorizedComponentsDrawer Create(IParentDrawer parent, GUIContent label)
        {
            CategorizedComponentsDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new CategorizedComponentsDrawer();
            }
            result.Setup(parent, label);
            result.LateSetup();
            return(result);
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        protected override void DoBuildMembers()
        {
                        #if DEV_MODE
            Debug.Log(ToString() + ".DoBuildMembers");
                        #endif

            int categoryCount = categorizedBuildList.Count;

            int newMemberCount = categoryCount;

            bool includeAddComponentButton = ShouldIncludeAddComponentButton();
            if (includeAddComponentButton)
            {
                newMemberCount++;
            }

            if (componentsOnlyOnSomeObjectsFound)
            {
                newMemberCount++;
            }

            DrawerArrayPool.Resize(ref members, newMemberCount);

            int index    = 0;
            var readOnly = ReadOnly;
            foreach (var categoryAndComponents in categorizedBuildList)
            {
                var category            = categoryAndComponents.Key;
                var categoryComponents  = categoryAndComponents.Value;
                int categoryMemberCount = categoryComponents.Count;

                if (category.Length == 0)
                {
                    int increaseMemberCount = categoryMemberCount - 1;
                    if (increaseMemberCount > 0)
                    {
                        newMemberCount += increaseMemberCount;
                        DrawerArrayPool.Resize(ref members, newMemberCount);
                    }

                    for (int n = 0; n < categoryMemberCount; n++)
                    {
                        var memberComponents = categoryComponents[n];
                        var componentDrawer  = DrawerProvider.GetForComponents(inspector, memberComponents, this);
                        members[index] = componentDrawer;
                        index++;
                    }
                }
                else
                {
                    var categoryDrawer = CategorizedComponentsDrawer.Create(this, GUIContentPool.Create(category));
                    var setMembers     = DrawerArrayPool.Create(categoryMemberCount);

                    for (int n = 0; n < categoryMemberCount; n++)
                    {
                        var memberComponents = categoryComponents[n];
                        var componentDrawer  = DrawerProvider.GetForComponents(inspector, memberComponents, categoryDrawer);
                        setMembers[n] = componentDrawer;
                    }

                    categoryDrawer.SetMembers(setMembers, true);
                    members[index] = categoryDrawer;
                    index++;
                }
            }

            if (componentsOnlyOnSomeObjectsFound)
            {
                members[index] = GameObjectBoxDrawer.Create(this, GUIContentPool.Create("Components found only on some selected objects can't be multi-edited."));
                index++;
            }

            if (includeAddComponentButton)
            {
                members[index] = AddComponentButtonDrawer.Create(this, inspector);
            }
        }
Ejemplo n.º 3
0
        protected CategorizedComponentsDrawer GetOrCreateCategoryDrawer(string category)
        {
            if (category.Length == 0)
            {
                                #if DEV_MODE && DEBUG_ADD_COMPONENT
                Debug.Log(ToString() + ".GetOrCreateCategoryDrawer(" + StringUtils.ToString(category) + "): returning null");
                                #endif
                return(null);
            }

            // try to find existing CategorizedComponentsDrawer
            for (int n = members.Length - LastCollectionMemberCountOffset; n >= 0; n--)
            {
                var member = members[n];
                if (string.Equals(member.Name, category, StringComparison.OrdinalIgnoreCase))
                {
                    var existingCategoryDrawer = member as CategorizedComponentsDrawer;
                    if (existingCategoryDrawer != null)
                    {
                                                #if DEV_MODE && DEBUG_ADD_COMPONENT
                        Debug.Log(ToString() + ".GetOrCreateCategoryDrawer(" + StringUtils.ToString(category) + "): existing found @ members[" + n + "]");
                                                #endif
                        return(existingCategoryDrawer);
                    }
                }
            }

            // create new CategorizedComponentsDrawer

                        #if DEV_MODE && PI_ASSERTATIONS
            int assertCount = members.Length + 1;
                        #endif

            var newCategoryDrawer = CategorizedComponentsDrawer.Create(this, GUIContentPool.Create(category));

            var setMembers = members;

            // insert new category drawer at the end, but before the add component button
            int insertAt = setMembers.Length - LastCollectionMemberCountOffset + 1;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(insertAt <= setMembers.Length);
            Debug.Assert(insertAt >= 0);
                        #endif

            DrawerArrayPool.InsertAt(ref setMembers, insertAt, newCategoryDrawer, false);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(!setMembers.ContainsNullMembers());
            Debug.Assert(!members.ContainsNullMembers());
            Debug.Assert(!visibleMembers.ContainsNullMembers());
            Debug.Assert(Array.IndexOf(setMembers, newCategoryDrawer) == insertAt);
                        #endif

            SetMembers(setMembers);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(members.Length == assertCount);
            Debug.Assert(setMembers.Length == assertCount);
            Debug.Assert(Array.IndexOf(members, newCategoryDrawer) == insertAt);
                        #endif

                        #if DEV_MODE && DEBUG_ADD_COMPONENT
            Debug.Log(ToString() + ".GetOrCreateCategoryDrawer(" + StringUtils.ToString(category) + "): created new and added @ members[" + insertAt + "]. members now:\n" + StringUtils.TypesToString(members, "\n"));
                        #endif

            return(newCategoryDrawer);
        }