static bool IsDropTargetUserModifiable(GameObjectTreeViewItem targetItem, DropPosition dropPos)
        {
            switch (dropPos)
            {
            case DropPosition.Upon:
                if (targetItem.objectPPTR != null)
                {
                    return(IsUserModifiable(targetItem.objectPPTR));
                }
                break;

            case DropPosition.Below:
            case DropPosition.Above:
                var targetParent = targetItem.parent as GameObjectTreeViewItem;
                if (targetParent != null && targetParent.objectPPTR != null)
                {
                    return(IsUserModifiable(targetParent.objectPPTR));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(dropPos), dropPos, null);
            }

            return(true);
        }
        public float PrefabModeButton(GameObjectTreeViewItem item, Rect selectionRect)
        {
            float contentRectRight = selectionRect.xMax;

            if (item.showPrefabModeButton)
            {
                float yOffset    = (selectionRect.height - GameObjectStyles.rightArrow.fixedWidth) / 2;
                Rect  buttonRect = new Rect(
                    selectionRect.xMax - GameObjectStyles.rightArrow.fixedWidth - GameObjectStyles.rightArrow.margin.right,
                    selectionRect.y + yOffset,
                    GameObjectStyles.rightArrow.fixedWidth,
                    GameObjectStyles.rightArrow.fixedHeight);

                int        instanceID = item.id;
                GUIContent content    = buttonRect.Contains(Event.current.mousePosition) ? PrefabStageUtility.GetPrefabButtonContent(instanceID) : GUIContent.none;
                if (GUI.Button(buttonRect, content, GameObjectStyles.rightArrow))
                {
                    GameObject go             = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
                    string     assetPath      = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go);
                    Object     originalSource = AssetDatabase.LoadMainAssetAtPath(assetPath);
                    if (originalSource != null)
                    {
                        var prefabStageMode = PrefabStageUtility.GetPrefabStageModeFromModifierKeys();
                        PrefabStageUtility.OpenPrefab(assetPath, go, prefabStageMode, StageNavigationManager.Analytics.ChangeType.EnterViaInstanceHierarchyRightArrow);
                    }
                }

                contentRectRight = buttonRect.xMin;
            }

            return(contentRectRight);
        }
        protected void DoAdditionalSceneHeaderGUI(GameObjectTreeViewItem goItem, Rect rect)
        {
            Rect position = new Rect(rect.width - 16f - 4f, rect.y + (rect.height - 6f) * 0.5f, 16f, rect.height);

            if (Event.current.type == EventType.Repaint)
            {
                GameObjectTreeViewGUI.GameObjectStyles.optionsButtonStyle.Draw(position, false, false, false, false);
            }
            position.y      = rect.y;
            position.height = rect.height;
            position.width  = 24f;
            if (EditorGUI.DropdownButton(position, GUIContent.none, FocusType.Passive, GUIStyle.none))
            {
                this.m_TreeView.SelectionClick(goItem, true);
                this.m_TreeView.contextClickItemCallback(goItem.id);
            }
            if (GameObjectTreeViewGUI.OnPostHeaderGUI != null)
            {
                float num           = rect.width - position.x;
                float width         = rect.width - num - 4f;
                float x             = 0f;
                float y             = rect.y;
                float height        = rect.height;
                Rect  availableRect = new Rect(x, y, width, height);
                GameObjectTreeViewGUI.OnPostHeaderGUI(availableRect, goItem.scene.path);
            }
        }
 int GetDropTargetInstanceID(GameObjectTreeViewItem hierarchyTargetItem, DropPosition dropPosition)
 {
     if (SubSceneGUI.IsUsingSubScenes())
     {
         var gameObjectDropTarget = hierarchyTargetItem.objectPPTR as GameObject;
         if (gameObjectDropTarget != null)
         {
             if (dropPosition == DropPosition.Above)
             {
                 return(hierarchyTargetItem.id);
             }
             if (SubSceneGUI.IsSubSceneHeader(gameObjectDropTarget))
             {
                 Scene subScene = SubSceneGUI.GetSubScene(gameObjectDropTarget);
                 if (subScene.IsValid())
                 {
                     return(subScene.handle);
                 }
                 else
                 {
                     return(0);
                 }
             }
         }
     }
     return(hierarchyTargetItem.id);
 }
        void SetItemIcon(GameObjectTreeViewItem item)
        {
            var go = item.objectPPTR as GameObject;

            if (go == null)
            {
                if (IsPrefabStageHeader(item))
                {
                    string prefabAssetPath = PrefabStageUtility.GetCurrentPrefabStage().prefabAssetPath;
                    item.icon = (Texture2D)AssetDatabase.GetCachedIcon(prefabAssetPath);
                }
                else
                {
                    item.icon = GameObjectStyles.sceneAssetIcon;
                }
            }
            else
            {
                if (SubSceneGUI.IsSubSceneHeader(go))
                {
                    item.icon = GameObjectStyles.sceneAssetIcon;
                }
                else
                {
                    item.icon = PrefabUtility.GetIconForGameObject(go);
                }
            }
        }
        protected override void OnAdditionalGUI(Rect rect, int row, TreeViewItem item, bool selected, bool focused)
        {
            GameObjectTreeViewItem goItem = item as GameObjectTreeViewItem;

            if (goItem == null)
            {
                return;
            }

            m_ContentRectRight = 0;

            if (goItem.isSceneHeader)
            {
                m_ContentRectRight = DoAdditionalSceneHeaderGUI(goItem, rect);
            }
            else
            {
                m_ContentRectRight = PrefabModeButton(goItem, rect);
                if (SubSceneGUI.IsUsingSubScenes() && !showingSearchResults)
                {
                    SubSceneGUI.DrawVerticalLine(rect, k_BaseIndent, k_IndentWidth, (GameObject)goItem.objectPPTR);
                }

                HandlePrefabInstanceOverrideStatus(goItem, rect, selected, focused);
            }

            if (SceneHierarchy.s_Debug)
            {
                GUI.Label(new Rect(rect.xMax - 70, rect.y, 70, rect.height), "" + row + " (" + goItem.id + ")", EditorStyles.boldLabel);
            }
        }
 private void InitTreeViewItem(GameObjectTreeViewItem item, int itemID, Scene scene, bool isSceneHeader, int colorCode, UnityEngine.Object pptrObject, bool hasChildren, int depth)
 {
     item.children = null;
     item.userData = null;
     item.id       = itemID;
     item.depth    = depth;
     item.parent   = null;
     if (isSceneHeader)
     {
         item.displayName = ((!string.IsNullOrEmpty(scene.name)) ? scene.name : "Untitled");
     }
     else
     {
         item.displayName = null;
     }
     item.colorCode     = colorCode;
     item.objectPPTR    = pptrObject;
     item.shouldDisplay = true;
     item.isSceneHeader = isSceneHeader;
     item.scene         = scene;
     item.icon          = ((!isSceneHeader) ? null : EditorGUIUtility.FindTexture("SceneAsset Icon"));
     if (hasChildren)
     {
         item.children = LazyTreeViewDataSource.CreateChildListForCollapsedParent();
     }
 }
        protected float DoAdditionalSceneHeaderGUI(GameObjectTreeViewItem goItem, Rect rect)
        {
            const float margin = 4f;
            Rect        buttonRect;

            if (DoOptionsButton(rect, out buttonRect))
            {
                // Ensure item is selected before using context menu (menu logic is based on selection)
                m_TreeView.SelectionClick(goItem, true);
                m_TreeView.contextClickItemCallback(goItem.id);
            }

            float availableRectLeft = buttonRect.xMin;

            if (null != OnPostHeaderGUI)
            {
                float optionsWidth  = (rect.width - buttonRect.x);
                float width         = (rect.width - optionsWidth - margin);
                float x             = 0;
                float y             = rect.y;
                float height        = rect.height;
                Rect  availableRect = new Rect(x, y, width, height);
                availableRectLeft = Math.Min(availableRectLeft, OnPostHeaderGUI(availableRect, goItem.scene.path));
            }

            return(availableRectLeft);
        }
        static DragAndDropVisualMode PrefabModeDraggingHandler(GameObjectTreeViewItem parentItem, GameObjectTreeViewItem targetItem, TreeViewDragging.DropPosition dropPos, bool perform)
        {
            var stage = StageNavigationManager.instance.currentItem;

            if (!stage.isPrefabStage)
            {
                throw new InvalidOperationException("PrefabModeDraggingHandler should only be called in Prefab Mode");
            }

            // Disallow dropping as sibling to the prefab instance root (In Prefab Mode we only want to show one root).
            if (parentItem != null && parentItem.parent == null && dropPos != TreeViewDragging.DropPosition.Upon)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            // Check for cyclic nesting (only on perform since it is an expensive operation)
            if (perform)
            {
                var prefabAssetThatIsAddedTo = AssetDatabase.LoadMainAssetAtPath(stage.prefabAssetPath);
                foreach (var dragged in DragAndDrop.objectReferences)
                {
                    if (dragged is GameObject && EditorUtility.IsPersistent(dragged))
                    {
                        var prefabAssetThatWillBeAdded = dragged;
                        if (PrefabUtility.CheckIfAddingPrefabWouldResultInCyclicNesting(prefabAssetThatIsAddedTo, prefabAssetThatWillBeAdded))
                        {
                            PrefabUtility.ShowCyclicNestingWarningDialog();
                            return(DragAndDropVisualMode.Rejected);
                        }
                    }
                }
            }

            return(DragAndDropVisualMode.None);
        }
