private void OnItemGUI(int id, Rect rect) { var instance = EditorUtility.InstanceIDToObject(id) as GameObject; if (!instance) { return; } GetInstanceViewItem(id, instance, rect, out var item); // Happens to be null when entering prefab mode if (!item.EnsureViewExist(hierarchy)) { return; } item.UpdateViewIcon(); if (item.isCollection) { if (item.OnCollectionButton(rect, IsSelected(id))) { var popup = new CollectionPopup(item.collection); var position = new Vector2(rect.x, rect.yMax - state.scrollPos.y + 32); popup.ShowInsideWindow(position, root); } } if (hierarchy.hoveredItem == item.view) { var fullWidthRect = GetFullWidthRect(rect); OnHoverGUI(fullWidthRect, item); } }
private void OnItemGUI(int id, Rect rect) { var instance = EditorUtility.InstanceIDToObject(id) as GameObject; if (!instance) { return; } GetInstanceViewItem(id, instance, rect, out var item); // Happens to be null when entering prefab mode if (!item.EnsureViewExist(hierarchy)) { return; } // Changing icon in TreeViewItem is not enough, // When item is selected, it is hardcoded to use "On" icon (white version for blue background). // https://github.com/Unity-Technologies/UnityCsReference/blob/2019.4/Editor/Mono/GUI/TreeView/TreeViewGUI.cs#L157 // Setting width to zero will hide default icon, so we can draw our own on top, // But this also removes item text indentation and "Pinging" icon.. controller.gui.SetIconWidth(0); controller.gui.SetSpaceBetweenIconAndText(18); var isSelected = controller.IsSelected(item.view); var isOn = isSelected && controller.HasFocus(); item.DrawIcon(rect, isOn); if (item.isCollection) { if (ViewItemGUI.OnIconClick(rect)) { var popup = new CollectionPopup(item.collection); var position = new Vector2(rect.x, rect.yMax - state.scrollPos.y + 32); popup.ShowInsideWindow(position, root); } } if (hierarchy.hoveredItem == item.view) { var fullWidthRect = GetFullWidthRect(rect); OnHoverGUI(fullWidthRect, item); } }
public static void DoItemGUI(this ViewItem item, SmartHierarchy hierarchy, Rect rect, bool isHover, bool isOn) { item.DrawIcon(rect, isOn); if (item.isCollection) { if (OnIconClick(rect)) { var collectionPopup = ObjectPopupWindow.GetPopup <CollectionPopup>(); if (collectionPopup == null) { var popup = new CollectionPopup(item.collection); var scrollPos = hierarchy.state.scrollPos.y; var position = new Vector2(rect.x, rect.yMax - scrollPos + 32); popup.ShowInsideWindow(position, hierarchy.root); } else { collectionPopup.Close(); } } } var fullWidthRect = new Rect(rect) { x = 0, width = Screen.width }; var toggleRect = new Rect(fullWidthRect) { x = 32 }; var isDragged = activationToggle.IsObjectDragged(item.instance); if (isDragged) { var c = EditorGUIUtility.isProSkin ? new Color(1, 1, 1, 1) : new Color(0, 0, 0, 1); EditorGUI.DrawRect(toggleRect, new Color(c.r, c.g, c.b, 0.0666f)); } activationToggle.DoActivationToggle(toggleRect, item.instance, isHover || isDragged); }