public void SetSource(EntityHierarchyItem item) { // Needs to be cleared here because list virtualization doesn't use IPoolable.Reset() ClearDynamicStyles(); m_Item = item; switch (m_Item.NodeId.Kind) { case NodeKind.Entity: { RenderEntityNode(); break; } case NodeKind.Scene: case NodeKind.SubScene: { RenderSceneNode(m_Item.NodeId.Kind == NodeKind.SubScene); break; } case NodeKind.Root: case NodeKind.None: { RenderInvalidNode(m_Item.NodeId); break; } default: throw new ArgumentOutOfRangeException(); } }
public void Release() { if (m_ContextMenuManipulator != null) { this.RemoveManipulator(m_ContextMenuManipulator); UnregisterCallback <ContextualMenuPopulateEvent>(OnSceneContextMenu); m_ContextMenuManipulator = null; } m_Item = null; m_OriginatingId = null; Pool.Release(this); }
void IPoolable.Reset() { Owner = null; if (m_ContextMenuManipulator != null) { this.RemoveManipulator(m_ContextMenuManipulator); UnregisterCallback <ContextualMenuPopulateEvent>(OnSceneContextMenu); m_ContextMenuManipulator = null; } m_Item = null; m_OriginatingId = null; // These are overwritten by ListView in a way that conflicts with the TreeView representation // NOTE: Adding those to "ClearDynamicStyles()" messes-up the rendering of the ListView style.top = 0.0f; style.bottom = Constants.EntityHierarchy.ItemHeight; style.position = Position.Relative; }
void OnSelectionChanged(EntityHierarchyItem selectedItem) { // TODO: Support undo/redo (see: Hierarchy window) if (selectedItem.NodeId.Kind == NodeKind.Entity) { var entity = selectedItem.Strategy.GetUnderlyingEntity(selectedItem.NodeId); if (selectedItem.Strategy.GetUnderlyingEntity(selectedItem.NodeId) != Entity.Null) { m_SelectionProxy.SetEntity(m_Hierarchy.World, entity); Selection.activeObject = m_SelectionProxy; } } else { // TODO: Deal with non-Entity selections Selection.activeObject = null; } }
void OnLocalSelectionChanged(EntityHierarchyItem selectedItem) { m_SelectedItem = selectedItem.NodeId; if (selectedItem.NodeId.Kind == NodeKind.Entity) { var entity = selectedItem.NodeId.ToEntity(); if (entity != Entity.Null) { var undoGroup = Undo.GetCurrentGroup(); EntitySelectionProxy.SelectEntity(m_Hierarchy.World, entity); // Collapsing the selection of the entity into the selection of the ListView / TreeView item Undo.CollapseUndoOperations(undoGroup); } } else { // TODO: Deal with non-Entity selections } }
void RecreateRootItems() { ClearTreeViewRootItems(); // We need to refresh the treeview since we changed its source collection // otherwise it could keep references to pooled objects that have been reset. m_TreeView.Refresh(); if (m_Hierarchy?.GroupingStrategy == null) { return; } using (var rootNodes = m_Hierarchy.State.GetChildren(EntityHierarchyNodeId.Root, Allocator.TempJob)) { foreach (var node in rootNodes) { m_TreeViewRootItems.Add(EntityHierarchyItem.Acquire(null, node, m_Hierarchy)); } } }
void RefreshSearchView() { if (m_SearcherCacheNeedsRebuild) { m_ItemsCache.Rebuild(m_TreeViewRootItems.OfType <EntityHierarchyItem>()); m_SearcherCacheNeedsRebuild = false; } m_ListViewFilteredItems.Clear(); var filteredData = m_CurrentQuery?.Apply(m_ItemsCache.Items) ?? m_ItemsCache.Items; EntityHierarchyItem lastSubsceneItem = null; foreach (var item in filteredData) { if (item.NodeId.Kind != NodeKind.Entity) { continue; } if (item.parent != null && IsParentedBySubScene(item, out var closestSubScene) && closestSubScene != lastSubsceneItem) { lastSubsceneItem = closestSubScene; m_ListViewFilteredItems.Add(lastSubsceneItem); } m_ListViewFilteredItems.Add(item); } if (m_ListViewFilteredItems.Count == 0 && m_QueryBuilderResult.IsValid) { m_SearchEmptyMessage.Title = NoEntitiesFoundTitle; m_SearchEmptyMessage.Message = string.Empty; m_CurrentViewMode = ViewMode.Message; } m_ListView.Refresh(); bool IsParentedBySubScene(EntityHierarchyItem item, out EntityHierarchyItem subSceneItem) { subSceneItem = null; var current = item; while (true) { if (current.parent == null) { return(false); } var currentParent = (EntityHierarchyItem)current.parent; switch (currentParent.NodeId.Kind) { case NodeKind.Root: case NodeKind.Scene: return(false); case NodeKind.Entity: current = currentParent; continue; case NodeKind.SubScene: subSceneItem = currentParent; return(true); default: throw new NotSupportedException($"{nameof(currentParent.NodeId.Kind)} is not supported in this context"); } } } }
public static void ReturnTreeViewItem(EntityHierarchyItem item) { Pool <EntityHierarchyItem> .Release(item); }