Example #10
0
        private void InitTreeViewItem(GameObjectTreeViewItem item, int itemID, Scene scene, bool isSceneHeader, int colorCode, Object pptrObject, bool hasChildren, int depth)
        {
            item.children = null;
            item.id       = itemID;
            item.depth    = depth;
            item.parent   = null;
            if (isSceneHeader)
            {
                item.displayName = string.IsNullOrEmpty(scene.name) ? "Untitled" : scene.name;
            }
            else
            {
                item.displayName = null; // For GameObject, name is empty as the name gets set from the objectPPTR if the Item is used in GameObjectTreeViewGUI.
            }
            item.colorCode     = colorCode;
            item.objectPPTR    = pptrObject;
            item.shouldDisplay = true;
            item.isSceneHeader = isSceneHeader;
            item.scene         = scene;
            item.icon          = isSceneHeader ? EditorGUIUtility.FindTexture(typeof(SceneAsset)) : null;

            if (hasChildren)
            {
                item.children = CreateChildListForCollapsedParent(); // add a dummy child in children list to ensure we show the collapse arrow (because we do not fetch data for collapsed items)
            }
        }
Example #11
0
        public override bool BeginRename(TreeViewItem item, float delay)
        {
            GameObjectTreeViewItem gameObjectTreeViewItem = item as GameObjectTreeViewItem;
            bool result;

            if (gameObjectTreeViewItem == null)
            {
                result = false;
            }
            else if (gameObjectTreeViewItem.isSceneHeader)
            {
                result = false;
            }
            else
            {
                UnityEngine.Object objectPPTR = gameObjectTreeViewItem.objectPPTR;
                if ((objectPPTR.hideFlags & HideFlags.NotEditable) != HideFlags.None)
                {
                    Debug.LogWarning("Unable to rename a GameObject with HideFlags.NotEditable.");
                    result = false;
                }
                else
                {
                    result = base.BeginRename(item, delay);
                }
            }
            return(result);
        }
