public static BonsaiNode DuplicateSingle(BonsaiCanvas canvas, BonsaiNode original) { BonsaiNode duplicate = canvas.CreateNode(original.Behaviour.GetType()); // Duplicate nodes are placed offset from the original. duplicate.Position = original.Position + Vector2.one * 40f; return(duplicate); }
private void onMultiNodeCallback(object o) { NodeContext context = (NodeContext)o; switch (context) { case NodeContext.DuplicateSelection: BonsaiCanvas canvas = _window.editor.canvas; BehaviourTree bt = _window.tree; for (int i = 0; i < _selectedNodes.Count; ++i) { // The original nodes will become selected. BonsaiNode node = _selectedNodes[i]; node.bAreaSelectionFlag = false; Type t = node.behaviour.GetType(); // Duplicate nodes become selected and are spawned // at offset from their original. BonsaiNode duplicate = canvas.CreateNode(t, bt); duplicate.bAreaSelectionFlag = true; duplicate.bodyRect.position = node.bodyRect.position + Vector2.one * 40f; // Replace in the list with new selections. _selectedNodes[i] = duplicate; } // Notify inspector about the new selections. setSelectedInInspector(); break; case NodeContext.DeleteSelection: _window.editor.canvas.RemoveSelected(); clearAreaSelection(); setTreeAsSelected(); break; } }