// Paste protected override void PasteNodesFromPasteboard() { var g = (Graph)graph; // Create a paste point. It has two level depth. var point1 = new GameObject("<PastePoint1>"); var point2 = new GameObject("<PastePoint2>"); point1.transform.parent = g.patch.transform; point2.transform.parent = point1.transform; // Select the paste point in the scene hierarchy. Selection.activeGameObject = point2; // Paste from the pasteboard. Unsupported.PasteGameObjectsFromPasteboard(); // Point2 (placeholder) is not needed anymore. DestroyImmediate(point2); // Move pasted objects to the right position. var instances = point1.GetComponentsInChildren <Wiring.NodeBase>(); foreach (var i in instances) { i.transform.parent = g.patch.transform; } // Point1 (group) is not needed anymore. DestroyImmediate(point1); // Resync the graph. g.Invalidate(); g.SyncWithPatch(); // Select and offset the pasted nodes. ClearSelection(); foreach (var i in instances) { var node = graph[i.GetInstanceID().ToString()]; node.position.position += Vector2.one * (_pasteOffset * kNodeGridSize * 2); node.Dirty(); selection.Add(node); } _pasteOffset++; }
private void PasteToSelection(GameObject[] selection) { GameObject tempObject = null; if (selection == null || selection.Length == 0 || (selection.Length == 1 && selection[0] == RootGameObject)) { // We want to paste inside the root object, so we have to select one of its children Transform rootTransform = RootTransform; if (rootTransform.childCount > 0) { selection = new GameObject[1] { rootTransform.GetChild(0).gameObject } } ; else { // Create a temporary child object tempObject = new GameObject("TEMP"); selection = new GameObject[1] { tempObject }; } } try { if (tempObject) { tempObject.transform.SetParent(RootTransform, false); } Selection.objects = selection; using (new SelectionChangeApplier(this)) Unsupported.PasteGameObjectsFromPasteboard(); } finally { if (tempObject) { Object.DestroyImmediate(tempObject); } } }
public override void ExecuteAction() { Unsupported.PasteGameObjectsFromPasteboard(); var transforms = Selection.transforms; var bounds = ObjectUtils.GetBounds(transforms); foreach (var transform in transforms) { var pasted = transform.gameObject; var pastedTransform = pasted.transform; pasted.hideFlags = HideFlags.None; var cameraTransform = CameraUtils.GetMainCamera().transform; pastedTransform.position = cameraTransform.TransformPoint(Vector3.forward * s_BufferDistance) + pastedTransform.position - bounds.center; pasted.SetActive(true); this.AddToSpatialHash(pasted); } }