public override List<SelObj> CloneObjects(IEnumerable<SelObj> objEnum) { if (objEnum == null || !objEnum.Any()) return base.CloneObjects(objEnum); var objList = objEnum.Select(s => s.ActualObject as GameObject).ToList(); CloneGameObjectAction cloneAction = new CloneGameObjectAction(objList); UndoRedoManager.Do(cloneAction); return cloneAction.Result.Select(o => new SelGameObj(o) as SelObj).ToList(); }
protected void CloneNodes(IEnumerable<TreeNodeAdv> nodes) { if (!nodes.Any()) return; var nodeQuery = from viewNode in nodes select this.objectModel.FindNode(this.objectView.GetPath(viewNode)) as NodeBase; var objQuery = from objNode in nodeQuery where objNode is GameObjectNode select (objNode as GameObjectNode).Obj; var objArray = objQuery.ToArray(); this.objectView.BeginUpdate(); // Deselect original nodes foreach (GameObject obj in objArray) { TreeNodeAdv dragObjViewNode; dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(obj))); dragObjViewNode.IsSelected = false; } CloneGameObjectAction cloneAction = new CloneGameObjectAction(objArray); UndoRedoManager.Do(cloneAction); // Select new nodes foreach (GameObject clonedObj in cloneAction.Result) { TreeNodeAdv dragObjViewNode; dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(clonedObj))); dragObjViewNode.IsSelected = true; this.objectView.EnsureVisible(dragObjViewNode); } this.objectView.EndUpdate(); }
private void copyHereToolStripMenuItem_Click(object sender, EventArgs e) { GameObject[] draggedObj = this.tempDropData as GameObject[]; Component[] draggedComp = this.tempDropData as Component[]; GameObject dropObj = (this.tempDropTarget is GameObjectNode) ? (this.tempDropTarget as GameObjectNode).Obj : null; if (draggedObj != null) { UndoRedoManager.BeginMacro(); CloneGameObjectAction cloneAction = new CloneGameObjectAction(draggedObj); UndoRedoManager.Do(cloneAction); UndoRedoManager.Do(new SetGameObjectParentAction(dropObj, cloneAction.Result)); UndoRedoManager.EndMacro(UndoRedoManager.MacroDeriveName.FromFirst); // Deselect dragged nodes foreach (GameObject dragObj in draggedObj) { TreeNodeAdv dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(dragObj))); dragObjViewNode.IsSelected = false; } // Select new nodes foreach (GameObject dragObjClone in cloneAction.Result) { TreeNodeAdv dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(dragObjClone))); dragObjViewNode.IsSelected = true; this.objectView.EnsureVisible(dragObjViewNode); } } else if (draggedComp != null) { // Clone Components CreateComponentAction cloneAction = new CreateComponentAction(dropObj, draggedComp.Select(c => c.Clone())); UndoRedoManager.Do(cloneAction); // Deselect dragged nodes foreach (Component dragObj in draggedComp) { TreeNodeAdv dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(dragObj))); dragObjViewNode.IsSelected = false; } // Select new nodes foreach (Component dragObjClone in cloneAction.Result) { TreeNodeAdv dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(dragObjClone))); dragObjViewNode.IsSelected = true; this.objectView.EnsureVisible(dragObjViewNode); } } }