Example #12
0
        private void HandleContextClick()
        {
            Event current = Event.current;

            if (current.type == EventType.ContextClick)
            {
                current.Use();
                GenericMenu menu = new GenericMenu();
                menu.AddItem(EditorGUIUtility.TextContent("Copy"), false, new GenericMenu.MenuFunction(this.CopyGO));
                menu.AddItem(EditorGUIUtility.TextContent("Paste"), false, new GenericMenu.MenuFunction(this.PasteGO));
                menu.AddSeparator(string.Empty);
                if (!base.hasSearchFilter && (this.m_TreeViewState.selectedIDs.Count == 1))
                {
                    menu.AddItem(EditorGUIUtility.TextContent("Rename"), false, new GenericMenu.MenuFunction(this.RenameGO));
                }
                else
                {
                    menu.AddDisabledItem(EditorGUIUtility.TextContent("Rename"));
                }
                menu.AddItem(EditorGUIUtility.TextContent("Duplicate"), false, new GenericMenu.MenuFunction(this.DuplicateGO));
                menu.AddItem(EditorGUIUtility.TextContent("Delete"), false, new GenericMenu.MenuFunction(this.DeleteGO));
                menu.AddSeparator(string.Empty);
                bool flag = false;
                if (this.m_TreeViewState.selectedIDs.Count == 1)
                {
                    GameObjectTreeViewItem item = this.treeView.FindNode(this.m_TreeViewState.selectedIDs[0]) as GameObjectTreeViewItem;
                    if (item != null)
                    {
        void SetItemOverlayIcon(GameObjectTreeViewItem item)
        {
            item.overlayIcon = null;

            var go = item.objectPPTR as GameObject;

            if (go == null)
            {
                return;
            }

            if (PrefabUtility.IsAddedGameObjectOverride(go))
            {
                item.overlayIcon = EditorGUIUtility.LoadIcon("PrefabOverlayAdded Icon");
            }


            if (!EditorApplication.isPlaying)
            {
                Asset asset = GetAsset(item);
                if (asset != null && !m_HierarchyPrefabToAssetIDMap.ContainsKey(item.id))
                {
                    string  metaPath  = asset.path.Trim('/') + ".meta";
                    Asset   metaAsset = Provider.GetAssetByPath(metaPath);
                    Asset[] assets    = new[] { asset, metaAsset };

                    m_HierarchyPrefabToAssetIDMap.Add(item.id, assets);
                }
            }
        }
Example #14
0
        protected void DoAdditionalSceneHeaderGUI(GameObjectTreeViewItem goItem, Rect rect)
        {
            // Options button
            const float optionsButtonWidth  = 16f;
            const float optionsButtonHeight = 6f;
            const float margin     = 4f;
            Rect        buttonRect = new Rect(rect.width - optionsButtonWidth - margin, rect.y + (rect.height - optionsButtonHeight) * 0.5f, optionsButtonWidth, rect.height);

            if (Event.current.type == EventType.Repaint)
            {
                GameObjectStyles.optionsButtonStyle.Draw(buttonRect, false, false, false, false);
            }

            // We want larger click area than the button icon
            buttonRect.y      = rect.y;
            buttonRect.height = rect.height;
            buttonRect.width  = 24f;
            if (EditorGUI.DropdownButton(buttonRect, GUIContent.none, FocusType.Passive, GUIStyle.none))
            {
                // Ensure item is selected before using context menu (menu logic is based on selection)
                m_TreeView.SelectionClick(goItem, true);
                m_TreeView.contextClickItemCallback(goItem.id);
            }

            if (null != OnPostHeaderGUI)
            {
                float optionsWidth  = (rect.width - buttonRect.x);
                float width         = (rect.width - optionsWidth - margin);
                float x             = 0;
                float y             = rect.y;
                float height        = rect.height;
                Rect  availableRect = new Rect(x, y, width, height);
                OnPostHeaderGUI(availableRect, goItem.scene.path);
            }
        }
Example #15
0
        private void InitTreeViewItem(GameObjectTreeViewItem item, int itemID, Scene scene, bool isSceneHeader, int colorCode, Object pptrObject, bool hasChildren, int depth)
        {
            item.children = null;
            item.id       = itemID;
            item.depth    = depth;
            item.parent   = null;
            item.icon     = null;
            if (isSceneHeader)
            {
                item.displayName = string.IsNullOrEmpty(scene.name) ? "Untitled" : scene.name;
            }
            else
            {
                item.displayName = null; // For GameObject, name is empty as the name gets set from the objectPPTR if the Item is used in GameObjectTreeViewGUI.
            }
            item.colorCode     = colorCode;
            item.objectPPTR    = pptrObject;
            item.isSceneHeader = isSceneHeader;
            item.scene         = scene;

            item.lazyInitializationDone = false;
            item.showPrefabModeButton   = false;
            item.overlayIcon            = null;

            if (hasChildren)
            {
                item.children = CreateChildListForCollapsedParent(); // add a dummy child in children list to ensure we show the collapse arrow (because we do not fetch data for collapsed items)
            }
        }
Example #16
0
        override protected void DoItemGUI(Rect rect, int row, TreeViewItem item, bool selected, bool focused, bool useBoldFont)
        {
            GameObjectTreeViewItem goItem = item as GameObjectTreeViewItem;

            if (goItem == null)
            {
                return;
            }

            // Scene header background (make it slightly transparent to hint it
            // is not the normal scene header)
            if (goItem.isSceneHeader)
            {
                Color oldColor = GUI.color;
                GUI.color = GUI.color * new Color(1, 1, 1, 0.9f);
                GUI.Label(rect, GUIContent.none, GameObjectStyles.sceneHeaderBg);
                GUI.color = oldColor;
            }

            base.DoItemGUI(rect, row, item, selected, focused, useBoldFont);

            // Scene header extras
            if (goItem.isSceneHeader)
            {
                DoAdditionalSceneHeaderGUI(goItem, rect);
            }

            if (SceneHierarchyWindow.s_Debug)
            {
                GUI.Label(new Rect(rect.xMax - 70, rect.y, 70, rect.height), "" + row + " (" + goItem.id + ")", EditorStyles.boldLabel);
            }
        }
        private int InitializeSearchResults(HierarchyProperty property, int minAllowedDepth)
        {
            int currentSceneHandle = -1;
            int row = 0;

            while (property.NextWithDepthCheck((int[])null, minAllowedDepth))
            {
                GameObjectTreeViewItem objectTreeViewItem = this.EnsureCreatedItem(row);
                if (this.AddSceneHeaderToSearchIfNeeded(objectTreeViewItem, property, ref currentSceneHandle))
                {
                    ++row;
                    if (!this.IsSceneHeader(property))
                    {
                        objectTreeViewItem = this.EnsureCreatedItem(row);
                    }
                    else
                    {
                        continue;
                    }
                }
                this.InitTreeViewItem(objectTreeViewItem, property, false, 0);
                ++row;
            }
            return(row);
        }
 void SetItemSelectedIcon(GameObjectTreeViewItem item)
 {
     if (item.icon != null)
     {
         item.selectedIcon = EditorUtility.GetIconInActiveState(item.icon) as Texture2D;
     }
 }
        protected override void DoItemGUI(Rect rect, int row, TreeViewItem item, bool selected, bool focused, bool useBoldFont)
        {
            GameObjectTreeViewItem gameObjectTreeViewItem = item as GameObjectTreeViewItem;

            if (gameObjectTreeViewItem == null)
            {
                return;
            }
            if (gameObjectTreeViewItem.isSceneHeader)
            {
                Color color = GUI.color;
                GUI.color *= new Color(1f, 1f, 1f, 0.9f);
                GUI.Label(rect, GUIContent.none, GameObjectTreeViewGUI.s_GOStyles.sceneHeaderBg);
                GUI.color = color;
            }
            base.DoItemGUI(rect, row, item, selected, focused, useBoldFont);
            if (gameObjectTreeViewItem.isSceneHeader)
            {
                this.DoAdditionalSceneHeaderGUI(gameObjectTreeViewItem, rect);
            }
            if (SceneHierarchyWindow.s_Debug)
            {
                GUI.Label(new Rect(rect.xMax - 70f, rect.y, 70f, rect.height), string.Concat(new object[]
                {
                    string.Empty,
                    row,
                    " (",
                    gameObjectTreeViewItem.id,
                    ")"
                }), EditorStyles.boldLabel);
            }
        }
Example #20
0
        protected override void DrawIconAndLabel(Rect rect, TreeViewItem item, string label, bool selected, bool focused, bool useBoldFont, bool isPinging)
        {
            GameObjectTreeViewItem objectTreeViewItem = item as GameObjectTreeViewItem;

            if (objectTreeViewItem == null)
            {
                return;
            }
            if (objectTreeViewItem.isSceneHeader)
            {
                if (objectTreeViewItem.scene.isDirty)
                {
                    label += "*";
                }
                if (!objectTreeViewItem.scene.isLoaded)
                {
                    label += " (not loaded)";
                }
                bool useBoldFont1 = objectTreeViewItem.scene == SceneManager.GetActiveScene();
                EditorGUI.BeginDisabledGroup(!objectTreeViewItem.scene.isLoaded);
                base.DrawIconAndLabel(rect, item, label, selected, focused, useBoldFont1, isPinging);
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                if (!isPinging)
                {
                    float contentIndent = this.GetContentIndent(item);
                    rect.x     += contentIndent;
                    rect.width -= contentIndent;
                }
                int colorCode = objectTreeViewItem.colorCode;
                if (string.IsNullOrEmpty(item.displayName))
                {
                    objectTreeViewItem.displayName = !(objectTreeViewItem.objectPPTR != (UnityEngine.Object)null) ? "deleted gameobject" : objectTreeViewItem.objectPPTR.name;
                    label = objectTreeViewItem.displayName;
                }
                GUIStyle guiStyle = TreeViewGUI.s_Styles.lineStyle;
                if (!objectTreeViewItem.shouldDisplay)
                {
                    guiStyle = GameObjectTreeViewGUI.s_GOStyles.disabledLabel;
                }
                else if ((colorCode & 3) == 0)
                {
                    guiStyle = colorCode >= 4 ? GameObjectTreeViewGUI.s_GOStyles.disabledLabel : TreeViewGUI.s_Styles.lineStyle;
                }
                else if ((colorCode & 3) == 1)
                {
                    guiStyle = colorCode >= 4 ? GameObjectTreeViewGUI.s_GOStyles.disabledPrefabLabel : GameObjectTreeViewGUI.s_GOStyles.prefabLabel;
                }
                else if ((colorCode & 3) == 2)
                {
                    guiStyle = colorCode >= 4 ? GameObjectTreeViewGUI.s_GOStyles.disabledBrokenPrefabLabel : GameObjectTreeViewGUI.s_GOStyles.brokenPrefabLabel;
                }
                guiStyle.padding.left = (int)this.k_SpaceBetweenIconAndText;
                guiStyle.Draw(rect, label, false, false, selected, focused);
            }
        }
 void EnsureLazyInitialization(GameObjectTreeViewItem item)
 {
     if (!item.lazyInitializationDone)
     {
         item.lazyInitializationDone = true;
         SetItemIcon(item);
         SetItemOverlayIcon(item);
         SetPrefabModeButtonVisibility(item);
     }
 }
        public static void DoItemGUI(Rect rect, GameObjectTreeViewItem goItem, bool isSelected, bool isHovered, bool isFocused, bool isDragging)
        {
            if (Event.current.isKey || Event.current.type == EventType.Layout)
            {
                return;
            }

            Rect iconRect = rect;

            iconRect.xMin += k_VisibilityIconPadding;
            iconRect.width = k_IconWidth;
            isHovered      = isHovered && !isDragging;
            bool isIconHovered = !isDragging && iconRect.Contains(Event.current.mousePosition);

            Rect icon2Rect = rect;

            icon2Rect.xMin += 2 * k_VisibilityIconPadding + k_IconWidth;
            icon2Rect.width = k_IconWidth;
            bool isIcon2Hovered = !isDragging && icon2Rect.Contains(Event.current.mousePosition);

            if (isHovered)
            {
                GUIView.current.MarkHotRegion(GUIClip.UnclipToWindow(iconRect));
                GUIView.current.MarkHotRegion(GUIClip.UnclipToWindow(icon2Rect));
            }

            GameObject gameObject = goItem.objectPPTR as GameObject;

            if (gameObject)
            {
                // The scene header overlaps it's next item by some pixels. Displace the background so it doesn't draw on top of the scene header.
                // Don't displace when selected or hovered (They already show on top of the header)
                if (m_PrevItemWasScene && !isSelected && !isHovered)
                {
                    rect.yMin += k_sceneHeaderOverflow;
                }

                DrawItemBackground(rect, false, isSelected, isHovered, isFocused);
                DrawGameObjectItemVisibility(iconRect, gameObject, isHovered, isIconHovered);
                DrawGameObjectItemPicking(icon2Rect, gameObject, isHovered, isIcon2Hovered);

                m_PrevItemWasScene = false;
            }
            else
            {
                Scene scene = goItem.scene;
                if (scene.IsValid())
                {
                    DrawItemBackground(rect, true, isSelected, isHovered, isFocused);
                    DrawSceneItemVisibility(iconRect, scene, isHovered, isIconHovered);
                    DrawSceneItemPicking(icon2Rect, scene, isHovered, isIcon2Hovered);
                    m_PrevItemWasScene = true;
                }
            }
        }
Example #23
0
        private void DoStickySceneHeaders()
        {
            int firstRowVisible;
            int lastRowVisible;

            this.GetFirstAndLastRowVisible(out firstRowVisible, out lastRowVisible);
            if (firstRowVisible < 0 || lastRowVisible < 0)
            {
                return;
            }
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            GameObjectTreeViewGUI.\u003CDoStickySceneHeaders\u003Ec__AnonStorey79 headersCAnonStorey79 = new GameObjectTreeViewGUI.\u003CDoStickySceneHeaders\u003Ec__AnonStorey79();
            float y = this.m_TreeView.state.scrollPos.y;

            if (firstRowVisible == 0 && (double)y <= (double)this.topRowMargin)
            {
                return;
            }
            // ISSUE: reference to a compiler-generated field
            headersCAnonStorey79.firstItem = (GameObjectTreeViewItem)this.m_TreeView.data.GetItem(firstRowVisible);
            GameObjectTreeViewItem objectTreeViewItem = (GameObjectTreeViewItem)this.m_TreeView.data.GetItem(firstRowVisible + 1);
            // ISSUE: reference to a compiler-generated field
            bool  flag    = headersCAnonStorey79.firstItem.scene != objectTreeViewItem.scene;
            float width   = GUIClip.visibleRect.width;
            Rect  rowRect = this.GetRowRect(firstRowVisible, width);

            // ISSUE: reference to a compiler-generated field
            if (headersCAnonStorey79.firstItem.isSceneHeader && Mathf.Approximately(y, rowRect.y))
            {
                return;
            }
            if (!flag)
            {
                rowRect.y = y;
            }
            // ISSUE: reference to a compiler-generated method
            GameObjectTreeViewItem sceneHeaderItem = ((GameObjectTreeViewDataSource)this.m_TreeView.data).sceneHeaderItems.FirstOrDefault <GameObjectTreeViewItem>(new Func <GameObjectTreeViewItem, bool>(headersCAnonStorey79.\u003C\u003Em__117));

            if (sceneHeaderItem == null)
            {
                return;
            }
            bool selected    = this.m_TreeView.IsItemDragSelectedOrSelected((TreeViewItem)sceneHeaderItem);
            bool focused     = this.m_TreeView.HasFocus();
            bool useBoldFont = sceneHeaderItem.scene == SceneManager.GetActiveScene();

            this.DoNodeGUI(rowRect, firstRowVisible, (TreeViewItem)sceneHeaderItem, selected, focused, useBoldFont);
            if (GUI.Button(new Rect(rowRect.x, rowRect.y, rowRect.height, rowRect.height), GUIContent.none, GUIStyle.none))
            {
                this.m_TreeView.Frame(sceneHeaderItem.id, true, false);
            }
            this.m_TreeView.HandleUnusedMouseEventsForNode(rowRect, (TreeViewItem)sceneHeaderItem, false);
            this.HandleStickyHeaderContextClick(rowRect, sceneHeaderItem);
        }
        internal override Texture GetIconForSelectedItem(TreeViewItem item)
        {
            GameObjectTreeViewItem goItem = item as GameObjectTreeViewItem;

            if (goItem != null)
            {
                return(goItem.selectedIcon);
            }

            return(item.icon);
        }
        public override bool BeginRename(TreeViewItem item, float delay)
        {
            GameObjectTreeViewItem item2 = item as GameObjectTreeViewItem;

            if ((item2.objectPPTR.hideFlags & HideFlags.NotEditable) != HideFlags.None)
            {
                Debug.LogWarning("Unable to rename a GameObject with HideFlags.NotEditable.");
                return(false);
            }
            return(base.BeginRename(item, delay));
        }
        private bool AddSceneHeaderToSearchIfNeeded(GameObjectTreeViewItem item, HierarchyProperty property, ref int currentSceneHandle)
        {
            Scene scene = property.GetScene();

            if (currentSceneHandle != scene.handle)
            {
                currentSceneHandle = scene.handle;
                this.InitTreeViewItem(item, scene.handle, scene, true, 0, null, false, 0);
                return(true);
            }
            return(false);
        }
Example #27
0
        protected override void DrawIconAndLabel(Rect rect, TreeViewItem item, string label, bool selected, bool focused, bool useBoldFont, bool isPinging)
        {
            if (!isPinging)
            {
                float contentIndent = this.GetContentIndent(item);
                rect.x     += contentIndent;
                rect.width -= contentIndent;
            }
            GameObjectTreeViewItem gameObjectTreeViewItem = item as GameObjectTreeViewItem;
            int colorCode = gameObjectTreeViewItem.colorCode;

            if (string.IsNullOrEmpty(item.displayName))
            {
                if (gameObjectTreeViewItem.objectPPTR != null)
                {
                    gameObjectTreeViewItem.displayName = gameObjectTreeViewItem.objectPPTR.name;
                }
                else
                {
                    gameObjectTreeViewItem.displayName = "deleted gameobject";
                }
                label = gameObjectTreeViewItem.displayName;
            }
            GUIStyle gUIStyle = TreeViewGUI.s_Styles.lineStyle;

            if (!gameObjectTreeViewItem.shouldDisplay)
            {
                gUIStyle = GameObjectTreeViewGUI.s_GOStyles.disabledLabel;
            }
            else
            {
                if ((colorCode & 3) == 0)
                {
                    gUIStyle = ((colorCode >= 4) ? GameObjectTreeViewGUI.s_GOStyles.disabledLabel : TreeViewGUI.s_Styles.lineStyle);
                }
                else
                {
                    if ((colorCode & 3) == 1)
                    {
                        gUIStyle = ((colorCode >= 4) ? GameObjectTreeViewGUI.s_GOStyles.disabledPrefabLabel : GameObjectTreeViewGUI.s_GOStyles.prefabLabel);
                    }
                    else
                    {
                        if ((colorCode & 3) == 2)
                        {
                            gUIStyle = ((colorCode >= 4) ? GameObjectTreeViewGUI.s_GOStyles.disabledBrokenPrefabLabel : GameObjectTreeViewGUI.s_GOStyles.brokenPrefabLabel);
                        }
                    }
                }
            }
            gUIStyle.padding.left = (int)this.k_SpaceBetweenIconAndText;
            gUIStyle.Draw(rect, label, false, false, selected, focused);
        }
Example #28
0
        private void HandleContextClick()
        {
            Event current = Event.current;

            if (current.type != EventType.ContextClick)
            {
                return;
            }
            current.Use();
            GenericMenu genericMenu = new GenericMenu();

            genericMenu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupCopy"), false, new GenericMenu.MenuFunction(this.CopyGO));
            genericMenu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupPaste"), false, new GenericMenu.MenuFunction(this.PasteGO));
            genericMenu.AddSeparator(string.Empty);
            if (!base.hasSearchFilter && this.m_TreeViewState.selectedIDs.Count == 1)
            {
                genericMenu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupRename"), false, new GenericMenu.MenuFunction(this.RenameGO));
            }
            else
            {
                genericMenu.AddDisabledItem(EditorGUIUtility.TextContent("HierarchyPopupRename"));
            }
            genericMenu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupDuplicate"), false, new GenericMenu.MenuFunction(this.DuplicateGO));
            genericMenu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupDelete"), false, new GenericMenu.MenuFunction(this.DeleteGO));
            genericMenu.AddSeparator(string.Empty);
            bool flag = false;

            if (this.m_TreeViewState.selectedIDs.Count == 1)
            {
                GameObjectTreeViewItem gameObjectTreeViewItem = this.treeView.FindNode(this.m_TreeViewState.selectedIDs[0]) as GameObjectTreeViewItem;
                if (gameObjectTreeViewItem != null)
                {
                    UnityEngine.Object prefab = PrefabUtility.GetPrefabParent(gameObjectTreeViewItem.objectPPTR);
                    if (prefab != null)
                    {
                        genericMenu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupSelectPrefab"), false, delegate
                        {
                            Selection.activeObject = prefab;
                            EditorGUIUtility.PingObject(prefab.GetInstanceID());
                        });
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                genericMenu.AddDisabledItem(EditorGUIUtility.TextContent("HierarchyPopupSelectPrefab"));
            }
            genericMenu.AddSeparator(string.Empty);
            this.AddCreateGameObjectItemsToMenu(genericMenu, Selection.objects, false);
            genericMenu.ShowAsContext();
        }
        void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item)
        {
            item.showPrefabModeButton = false;

            GameObject go = item.objectPPTR as GameObject;

            if (go == null)
            {
                return;
            }

            if (!PrefabUtility.IsPartOfAnyPrefab(go))
            {
                return;
            }

            if (!PrefabUtility.IsAnyPrefabInstanceRoot(go))
            {
                return;
            }

            // Don't show button if prefab asset is missing
            if (PrefabUtility.GetPrefabInstanceStatus(go) == PrefabInstanceStatus.Connected)
            {
                var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go);
                if (source == null)
                {
                    return;
                }

                // Don't show buttons for model prefabs but allow buttons for other immutables
                if (PrefabUtility.IsPartOfModelPrefab(source))
                {
                    return;
                }
            }
            else if (PrefabUtility.GetPrefabInstanceHandle(go) == null)
            {
                return;
            }
            else
            {
                var assetPath = PrefabUtility.GetAssetPathOfSourcePrefab(go);
                var broken    = AssetDatabase.LoadMainAssetAtPath(assetPath) as BrokenPrefabAsset;
                if (broken == null || !broken.isPrefabFileValid)
                {
                    return;
                }
            }

            item.showPrefabModeButton = true;
        }
 private GameObjectTreeViewItem CreateTreeViewItem(HierarchyProperty property, bool hasSearchString, int depth, bool shouldDisplay)
 {
     GameObjectTreeViewItem item = new GameObjectTreeViewItem(property.instanceID, depth, null, string.Empty) {
         colorCode = property.colorCode,
         objectPPTR = property.pptrValue,
         shouldDisplay = shouldDisplay
     };
     if (!hasSearchString && property.hasChildren)
     {
         item.children = LazyTreeViewDataSource.CreateChildListForCollapsedParent();
     }
     return item;
 }
        static string GetAssetGUID(GameObjectTreeViewItem item)
        {
            var go = (GameObject)item.objectPPTR;

            if (!go || PrefabUtility.GetNearestPrefabInstanceRoot(go) != go)
            {
                return(null);
            }

            var assetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go);

            return(AssetDatabase.AssetPathToGUID(assetPath));
        }
 protected void DoAdditionalSceneHeaderGUI(GameObjectTreeViewItem goItem, Rect rect)
 {
   Rect position = new Rect((float) ((double) rect.width - 16.0 - 4.0), rect.y + (float) (((double) rect.height - 6.0) * 0.5), 16f, rect.height);
   if (Event.current.type == EventType.Repaint)
     GameObjectTreeViewGUI.s_GOStyles.optionsButtonStyle.Draw(position, false, false, false, false);
   position.y = rect.y;
   position.height = rect.height;
   position.width = 24f;
   if (!EditorGUI.ButtonMouseDown(position, GUIContent.none, FocusType.Passive, GUIStyle.none))
     return;
   this.m_TreeView.SelectionClick((TreeViewItem) goItem, true);
   this.m_TreeView.contextClickItemCallback(goItem.id);
 }
 private bool AddSceneHeaderToSearchIfNeeded(GameObjectTreeViewItem item, HierarchyProperty property, ref int currentSceneHandle)
 {
   if (SceneManager.sceneCount <= 1)
     return false;
   Scene scene = property.GetScene();
   if (currentSceneHandle == scene.handle)
     return false;
   currentSceneHandle = scene.handle;
   this.InitTreeViewItem(item, scene.handle, scene, true, 0, (UnityEngine.Object) null, false, 0);
   return true;
 }
 private DragAndDropVisualMode DoDragScenes(GameObjectTreeViewItem parentItem, GameObjectTreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos)
 {
   List<Scene> genericData = DragAndDrop.GetGenericData("SceneHeaderList") as List<Scene>;
   bool flag1 = genericData != null;
   bool flag2 = false;
   if (!flag1 && DragAndDrop.objectReferences.Length > 0)
   {
     int num = 0;
     foreach (UnityEngine.Object objectReference in DragAndDrop.objectReferences)
     {
       if (objectReference is SceneAsset)
         ++num;
     }
     flag2 = num == DragAndDrop.objectReferences.Length;
   }
   if (!flag1 && !flag2)
     return DragAndDropVisualMode.None;
   if (perform)
   {
     List<Scene> sceneList = (List<Scene>) null;
     if (flag2)
     {
       List<Scene> source = new List<Scene>();
       foreach (UnityEngine.Object objectReference in DragAndDrop.objectReferences)
       {
         string assetPath = AssetDatabase.GetAssetPath(objectReference);
         Scene sceneByPath = SceneManager.GetSceneByPath(assetPath);
         if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(sceneByPath))
         {
           this.m_TreeView.Frame(sceneByPath.handle, true, true);
         }
         else
         {
           Scene scene = !Event.current.alt ? EditorSceneManager.OpenScene(assetPath, OpenSceneMode.Additive) : EditorSceneManager.OpenScene(assetPath, OpenSceneMode.AdditiveWithoutLoading);
           if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene))
             source.Add(scene);
         }
       }
       if (targetItem != null)
         sceneList = source;
       if (SceneManager.sceneCount - source.Count == 1)
         ((TreeViewDataSource) this.m_TreeView.data).SetExpanded(SceneManager.GetSceneAt(0).handle, true);
       if (source.Count > 0)
       {
         Selection.instanceIDs = source.Select<Scene, int>((Func<Scene, int>) (x => x.handle)).ToArray<int>();
         this.m_TreeView.Frame(source.Last<Scene>().handle, true, false);
       }
     }
     else
       sceneList = genericData;
     if (sceneList != null)
     {
       if (targetItem != null)
       {
         Scene scene = targetItem.scene;
         if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene))
         {
           if (!targetItem.isSceneHeader || dropPos == TreeViewDragging.DropPosition.Upon)
             dropPos = TreeViewDragging.DropPosition.Below;
           if (dropPos == TreeViewDragging.DropPosition.Above)
           {
             for (int index = 0; index < sceneList.Count; ++index)
               EditorSceneManager.MoveSceneBefore(sceneList[index], scene);
           }
           else if (dropPos == TreeViewDragging.DropPosition.Below)
           {
             for (int index = sceneList.Count - 1; index >= 0; --index)
               EditorSceneManager.MoveSceneAfter(sceneList[index], scene);
           }
         }
       }
       else
       {
         Scene sceneAt = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
         for (int index = sceneList.Count - 1; index >= 0; --index)
           EditorSceneManager.MoveSceneAfter(sceneList[index], sceneAt);
       }
     }
   }
   return DragAndDropVisualMode.Move;
 }
 private GameObjectTreeViewItem EnsureCreatedItem(int row)
 {
   if (row >= this.m_VisibleRows.Count)
     this.m_VisibleRows.Add((TreeViewItem) null);
   GameObjectTreeViewItem objectTreeViewItem = (GameObjectTreeViewItem) this.m_VisibleRows[row];
   if (objectTreeViewItem == null)
   {
     objectTreeViewItem = new GameObjectTreeViewItem(0, 0, (TreeViewItem) null, (string) null);
     this.m_VisibleRows[row] = (TreeViewItem) objectTreeViewItem;
   }
   return objectTreeViewItem;
 }
 private void InitTreeViewItem(GameObjectTreeViewItem item, HierarchyProperty property, bool itemHasChildren, int itemDepth)
 {
   this.InitTreeViewItem(item, property.instanceID, property.GetScene(), this.IsSceneHeader(property), property.colorCode, property.pptrValue, itemHasChildren, itemDepth);
 }
 private void InitTreeViewItem(GameObjectTreeViewItem item, int itemID, Scene scene, bool isSceneHeader, int colorCode, UnityEngine.Object pptrObject, bool hasChildren, int depth)
 {
   item.children = (List<TreeViewItem>) null;
   item.userData = (object) null;
   item.id = itemID;
   item.depth = depth;
   item.parent = (TreeViewItem) null;
   item.displayName = !isSceneHeader ? (string) null : (!string.IsNullOrEmpty(scene.path) ? scene.name : "Untitled");
   item.colorCode = colorCode;
   item.objectPPTR = pptrObject;
   item.shouldDisplay = true;
   item.isSceneHeader = isSceneHeader;
   item.scene = scene;
   item.icon = !isSceneHeader ? (Texture2D) null : EditorGUIUtility.FindTexture("SceneAsset Icon");
   if (!hasChildren)
     return;
   item.children = LazyTreeViewDataSource.CreateChildListForCollapsedParent();
 }
 private void CreateSceneHeaderItems()
 {
   this.m_StickySceneHeaderItems.Clear();
   int sceneCount = SceneManager.sceneCount;
   for (int index = 0; index < sceneCount; ++index)
   {
     Scene sceneAt = SceneManager.GetSceneAt(index);
     GameObjectTreeViewItem objectTreeViewItem = new GameObjectTreeViewItem(0, 0, (TreeViewItem) null, (string) null);
     this.InitTreeViewItem(objectTreeViewItem, sceneAt.handle, sceneAt, true, 0, (UnityEngine.Object) null, false, 0);
     this.m_StickySceneHeaderItems.Add(objectTreeViewItem);
   }
 }
 private void HandleStickyHeaderContextClick(Rect rect, GameObjectTreeViewItem sceneHeaderItem)
 {
   Event current = Event.current;
   if (Application.platform == RuntimePlatform.OSXEditor)
   {
     if ((current.type != EventType.MouseDown || current.button != 1) && current.type != EventType.ContextClick || !rect.Contains(Event.current.mousePosition))
       return;
     current.Use();
     this.m_TreeView.contextClickItemCallback(sceneHeaderItem.id);
   }
   else
   {
     if (Application.platform != RuntimePlatform.WindowsEditor || current.type != EventType.MouseDown || (current.button != 1 || !rect.Contains(Event.current.mousePosition)))
       return;
     current.Use();
   }
 }