protected GameObject CreateGameObject(TreeNodeAdv baseNode, string objName = null) { if (objName == null) objName = typeof(GameObject).Name; GameObjectNode baseObjNode = baseNode == null ? null : baseNode.Tag as GameObjectNode; GameObject baseObj = baseObjNode == null ? null : baseObjNode.Obj; GameObject newObj = new GameObject(); newObj.Name = objName; CreateGameObjectAction action = new CreateGameObjectAction(baseObj, newObj); UndoRedoManager.Do(action); return action.Result.FirstOrDefault(); }
private void DragBeginAction(DragEventArgs e) { DataObject data = e.Data as DataObject; var dragObjQuery = new ConvertOperation(data, ConvertOperation.Operation.All).Perform<GameObject>(); if (dragObjQuery != null) { List<GameObject> dragObj = dragObjQuery.ToList(); bool lockZ = this.CameraComponent.FocusDist <= 0.0f; Point mouseLoc = this.PointToClient(new Point(e.X, e.Y)); Vector3 spaceCoord = this.GetSpaceCoord(new Vector3( mouseLoc.X, mouseLoc.Y, lockZ ? 0.0f : this.CameraObj.Transform.Pos.Z + MathF.Abs(this.CameraComponent.FocusDist))); if ((this.SnapToUserGuides & UserGuideType.Position) != UserGuideType.None) { spaceCoord = this.EditingUserGuide.SnapPosition(spaceCoord); } // Setup GameObjects CreateGameObjectAction createAction = new CreateGameObjectAction(null, dragObj); DropGameObjectInSceneAction dropAction = new DropGameObjectInSceneAction(dragObj, spaceCoord, this.CameraObj.Transform.Angle); UndoRedoManager.BeginMacro(dropAction.Name); UndoRedoManager.Do(createAction); UndoRedoManager.Do(dropAction); // Select them & begin action this.selBeforeDrag = DualityEditorApp.Selection; this.SelectObjects(createAction.Result.Select(g => new SceneEditorSelGameObj(g) as ObjectEditorSelObj)); this.BeginAction(ObjectEditorAction.Move); // Get focused this.Focus(); e.Effect = e.AllowedEffect; } }
private void objectView_DragDrop(object sender, DragEventArgs e) { this.objectView.BeginUpdate(); bool effectMove = (e.Effect & DragDropEffects.Move) != DragDropEffects.None; bool effectCopy = (e.Effect & DragDropEffects.Copy) != DragDropEffects.None; DataObject data = e.Data as DataObject; if (data != null) { ConvertOperation convertOp = new ConvertOperation(data, ConvertOperation.Operation.All); this.tempDropTarget = this.DragDropGetTargetNode(); if (data.ContainsGameObjectRefs()) { this.tempDropData = data.GetGameObjectRefs(); // Display context menu if both moving and copying are availabled if (effectMove && effectCopy) this.contextMenuDragMoveCopy.Show(this, this.PointToClient(new Point(e.X, e.Y))); else if (effectCopy) this.copyHereToolStripMenuItem_Click(this, null); else if (effectMove) this.moveHereToolStripMenuItem_Click(this, null); } else if (data.ContainsComponentRefs()) { this.tempDropData = data.GetComponentRefs(); // Display context menu if both moving and copying are availabled if (effectMove && effectCopy) this.contextMenuDragMoveCopy.Show(this, this.PointToClient(new Point(e.X, e.Y))); else if (effectCopy) this.copyHereToolStripMenuItem_Click(this, null); else if (effectMove) this.moveHereToolStripMenuItem_Click(this, null); } else if (this.tempDropTarget != null && convertOp.CanPerform<Component>()) { GameObject dropObj = null; if (this.tempDropTarget is GameObjectNode) dropObj = (this.tempDropTarget as GameObjectNode).Obj; else dropObj = (this.tempDropTarget as ComponentNode).Component.GameObj; var componentQuery = convertOp.Perform<Component>(); if (componentQuery != null) { // Create Components CreateComponentAction createAction = new CreateComponentAction(dropObj, componentQuery.Where(c => c.GameObj == null)); UndoRedoManager.BeginMacro(); UndoRedoManager.Do(new DeleteComponentAction(componentQuery.Select(c => dropObj.GetComponent(c.GetType())).NotNull())); UndoRedoManager.Do(createAction); UndoRedoManager.EndMacro(UndoRedoManager.MacroDeriveName.FromLast); bool selCleared = false; foreach (Component newComponent in createAction.Result) { NodeBase dataNode = this.FindNode(newComponent); if (dataNode == null) continue; TreeNodeAdv viewNode = this.objectView.FindNode(this.objectModel.GetPath(dataNode)); if (viewNode == null) continue; if (!selCleared) { this.objectView.ClearSelection(); selCleared = true; } viewNode.IsSelected = true; this.objectView.EnsureVisible(viewNode); } } } else if (convertOp.CanPerform<GameObject>()) { GameObject dropObj = (this.tempDropTarget is GameObjectNode) ? (this.tempDropTarget as GameObjectNode).Obj : null; var gameObjQuery = convertOp.Perform<GameObject>(); if (gameObjQuery != null) { CreateGameObjectAction action = new CreateGameObjectAction(dropObj, gameObjQuery); UndoRedoManager.Do(action); bool selCleared = false; foreach (GameObject newObj in action.Result) { NodeBase dataNode = this.FindNode(newObj); if (dataNode == null) continue; TreeNodeAdv viewNode = this.objectView.FindNode(this.objectModel.GetPath(dataNode)); if (viewNode == null) continue; if (!selCleared) { this.objectView.ClearSelection(); selCleared = true; } viewNode.IsSelected = true; this.objectView.EnsureVisible(viewNode); } } } } this.objectView.EndUpdate(); }
private void ActionPrefabOpenRes(Prefab prefab) { try { CreateGameObjectAction undoRedoAction = new CreateGameObjectAction(null, prefab.Instantiate()); UndoRedoManager.Do(undoRedoAction); DualityEditorApp.Select(this, new ObjectSelection(undoRedoAction.Result)); } catch (Exception exception) { Log.Editor.WriteError("An error occurred instanciating Prefab {1}: {0}", Log.Exception(exception), prefab != null ? prefab.Path : "null"); } }