Beispiel #1
0
        /// <inheritdoc/>
        public override void AddComponentMember(int memberIndex, [NotNull] IComponentDrawer componentDrawer)
        {
            var category = ComponentCategories.Get(componentDrawer.Component);

                        #if DEV_MODE
            Debug.Log("AddComponentMember(" + memberIndex + ", " + componentDrawer.GetType().Name + ") category=\"" + category + "\", members.Length=" + members.Length);
                        #endif

            var categoryDrawer = GetOrCreateCategoryDrawer(category);

            if (categoryDrawer == null)
            {
                var setMembers = members;

                if (memberIndex == -1)
                {
                    memberIndex = setMembers.Length - LastCollectionMemberCountOffset + 1;
                }
                DrawerArrayPool.InsertAt(ref setMembers, memberIndex, componentDrawer, false);
                SetMembers(setMembers);
                return;
            }

            var setCategoryMembers = categoryDrawer.Members;
            DrawerArrayPool.InsertAt(ref setCategoryMembers, setCategoryMembers.Length, componentDrawer, false);
            categoryDrawer.SetMembers(setCategoryMembers);
        }
Beispiel #2
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
                        #if DEV_MODE
            Debug.Log(ToString() + ".DoBuildMembers()");
                        #endif

            ParentDrawerUtility.BuildMembers(DrawerProvider, this, memberBuildList, ref members);

            if (inspector.Preferences.drawScriptReferenceFields || DebugMode)
            {
                var monoScript = MonoScript;
                if (monoScript != null)
                {
                    DrawerArrayPool.InsertAt(ref members, 0, ScriptReferenceDrawer.Create(MonoScript, this, false), true);
                }
            }

            if (DebugMode && (members.Length == 0 || !(members[0] is DebugModeDisplaySettingsDrawer)))
            {
                                #if DEV_MODE
                Debug.Log("InsertAt(0, DebugModeDisplaySettingsDrawer)");
                                #endif

                DrawerArrayPool.InsertAt(ref members, 0, SpaceDrawer.Create(7f, this), true);
                DrawerArrayPool.InsertAt(ref members, 0, DebugModeDisplaySettingsDrawer.Create(this, debugModeDisplaySettings), true);
                DrawerArrayPool.InsertAt(ref members, 0, SpaceDrawer.Create(7f, this), true);
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(!members.ContainsNullMembers());
                        #endif
        }
Beispiel #3
0
        public static TDrawerWindow Create <TDrawerWindow>([NotNull] Component[] targets, [NotNull] IInspector inspector, Action doOnClosed = null) where TDrawerWindow : DrawerToWindow
        {
            var drawers = DrawerGroup.Create(inspector);
            var members = drawers.Members;

            DrawerArrayPool.InsertAt(ref members, 0, inspector.DrawerProvider.GetForComponents(inspector, targets, drawers), false);
            drawers.SetMembers(members);
            return(Create <TDrawerWindow>(drawers, doOnClosed));
        }
Beispiel #4
0
        public static TDrawerWindow Create <TDrawerWindow>([NotNull] GameObject[] targets, [NotNull] IInspector inspector, Action doOnClosed = null) where TDrawerWindow : DrawerToWindow
        {
            var drawers = DrawerGroup.Create(inspector);
            var members = drawers.Members;

            DrawerArrayPool.InsertAt(ref members, 0, GameObjectDrawer.Create(targets, drawers, inspector), false);
            drawers.SetMembers(members);
            return(Create <TDrawerWindow>(drawers, doOnClosed));
        }
Beispiel #5
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
                        #if DEV_MODE
            Debug.Log(ToString() + ".DoBuildMembers()");
                        #endif

            ParentDrawerUtility.BuildMembers(DrawerProvider, this, memberBuildList, ref members);

                        #if UNITY_EDITOR
            if (Platform.EditorMode && (inspector.Preferences.drawScriptReferenceFields || DebugMode))
            {
                var monoScript = MonoScript;
                if (monoScript != null)
                {
                    DrawerArrayPool.InsertAt(ref members, 0, ScriptReferenceDrawer.Create(MonoScript, this, false), true);
                }
            }
                        #endif
        }
Beispiel #6
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);
        }
Beispiel #7
0
        /// <inheritdoc/>
        public void OnMemberDragNDrop(MouseDownInfo mouseDownInfo, Object[] draggedObjects)
        {
            var reordering = mouseDownInfo.Reordering;

            int dropIndex = reordering.MouseoveredDropTarget.MemberIndex;

            if (dropIndex >= 0)
            {
                var draggedGameObjectDrawer = reordering.Drawer;

                //if only raw GameObject references are dragged, e.g. from the hierarchy view
                if (draggedGameObjectDrawer == null)
                {
                    var gameObjects = draggedObjects as GameObject[];
                    if (gameObjects != null)
                    {
                        var inspector = Inspector;

                                                #if DEV_MODE && PI_ASSERTATIONS
                        Debug.Assert(reordering.MouseoveredDropTarget.Inspector == inspector);
                                                #endif

                        //create a new GameObjectGUIInstrutions to display the dragged GameObjects
                        var gameObjectDrawer = inspector.DrawerProvider.GetForGameObjects(inspector, gameObjects, this);
                        if (gameObjectDrawer != null)
                        {
                            var setMembers = Members;
                            DrawerArrayPool.InsertAt(ref members, dropIndex, gameObjectDrawer, false);
                            SetMembers(setMembers, true);
                        }
                    }
                }
                else
                {
                    var sourceParent = reordering.Parent;
                    int sourceIndex  = reordering.MemberIndex;

                    //if reordering GameObjects within the same DrawerGroup (e.g. stacked multi-editing mode)
                    if (sourceParent == this)
                    {
                        if (dropIndex != sourceIndex)
                        {
                            inspector.State.ViewIsLocked = true;

                            var setMembers = Members;
                            DrawerArrayPool.RemoveAt(ref setMembers, sourceIndex, false, false);

                            if (sourceIndex < dropIndex)
                            {
                                dropIndex--;
                            }
                            DrawerArrayPool.InsertAt(ref setMembers, dropIndex, draggedGameObjectDrawer, false);

                            SetMembers(setMembers);
                        }
                    }
                    //if cloning (or moving?) GameObjects from one DrawerGroup to another (e.g. between split views)
                    else
                    {
                        var setMembers = Members;
                        var clone      = inspector.DrawerProvider.GetForGameObjects(reordering.MouseoveredDropTarget.Inspector, draggedGameObjectDrawer.GetValues() as GameObject[], this);
                        DrawerArrayPool.InsertAt(ref setMembers, dropIndex, clone, false);
                        SetMembers(setMembers);
                    }
                }
            }
        }