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); } }
static void RefreshSubSceneInfo() { if (SubSceneGUI.IsUsingSubScenes()) { SubSceneGUI.FetchSubSceneInfo(); } }
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); }
override public bool IsRenamingItemAllowed(TreeViewItem item) { GameObjectTreeViewItem goItem = item as GameObjectTreeViewItem; if (goItem.isSceneHeader) { return(false); } if (SubSceneGUI.IsUsingSubScenes() && SubSceneGUI.IsSubSceneHeader((GameObject)goItem.objectPPTR)) { return(false); } return(true); }
void CreateSceneHeaderItems() { m_StickySceneHeaderItems.Clear(); int numScenesInHierarchy = EditorSceneManager.sceneCount; if (SubSceneGUI.IsUsingSubScenes()) { for (int i = 0; i < numScenesInHierarchy; ++i) { Scene scene = SceneManager.GetSceneAt(i); var subSceneInfo = SubSceneGUI.GetSubSceneInfo(scene); if (subSceneInfo.isValid) { var item = new GameObjectTreeViewItem(0, 0, null, null); var transform = subSceneInfo.transform; GameObject gameObject = transform.gameObject; int depth = SubSceneGUI.CalculateHierarchyDepthOfSubScene(subSceneInfo); InitTreeViewItem(item, gameObject.GetInstanceID(), subSceneInfo.scene, false, 0, gameObject, false, depth); m_StickySceneHeaderItems.Add(item); } else { var item = new GameObjectTreeViewItem(0, 0, null, null); InitTreeViewItem(item, scene.handle, scene, true, 0, null, false, 0); m_StickySceneHeaderItems.Add(item); } } } else { for (int i = 0; i < numScenesInHierarchy; ++i) { Scene scene = SceneManager.GetSceneAt(i); var item = new GameObjectTreeViewItem(0, 0, null, null); InitTreeViewItem(item, scene.handle, scene, true, 0, null, false, 0); m_StickySceneHeaderItems.Add(item); } } }
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; } EnsureLazyInitialization(goItem); if (goItem.isSceneHeader) { useBoldFont = (goItem.scene == SceneManager.GetActiveScene()) || IsPrefabStageHeader(goItem); } SceneVisibilityHierarchyGUI.DoItemGUI(rect, goItem, selected && !IsRenaming(item.id), m_TreeView.hoveredItem == goItem, focused, isDragging); rect.xMin += SceneVisibilityHierarchyGUI.utilityBarWidth; base.DoItemGUI(rect, row, item, selected, focused, useBoldFont); if (goItem.isSceneHeader) { DoAdditionalSceneHeaderGUI(goItem, rect); } else { PrefabModeButton(goItem, rect); if (SubSceneGUI.IsUsingSubScenes() && !showingSearchResults) { SubSceneGUI.DrawVerticalLine(rect, (GameObject)goItem.objectPPTR); } } if (SceneHierarchy.s_Debug) { GUI.Label(new Rect(rect.xMax - 70, rect.y, 70, rect.height), "" + row + " (" + goItem.id + ")", EditorStyles.boldLabel); } }
override protected void DrawItemBackground(Rect rect, int row, TreeViewItem item, bool selected, bool focused) { var goItem = (GameObjectTreeViewItem)item; if (goItem.isSceneHeader) { GUI.Label(rect, GUIContent.none, GameObjectStyles.sceneHeaderBg); } else { // Don't show indented sub scene header backgrounds when searching (as the texts are not indented here) if (SubSceneGUI.IsUsingSubScenes() && !showingSearchResults) { var gameObject = (GameObject)goItem.objectPPTR; if (gameObject != null && SubSceneGUI.IsSubSceneHeader(gameObject)) { SubSceneGUI.DrawSubSceneHeaderBackground(rect, k_BaseIndent, k_IndentWidth, gameObject); } } } if (m_TreeView.hoveredItem != item) { return; } if (isDragging) { return; } using (new GUI.BackgroundColorScope(GameObjectStyles.hoveredBackgroundColor)) { GUI.Label(rect, GUIContent.none, GameObjectStyles.hoveredItemBackgroundStyle); } }
protected override void OnContentGUI(Rect rect, int row, TreeViewItem item, string label, bool selected, bool focused, bool useBoldFont, bool isPinging) { if (Event.current.type != EventType.Repaint) { return; } GameObjectTreeViewItem goItem = item as GameObjectTreeViewItem; if (goItem == null) { return; } rect.xMax = m_ContentRectRight; if (goItem.isSceneHeader) { if (goItem.scene.isDirty) { label += "*"; } switch (goItem.scene.loadingState) { case Scene.LoadingState.NotLoaded: label += " (not loaded)"; break; case Scene.LoadingState.Loading: label += " (is loading)"; break; case Scene.LoadingState.Unloading: label += " (is unloading)"; break; } // Render disabled if scene is unloaded using (new EditorGUI.DisabledScope(!goItem.scene.isLoaded)) { base.OnContentGUI(rect, row, item, label, selected, focused, useBoldFont, isPinging); } return; } if (!isPinging) { // The rect is assumed indented and sized after the content when pinging rect.xMin += GetContentIndent(item) + extraSpaceBeforeIconAndLabel; } int colorCode = goItem.colorCode; bool renderDisabled = colorCode >= 4; lineStyle = Styles.lineStyle; if (SubSceneGUI.IsUsingSubScenes()) { useBoldFont = SubSceneGUI.UseBoldFontForGameObject((GameObject)goItem.objectPPTR); } if (useBoldFont) { lineStyle = Styles.lineBoldStyle; } else { GameObjectColorType objectColorType = (GameObjectColorType)(colorCode & 3); if (objectColorType == GameObjectColorType.Normal) { lineStyle = (renderDisabled) ? GameObjectStyles.disabledLabel : Styles.lineStyle; } else if (objectColorType == GameObjectColorType.Prefab) { lineStyle = (renderDisabled) ? GameObjectStyles.disabledPrefabLabel : GameObjectStyles.prefabLabel; } else if (objectColorType == GameObjectColorType.BrokenPrefab) { lineStyle = (renderDisabled) ? GameObjectStyles.disabledBrokenPrefabLabel : GameObjectStyles.brokenPrefabLabel; } } var sceneGUID = s_ActiveParentObjectPerSceneGUID.FirstOrDefault(x => x.Value == goItem.id).Key; if (!string.IsNullOrEmpty(sceneGUID) && (EditorSceneManager.GetActiveScene().guid == sceneGUID || PrefabStageUtility.GetCurrentPrefabStage() != null)) { lineStyle = Styles.lineBoldStyle; } lineStyle.padding.left = 0; Texture icon = GetEffectiveIcon(goItem, selected, focused); if (icon != null) { Rect iconRect = rect; iconRect.width = k_IconWidth; Color col = GUI.color; if (renderDisabled || (CutBoard.hasCutboardData && CutBoard.IsGameObjectPartOfCutAndPaste((GameObject)goItem.objectPPTR))) { col = new Color(1f, 1f, 1f, 0.5f); } GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit, true, 0, col, 0, 0); if (goItem.overlayIcon != null) { GUI.DrawTexture(iconRect, goItem.overlayIcon, ScaleMode.ScaleToFit, true, 0, col, 0, 0); } if (!EditorApplication.isPlaying) { var vco = VersionControlManager.activeVersionControlObject; if (vco != null) { var extension = vco.GetExtension <IIconOverlayExtension>(); if (extension != null && m_HierarchyPrefabToAssetPathMap.TryGetValue(item.id, out var assetPath)) { iconRect.x -= 10; iconRect.width += 7 * 2; extension.DrawOverlay(assetPath, IconOverlayType.Hierarchy, iconRect); } } else { Asset[] assets; m_HierarchyPrefabToAssetIDMap.TryGetValue(item.id, out assets); if (assets != null) { iconRect.x -= 10; iconRect.width += 7 * 2; Overlay.DrawHierarchyOverlay(assets[0], assets[1], iconRect); } } } rect.xMin += iconTotalPadding + k_IconWidth + k_SpaceBetweenIconAndText; } // Draw text lineStyle.Draw(rect, label, false, false, selected, focused); }
protected override void OnContentGUI(Rect rect, int row, TreeViewItem item, string label, bool selected, bool focused, bool useBoldFont, bool isPinging) { if (Event.current.type != EventType.Repaint) { return; } GameObjectTreeViewItem goItem = item as GameObjectTreeViewItem; if (goItem == null) { return; } if (goItem.isSceneHeader) { if (goItem.scene.isDirty) { label += "*"; } switch (goItem.scene.loadingState) { case Scene.LoadingState.NotLoaded: label += " (not loaded)"; break; case Scene.LoadingState.Loading: label += " (is loading)"; break; } // Render disabled if scene is unloaded using (new EditorGUI.DisabledScope(!goItem.scene.isLoaded)) { base.OnContentGUI(rect, row, item, label, selected, focused, useBoldFont, isPinging); } return; } if (!isPinging) { // The rect is assumed indented and sized after the content when pinging rect.xMin += GetContentIndent(item) + extraSpaceBeforeIconAndLabel; } int colorCode = goItem.colorCode; GUIStyle lineStyle = Styles.lineStyle; if (SubSceneGUI.IsUsingSubScenes()) { useBoldFont = SubSceneGUI.UseBoldFontForGameObject((GameObject)goItem.objectPPTR); } if (useBoldFont) { lineStyle = Styles.lineBoldStyle; } else { if ((colorCode & 3) == (int)GameObjectColorType.Normal) { lineStyle = (colorCode < 4) ? Styles.lineStyle : GameObjectStyles.disabledLabel; } else if ((colorCode & 3) == (int)GameObjectColorType.Prefab) { lineStyle = (colorCode < 4) ? GameObjectStyles.prefabLabel : GameObjectStyles.disabledPrefabLabel; } else if ((colorCode & 3) == (int)GameObjectColorType.BrokenPrefab) { lineStyle = (colorCode < 4) ? GameObjectStyles.brokenPrefabLabel : GameObjectStyles.disabledBrokenPrefabLabel; } } lineStyle.padding.left = 0; if (goItem.icon != null) { Rect iconRect = rect; iconRect.width = k_IconWidth; bool renderDisabled = colorCode >= 4; Color col = GUI.color; if (renderDisabled) { col = new Color(1f, 1f, 1f, 0.5f); } GUI.DrawTexture(iconRect, goItem.icon, ScaleMode.ScaleToFit, true, 0, col, 0, 0); if (goItem.overlayIcon != null) { GUI.DrawTexture(iconRect, goItem.overlayIcon, ScaleMode.ScaleToFit, true, 0, col, 0, 0); } rect.xMin += iconTotalPadding + k_IconWidth + k_SpaceBetweenIconAndText; } // Draw text lineStyle.Draw(rect, label, false, false, selected, focused); }
public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, DropPosition dropPos) { var hierarchyTargetItem = targetItem as GameObjectTreeViewItem; // Allow client to handle drag if (m_CustomDragHandling != null) { DragAndDropVisualMode dragResult = m_CustomDragHandling(parentItem as GameObjectTreeViewItem, hierarchyTargetItem, dropPos, perform); if (dragResult != DragAndDropVisualMode.None) { return(dragResult); } } // Scene dragging logic DragAndDropVisualMode dragSceneResult = DoDragScenes(parentItem as GameObjectTreeViewItem, hierarchyTargetItem, perform, dropPos); if (dragSceneResult != DragAndDropVisualMode.None) { return(dragSceneResult); } if (targetItem != null && !IsDropTargetUserModifiable(hierarchyTargetItem, dropPos)) { return(DragAndDropVisualMode.Rejected); } var option = InternalEditorUtility.HierarchyDropMode.kHierarchyDragNormal; var searchActive = !string.IsNullOrEmpty(dataSource.searchString); if (searchActive) { option |= InternalEditorUtility.HierarchyDropMode.kHierarchySearchActive; } if (parentItem == null || targetItem == null) { // Here we are dragging outside any treeview items: if (parentForDraggedObjectsOutsideItems != null) { // Use specific parent for DragAndDropForwarding return(DragAndDropService.Drop(DragAndDropService.kHierarchyDropDstId, 0, option, parentForDraggedObjectsOutsideItems, perform)); } else { // Simulate drag upon the last loaded scene in the hierarchy (adds as last root sibling of the last scene) Scene lastScene = dataSource.GetLastScene(); if (!lastScene.IsValid()) { return(DragAndDropVisualMode.Rejected); } option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropUpon; return(DragAndDropService.Drop(DragAndDropService.kHierarchyDropDstId, lastScene.handle, option, null, perform)); } } // Here we are hovering over items var draggingUpon = dropPos == TreeViewDragging.DropPosition.Upon; if (searchActive && !draggingUpon) { return(DragAndDropVisualMode.None); } if (draggingUpon) { option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropUpon; } else { if (dropPos == TreeViewDragging.DropPosition.Above) { option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropAbove; } else { option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropBetween; } } bool isDroppingBetweenParentAndFirstChild = parentItem != null && targetItem != parentItem && dropPos == DropPosition.Above && parentItem.children[0] == targetItem; if (isDroppingBetweenParentAndFirstChild) { option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropAfterParent; } int gameObjectOrSceneInstanceID = GetDropTargetInstanceID(hierarchyTargetItem, dropPos); if (gameObjectOrSceneInstanceID == 0) { return(DragAndDropVisualMode.Rejected); } if (perform && SubSceneGUI.IsUsingSubScenes() && !IsValidSubSceneDropTarget(gameObjectOrSceneInstanceID, dropPos, DragAndDrop.objectReferences)) { return(DragAndDropVisualMode.Rejected); } return(DragAndDropService.Drop(DragAndDropService.kHierarchyDropDstId, gameObjectOrSceneInstanceID, option, null, perform)); }
protected override void OnContentGUI(Rect rect, int row, TreeViewItem item, string label, bool selected, bool focused, bool useBoldFont, bool isPinging) { if (Event.current.type != EventType.Repaint) { return; } GameObjectTreeViewItem goItem = item as GameObjectTreeViewItem; if (goItem == null) { return; } rect.xMax = m_ContentRectRight; if (goItem.isSceneHeader) { if (goItem.scene.isDirty) { label += "*"; } switch (goItem.scene.loadingState) { case Scene.LoadingState.NotLoaded: label += " (not loaded)"; break; case Scene.LoadingState.Loading: label += " (is loading)"; break; } // Render disabled if scene is unloaded using (new EditorGUI.DisabledScope(!goItem.scene.isLoaded)) { base.OnContentGUI(rect, row, item, label, selected, focused, useBoldFont, isPinging); } return; } if (!isPinging) { // The rect is assumed indented and sized after the content when pinging rect.xMin += GetContentIndent(item) + extraSpaceBeforeIconAndLabel; } int colorCode = goItem.colorCode; lineStyle = Styles.lineStyle; if (SubSceneGUI.IsUsingSubScenes()) { useBoldFont = SubSceneGUI.UseBoldFontForGameObject((GameObject)goItem.objectPPTR); } if (useBoldFont) { lineStyle = Styles.lineBoldStyle; } else { if ((colorCode & 3) == (int)GameObjectColorType.Normal) { lineStyle = (colorCode < 4) ? Styles.lineStyle : GameObjectStyles.disabledLabel; } else if ((colorCode & 3) == (int)GameObjectColorType.Prefab) { lineStyle = (colorCode < 4) ? GameObjectStyles.prefabLabel : GameObjectStyles.disabledPrefabLabel; } else if ((colorCode & 3) == (int)GameObjectColorType.BrokenPrefab) { lineStyle = (colorCode < 4) ? GameObjectStyles.brokenPrefabLabel : GameObjectStyles.disabledBrokenPrefabLabel; } } if (activeParentObjects.ContainsValue(goItem.id)) { lineStyle = Styles.lineBoldStyle; } lineStyle.padding.left = 0; Texture icon = GetEffectiveIcon(goItem); if (icon != null) { Rect iconRect = rect; iconRect.width = k_IconWidth; bool renderDisabled = colorCode >= 4; Color col = GUI.color; if (renderDisabled || (CutBoard.hasCutboardData && CutBoard.IsGameObjectPartOfCutAndPaste((GameObject)goItem.objectPPTR))) { col = new Color(1f, 1f, 1f, 0.5f); } GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit, true, 0, col, 0, 0); if (goItem.overlayIcon != null) { GUI.DrawTexture(iconRect, goItem.overlayIcon, ScaleMode.ScaleToFit, true, 0, col, 0, 0); } if (!EditorApplication.isPlaying) { Asset[] assets; m_HierarchyPrefabToAssetIDMap.TryGetValue(item.id, out assets); if (assets != null) { iconRect.x -= 10; iconRect.width += 7 * 2; Overlay.DrawHierarchyOverlay(assets[0], assets[1], iconRect); } } rect.xMin += iconTotalPadding + k_IconWidth + k_SpaceBetweenIconAndText; } // Draw text lineStyle.Draw(rect, label, false, false, selected, focused); }