protected override void OnDragOver(DragEventArgs e) { base.OnDragEnter(e); HitTestResult result = VisualTreeHelper.HitTest(this, e.GetPosition(this)); if ((result.VisualHit as UIElement).IsDescendantOf(this)) { UIElement element = (result.VisualHit as UIElement); DragDropTreeViewItem targetNode = GetNearestContainer(e.Source as UIElement); if (e.GetPosition(targetNode).Y < targetNode.ActualHeight * 0.2f) { // meter em cima //Console.WriteLine("cima"); DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Top; DragDropHelper.CreateInsertionAdorner(targetNode, true); } else if (e.GetPosition(targetNode).Y > targetNode.ActualHeight * 0.8f) { //Console.WriteLine("baixo"); DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Bottom; DragDropHelper.CreateInsertionAdorner(targetNode, false); } else { //Console.WriteLine("centro"); DragDropHelper.RemoveInsertionAdorner(); DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Center; var converter = new System.Windows.Media.BrushConverter(); Background = (Brush)converter.ConvertFromString("#555"); } } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); HitTestResult result = VisualTreeHelper.HitTest(this, e.GetPosition(this)); // Move the dragged node when the left mouse button is used. EditorUtils.GetParent(result.VisualHit, 2) == if (e.LeftButton == MouseButtonState.Pressed && CanDrag && (result.VisualHit as UIElement) != null && (result.VisualHit as UIElement).IsDescendantOf(this)) { try { DragDrop.DoDragDrop(this, this, DragDropEffects.Move); } catch (Exception ex) { Console.WriteLine(ex.Message); } } DragDropTreeViewItem targetNode = GetNearestContainer(e.Source as UIElement); if (targetNode == null) { DragDropHelper.RemoveInsertionAdorner(); } //Console.WriteLine(this.PointFromScreen(Mouse.GetPosition(targetNode))); }
private void treeView_MouseUp(object sender, MouseButtonEventArgs e) { // NEW WAY TO DETECT SELECTIONS: if (sender != null && (sender as TreeView).SelectedItem != null) { List <TreeViewItem> it = TreeViewExtension.GetSelectedTreeViewItems(treeView); EditorHandler.SelectedGameObjects = new List <GameObject>(); foreach (var i in it) { //Console.WriteLine(i.Header); //object tag = ((sender as TreeView).SelectedItem as DragDropTreeViewItem).Tag; // old object tag = (i as DragDropTreeViewItem).Tag; if (tag is GameObject) { // TODO : multiple selection EditorHandler.SelectedGameObjects.Add((GameObject)tag); } } EditorHandler.ChangeSelectedObjects(); lastSelectedItem = (sender as TreeView).SelectedItem as DragDropTreeViewItem; } else { EditorHandler.SelectedGameObjects.Clear(); EditorHandler.ChangeSelectedObjects(); } }
void deleteItem_Click(object sender, RoutedEventArgs e) { List <TreeViewItem> selected = TreeViewExtension.GetSelectedTreeViewItems(treeView); string message = "Are you sure you want to delete the selected game object?"; if (selected.Count > 1) { message = "Are you sure you want to delete the selected game objects?"; } if (System.Windows.Forms.MessageBox.Show(message, "Warning", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { TreeViewExtension.UnselectAll(treeView); foreach (var t in selected) { GameObject gameObject = (GameObject)(t as DragDropTreeViewItem).Tag; //(GameObject)(SelectedItem as DragDropTreeViewItem).Tag; DragDropTreeViewItem parentNode = (t as DragDropTreeViewItem).Parent as DragDropTreeViewItem; if (parentNode == null) { SceneManager.ActiveScene.GameObjects.Remove((t as DragDropTreeViewItem).Tag as GameObject); treeView.Items.Remove(t); } else { GameObject objParent = (GameObject)parentNode.Tag; objParent.Children.Remove((t as DragDropTreeViewItem).Tag as GameObject); parentNode.Items.Remove(t); } } EditorHandler.SelectedGameObjects.Clear(); EditorHandler.ChangeSelectedObjects(); } }
void cutItem_Click(object sender, RoutedEventArgs e) { List <GameObject> toCopy = new List <GameObject>(); foreach (TreeViewItem ti in TreeViewExtension.GetSelectedTreeViewItems(treeView)) { var gameObject = (ti.Tag as GameObject); gameObject.SaveComponentValues(); toCopy.Add(gameObject); DragDropTreeViewItem parentNode = ti.Parent as DragDropTreeViewItem; if (parentNode == null) { SceneManager.ActiveScene.GameObjects.Remove(ti.Tag as GameObject); treeView.Items.Remove(ti); } else { GameObject objParent = (GameObject)parentNode.Tag; objParent.Children.Remove(ti.Tag as GameObject); parentNode.Items.Remove(ti); } } Clipboard.SetData("GameObject", toCopy); TreeViewExtension.UnselectAll(treeView); EditorHandler.SelectedGameObjects.Clear(); EditorHandler.ChangeSelectedObjects(); }
internal void BeginEditTextOnSelected() { ItemLostFocus(); selectedForEditing = (SelectedItem as DragDropTreeViewItem); if (selectedForEditing == null) { return; } TextBox tb = new TextBox(); tb.LostFocus += tb_LostFocus; tb.KeyDown += tb_KeyDown; tb.Text = lastSelectedItem.Tag.ToString(); tb.Focusable = true; (selectedForEditing.Header as StackPanel).Children.RemoveAt(2); (selectedForEditing.Header as StackPanel).Children.Add(tb); selectedForEditing.CanDrag = false; tb.Select(0, tb.Text.Length); tb.Focus(); }
/// <summary> /// /// </summary> public void CreateView() { treeView.Items.Clear(); if (SceneManager.ActiveScene == null) { DragDropTreeViewItem noScene = new DragDropTreeViewItem(); noScene.Header = "No Scene in memory."; noScene.CanDrag = false; noScene.IsEnabled = false; noScene.Style = (Style)FindResource("IgniteMultiTreeViewItem"); // noScene.can treeView.Items.Add(noScene); return; } this.ContextMenu = panelContextMenu; // Set all this layer game objects foreach (GameObject gameObject in SceneManager.ActiveScene.GameObjects) { string name = gameObject.Name == null ? "Game Object" : gameObject.Name; gameObject.Name = name; DragDropTreeViewItem _node = AddNode(null, gameObject, GameObjectImageSource(gameObject)); //_node.ContextMenuStrip = objectContextMenuStrip; FillGameObjects(gameObject, _node); } }
private void AttachChildren(DragDropTreeViewItem node) { foreach (GameObject _obj in (node.Tag as GameObject).Children) { DragDropTreeViewItem _node = AddNode(node, _obj, GameObjectImageSource(_obj)); AttachChildren(_node); } }
private void ReApplyStyle(DragDropTreeViewItem ti, string styleName) { ti.Style = null; ti.Style = (Style)FindResource(styleName); foreach (var t in ti.Items) { ReApplyStyle(t as DragDropTreeViewItem, styleName); } }
public static void CreateInsertionAdorner(DragDropTreeViewItem target, bool firstHalf) { if (target != null && insertionAdorner == null && !(target is ExplorerTreeViewItem)) { // Here, I need to get adorner layer from targetItemContainer and not targetItemsControl. // This way I get the AdornerLayer within ScrollContentPresenter, and not the one under AdornerDecorator (Snoop is awesome). // If I used targetItemsControl, the adorner would hang out of ItemsControl when there's a horizontal scroll bar. var adornerLayer = AdornerLayer.GetAdornerLayer(target); insertionAdorner = new InsertionAdorner(true, firstHalf, target, adornerLayer); } }
private DragDropTreeViewItem GetNearestContainer(UIElement element) { // Walk up the element tree to the nearest tree view item. DragDropTreeViewItem container = element as DragDropTreeViewItem; while ((container == null) && (element != null)) { element = VisualTreeHelper.GetParent(element) as UIElement; container = element as DragDropTreeViewItem; } return(container); }
internal DragDropTreeViewItem AddNode(DragDropTreeViewItem parent, object tag, ImageSource imageSource) { DragDropTreeViewItem node = new DragDropTreeViewItem(); node.Style = (Style)FindResource("IgniteMultiTreeViewItem"); Image visibilityToggleImage = new Image(); visibilityToggleImage.Cursor = Cursors.Hand; visibilityToggleImage.Tag = tag; visibilityToggleImage.Width = 8; visibilityToggleImage.Height = 8; visibilityToggleImage.Margin = new Thickness(0, 0, MARGIN, 0); visibilityToggleImage.MouseUp += visibilityToggleImage_MouseUp; if (tag is GameObject) { visibilityToggleImage.Source = ((tag as GameObject).Visible ? visibleItemIcon : hiddenItemIcon); } StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; sp.Children.Add(visibilityToggleImage); sp.Children.Add(new Image() { Source = imageSource }); sp.Children.Add(new TextBlock() { Text = tag.ToString(), Margin = new Thickness(MARGIN, 0, 0, 0) }); node.Header = sp; node.MouseUp += node_MouseUp; node.Tag = tag; node.MouseDoubleClick += node_MouseDoubleClick; node.ContextMenu = contextMenu; //node.ContextMenu = objectContextMenuStrip; if (parent == null) { treeView.Items.Insert(0, node); } else { parent.Items.Insert(0, node); //parent.ExpandSubtree(); //parent.IsExpanded = true; } return(node); }
/// <summary> /// /// </summary> /// <param name="_gameObject"></param> /// <param name="node"></param> private void FillGameObjects(GameObject _gameObject, DragDropTreeViewItem node) { foreach (GameObject gameObject in _gameObject.Children) { string name = gameObject.Name == null ? "Game Object" : gameObject.Name; gameObject.Name = name; DragDropTreeViewItem _node = AddNode(node, gameObject, GameObjectImageSource(gameObject)); //_node.ContextMenuStrip = objectContextMenuStrip; FillGameObjects(gameObject, _node); } }
void moveUpItem_Click(object sender, RoutedEventArgs e) { GameObject gameObject = (GameObject)(SelectedItem as DragDropTreeViewItem).Tag; // no parent? if (!((SelectedItem as DragDropTreeViewItem).Parent is DragDropTreeView)) { DragDropTreeViewItem parentNode = (SelectedItem as DragDropTreeViewItem).Parent as DragDropTreeViewItem; int index = (parentNode.Tag as GameObject).Children.FindIndex(o => o.GetHashCode() == gameObject.GetHashCode()); // already on bottom? if (index == (parentNode.Tag as GameObject).Children.Count - 1) { return; } GameObject parent = (GameObject)parentNode.Tag; // Shift objects GameObject topObject = parent.Children[index + 1]; parent.Children.Delete(topObject); parent.Children.Insert(index, topObject); //// Shift in treeview DragDropTreeViewItem topNode = (DragDropTreeViewItem)parentNode.Items[parentNode.Items.IndexOf(SelectedItem) - 1]; parentNode.Items.Remove(topNode); parentNode.Items.Insert(parentNode.Items.IndexOf(SelectedItem) + 1, topNode); } else { int index = SceneManager.ActiveScene.GameObjects.FindIndex(o => o.GetHashCode() == gameObject.GetHashCode()); // already on bottom? if (index == SceneManager.ActiveScene.GameObjects.Count - 1) { return; } // Shift objects GameObject topObject = SceneManager.ActiveScene.GameObjects[index + 1]; SceneManager.ActiveScene.GameObjects.Delete(topObject); SceneManager.ActiveScene.GameObjects.Insert(index, topObject); //// Shift in treeview DragDropTreeViewItem topNode = (DragDropTreeViewItem)treeView.Items[treeView.Items.IndexOf(SelectedItem) - 1]; treeView.Items.Remove(topNode); treeView.Items.Insert(treeView.Items.IndexOf(SelectedItem) + 1, topNode); } }
public static bool TreeContainsNode(TreeView tv, DragDropTreeViewItem node1, DragDropTreeViewItem node2) { // Check the parent node of the second node. if (node2.Parent == null || node2.Parent == tv) { return(false); } if (node2.Parent == node1) { return(true); } // If the parent node is not null or equal to the first node, // call the ContainsNode method recursively using the parent of // the second node. return(TreeContainsNode(tv, node1, node2.Parent as DragDropTreeViewItem)); }
private void SelectOnClick(MouseButtonEventArgs e) { DragDropTreeViewItem ClickedTreeViewItem = new DragDropTreeViewItem(); //find the original object that raised the event UIElement ClickedItem = VisualTreeHelper.GetParent(e.OriginalSource as UIElement) as UIElement; //find the clicked TreeViewItem while ((ClickedItem != null) && !(ClickedItem is DragDropTreeViewItem)) { ClickedItem = VisualTreeHelper.GetParent(ClickedItem) as UIElement; } ClickedTreeViewItem = ClickedItem as DragDropTreeViewItem; if (ClickedTreeViewItem != null) { ClickedTreeViewItem.IsSelected = true; ClickedTreeViewItem.Focus(); } }
internal void BeginEditTextOnSelected() { ItemLostFocus(); selectedForEditing = (SelectedItem as DragDropTreeViewItem); if (selectedForEditing == null) return; TextBox tb = new TextBox(); tb.LostFocus += tb_LostFocus; tb.KeyDown += tb_KeyDown; tb.Text = lastSelectedItem.Tag.ToString(); tb.Focusable = true; (selectedForEditing.Header as StackPanel).Children.RemoveAt(2); (selectedForEditing.Header as StackPanel).Children.Add(tb); selectedForEditing.CanDrag = false; tb.Select(0, tb.Text.Length); tb.Focus(); }
internal DragDropTreeViewItem AddNode(DragDropTreeViewItem parent, object tag, ImageSource imageSource) { DragDropTreeViewItem node = new DragDropTreeViewItem(); node.Style = (Style)FindResource("IgniteMultiTreeViewItem"); Image visibilityToggleImage = new Image(); visibilityToggleImage.Cursor = Cursors.Hand; visibilityToggleImage.Tag = tag; visibilityToggleImage.Width = 8; visibilityToggleImage.Height = 8; visibilityToggleImage.Margin = new Thickness(0, 0, MARGIN, 0); visibilityToggleImage.MouseUp += visibilityToggleImage_MouseUp; if (tag is GameObject) visibilityToggleImage.Source = ((tag as GameObject).Visible ? visibleItemIcon : hiddenItemIcon); StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; sp.Children.Add(visibilityToggleImage); sp.Children.Add(new Image() { Source = imageSource }); sp.Children.Add(new TextBlock() { Text = tag.ToString(), Margin = new Thickness(MARGIN, 0, 0, 0) }); node.Header = sp; node.MouseUp += node_MouseUp; node.Tag = tag; node.MouseDoubleClick += node_MouseDoubleClick; node.ContextMenu = contextMenu; //node.ContextMenu = objectContextMenuStrip; if (parent == null) { treeView.Items.Insert(0, node); } else { parent.Items.Insert(0, node); //parent.ExpandSubtree(); //parent.IsExpanded = true; } return node; }
internal void AddGameObject(GameObject gameObject, string type, bool autoselect = true, bool addToSelectedParent = false, bool expand = false) { if (gameObject == null) { switch (type.ToLower()) { case "empty": gameObject = new GameObject(); gameObject.Name = "Empty Game Object"; break; case "sprite": gameObject = new Sprite(); gameObject.Name = "Sprite Game Object"; break; case "animatedsprite": gameObject = new AnimatedSprite(); gameObject.Name = "Animated Sprite Game Object"; break; case "audio": gameObject = new AudioObject(); gameObject.Name = "Audio Game Object"; break; case "tileset": gameObject = new Tileset(); gameObject.Name = "Tileset Game Object"; break; case "bmfont": gameObject = new BMFont(); gameObject.Name = "Bitmap Font Object"; break; case "particleemitter": gameObject = new ParticleEmitter(); gameObject.Name = "Particle Emitter Object"; break; } } else { gameObject.Initialize(); } if (SelectedItem == null) { SceneManager.ActiveScene.GameObjects.Add(gameObject); } else { if (addToSelectedParent) { GameObject _gameObject = (GameObject)(SelectedItem as DragDropTreeViewItem).Tag; if (_gameObject.Transform.Parent == null) { SceneManager.ActiveScene.GameObjects.Add(gameObject); } else { _gameObject.Transform.Parent.GameObject.Children.Add(gameObject); } } else { GameObject _gameObject = (GameObject)(SelectedItem as DragDropTreeViewItem).Tag; _gameObject.Children.Add(gameObject); } } if (gameObject != null) { DragDropTreeViewItem _parent = SelectedItem as DragDropTreeViewItem; if (addToSelectedParent) { var tmp = EditorUtils.FindVisualParent <DragDropTreeViewItem>(_parent); if (tmp != null) { _parent = tmp; } else { _parent = null; } } DragDropTreeViewItem node = AddNode(_parent, gameObject, GameObjectImageSource(gameObject)); if (_parent != null && expand) { //_parent.ExpandSubtree(); _parent.IsExpanded = true; } node.ContextMenu = contextMenu; // AddNodes(gameObject); //node.IsSelected = true; AttachChildren(node); //foreach (GameObject _obj in gameObject.Children) // AddGameObject(_obj, string.Empty); if (autoselect) { node.IsSelected = true; EditorHandler.SelectedGameObjects = new List <GameObject>(); EditorHandler.SelectedGameObjects.Add(gameObject); } } }
// Determine whether one node is a parent // or ancestor of a second node. private bool ContainsNode(DragDropTreeViewItem node1, DragDropTreeViewItem node2) { return DragDropTreeView.TreeContainsNode(this, node1, node2); }
void treeView_OnDragDropSuccess(DragDropTreeViewItem source, DragDropTreeViewItem target, System.ComponentModel.CancelEventArgs e) { if (!(source.Tag is GameObject)) { e.Cancel = true; return; } List<TreeViewItem> movedItems = TreeViewExtension.GetSelectedTreeViewItems(treeView); // verify if the moved items will not be placed on any of their children or in themselfs foreach (var ti in movedItems) { var tx = (DragDropTreeViewItem)ti; if (ti == target) { // trying to drop on one of the moved items e.Cancel = true; return; } if (DragDropTreeView.TreeContainsNode(treeView, tx, target)) { e.Cancel = true; return; } } if (target.Tag is GameObject) { foreach (var ti in movedItems) { GameObject _source = ti.Tag as GameObject; // no parent? if (_source.Transform.Parent == null) { SceneManager.ActiveScene.GameObjects.Remove(_source, false); } else { GameObject parent = (ti.Parent as DragDropTreeViewItem).Tag as GameObject; parent.Children.Remove(_source, false); } if (DragDropHelper.insertionPlace == DragDropHelper.InsertionPlace.Center) { (target.Tag as GameObject).Children.Insert(0, _source); } else { int index = 0; // no parent? if ((target.Tag as GameObject).Transform.Parent == null) { index = SceneManager.ActiveScene.GameObjects.IndexOf(target.Tag as GameObject); } else { GameObject parent = (target.Parent as DragDropTreeViewItem).Tag as GameObject; index = parent.Children.IndexOf(target.Tag as GameObject); } if (DragDropHelper.insertionPlace == DragDropHelper.InsertionPlace.Top) index++; if ((target.Tag as GameObject).Transform.Parent == null) { SceneManager.ActiveScene.GameObjects.Insert(index, _source); } else { GameObject parent = (target.Parent as DragDropTreeViewItem).Tag as GameObject; parent.Children.Insert(index, _source); } } } } else { e.Cancel = true; } }
// Determine whether one node is a parent // or ancestor of a second node. private bool ContainsNode(DragDropTreeViewItem node1, DragDropTreeViewItem node2) { return(DragDropTreeView.TreeContainsNode(this, node1, node2)); }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); // Retrieve the client coordinates of the drop location. Point targetPoint = e.GetPosition(this); try { // Retrieve the node at the drop location. DragDropTreeViewItem targetNode = GetNearestContainer(e.Source as UIElement); DragDropHelper.RemoveInsertionAdorner(); // Retrieve the node that was dragged. DragDropTreeViewItem draggedNode = (DragDropTreeViewItem)e.Data.GetData(typeof(DragDropTreeViewItem)); if (draggedNode == null) { draggedNode = (DragDropTreeViewItem)e.Data.GetData(typeof(ExplorerTreeViewItem)); } if (targetNode == null || draggedNode == null) { return; } // Confirm that the node at the drop location is not // the dragged node or a descendant of the dragged node. if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode)) { CancelEventArgs evt = new CancelEventArgs(); OnDragDropSuccess(draggedNode, targetNode, evt); if (!evt.Cancel) { // If it is a move operation, remove the node from its current // location and add it to the node at the drop location. if (e.Effects == DragDropEffects.Move) { List <TreeViewItem> items = TreeViewExtension.GetSelectedTreeViewItems(TreeViewExtension.GetTree(targetNode)); if (items != null && items.Count > 0) { // multi selection drag: foreach (var ti in items) { (ti.Parent as ItemsControl).Items.Remove(ti); if (DragDropHelper.insertionPlace == DragDropHelper.InsertionPlace.Center) { targetNode.Items.Add(ti); } else { int index = (targetNode.Parent as ItemsControl).ItemContainerGenerator.IndexFromContainer(targetNode); if (index < 0) { index = 0; } if (DragDropHelper.insertionPlace == DragDropHelper.InsertionPlace.Bottom) { index++; } (targetNode.Parent as ItemsControl).Items.Insert(index, ti); } ti.IsSelected = true; ReApplyStyle(ti as DragDropTreeViewItem, "IgniteMultiTreeViewItem"); } } else { (draggedNode.Parent as ItemsControl).Items.Remove(draggedNode); if (DragDropHelper.insertionPlace == DragDropHelper.InsertionPlace.Center) { targetNode.Items.Add(draggedNode); } else { int index = (targetNode.Parent as ItemsControl).ItemContainerGenerator.IndexFromContainer(targetNode); if (index < 0) { index = 0; } if (DragDropHelper.insertionPlace == DragDropHelper.InsertionPlace.Bottom) { index++; } (targetNode.Parent as ItemsControl).Items.Insert(index, draggedNode); } draggedNode.IsSelected = true; ReApplyStyle(draggedNode, "IgniteTreeViewItem"); } } // OPTIONAL: // If it is a copy operation, clone the dragged node // and add it to the node at the drop location. //else if (e.Effects == DragDropEffects.Copy) //{ // targetNode.Items.Add((DragDropTreeViewItem)draggedNode); //} // Expand the node at the location // to show the dropped node. targetNode.IsExpanded = true; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static bool TreeContainsNode(TreeView tv, DragDropTreeViewItem node1, DragDropTreeViewItem node2) { // Check the parent node of the second node. if (node2.Parent == null || node2.Parent == tv) return false; if (node2.Parent == node1) return true; // If the parent node is not null or equal to the first node, // call the ContainsNode method recursively using the parent of // the second node. return TreeContainsNode(tv, node1, node2.Parent as DragDropTreeViewItem); }
void treeView_OnDragDropSuccess(DragDropTreeViewItem source, DragDropTreeViewItem target, System.ComponentModel.CancelEventArgs e) { if (!(source.Tag is GameObject)) { e.Cancel = true; return; } List <TreeViewItem> movedItems = TreeViewExtension.GetSelectedTreeViewItems(treeView); // verify if the moved items will not be placed on any of their children or in themselfs foreach (var ti in movedItems) { var tx = (DragDropTreeViewItem)ti; if (ti == target) { // trying to drop on one of the moved items e.Cancel = true; return; } if (DragDropTreeView.TreeContainsNode(treeView, tx, target)) { e.Cancel = true; return; } } if (target.Tag is GameObject) { foreach (var ti in movedItems) { GameObject _source = ti.Tag as GameObject; // no parent? if (_source.Transform.Parent == null) { SceneManager.ActiveScene.GameObjects.Remove(_source, false); } else { GameObject parent = (ti.Parent as DragDropTreeViewItem).Tag as GameObject; parent.Children.Remove(_source, false); } if (DragDropHelper.insertionPlace == DragDropHelper.InsertionPlace.Center) { (target.Tag as GameObject).Children.Insert(0, _source); } else { int index = 0; // no parent? if ((target.Tag as GameObject).Transform.Parent == null) { index = SceneManager.ActiveScene.GameObjects.IndexOf(target.Tag as GameObject); } else { GameObject parent = (target.Parent as DragDropTreeViewItem).Tag as GameObject; index = parent.Children.IndexOf(target.Tag as GameObject); } if (DragDropHelper.insertionPlace == DragDropHelper.InsertionPlace.Top) { index++; } if ((target.Tag as GameObject).Transform.Parent == null) { SceneManager.ActiveScene.GameObjects.Insert(index, _source); } else { GameObject parent = (target.Parent as DragDropTreeViewItem).Tag as GameObject; parent.Children.Insert(index, _source); } } } } else { e.Cancel = true; } }
private void treeView_MouseUp(object sender, MouseButtonEventArgs e) { // NEW WAY TO DETECT SELECTIONS: if (sender != null && (sender as TreeView).SelectedItem != null) { List<TreeViewItem> it = TreeViewExtension.GetSelectedTreeViewItems(treeView); EditorHandler.SelectedGameObjects = new List<GameObject>(); foreach (var i in it) { //Console.WriteLine(i.Header); //object tag = ((sender as TreeView).SelectedItem as DragDropTreeViewItem).Tag; // old object tag = (i as DragDropTreeViewItem).Tag; if (tag is GameObject) { // TODO : multiple selection EditorHandler.SelectedGameObjects.Add((GameObject)tag); } } EditorHandler.ChangeSelectedObjects(); lastSelectedItem = (sender as TreeView).SelectedItem as DragDropTreeViewItem; } else { EditorHandler.SelectedGameObjects.Clear(); EditorHandler.ChangeSelectedObjects(); } }