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(); }
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(); } }
private void treeView_MouseDown(object sender, MouseButtonEventArgs e) { canCopyPaste = true; if (treeView.SelectedItem != null && e.LeftButton == MouseButtonState.Pressed) { (treeView.SelectedItem as TreeViewItem).IsSelected = false; TreeViewExtension.UnselectAll(treeView); } }