//Paste the copied objects by instantiating them private void PasteSelection() { //Temporary GameObject to enable cloned objects before storing them GameObject objectClone; //Reset the current selection ObjectSelection.Instance.DeselectAll(); //Loop through all of the copied objects foreach (Transform copiedObject in Instance.copiedObjectsRoot.transform) { //Instantiate and enable the cloned object objectClone = Instantiate(copiedObject.gameObject); objectClone.SetActive(true); //Get a reference to the cloned object's MapObject script MapObject mapObjectScript = objectClone.GetComponent <MapObject>(); //Copy the values of the original map object script mapObjectScript.CopyValues(copiedObject.GetComponent <MapObject>()); //Add the object to the map and make it selectable AddObjectToMap(objectClone, mapObjectScript); ObjectSelection.Instance.SelectObject(objectClone); } //Once the selection is pasted, change the tool type to translate ToolButtonManager.SetTool(Tool.Translate); //Notify listeners that the copied objects were pasted at the end of the frame StartCoroutine(InvokeOnPaste()); }
//Copy a selection by cloning all of the selected objects and storing them private void CopySelection() { //Get a reference to the list of selected objects HashSet <GameObject> selectedObjects = ObjectSelection.Instance.GetSelection(); //If there aren't any objects to copy, return if (selectedObjects.Count == 0) { return; } //Destroy any previously copied objects foreach (Transform copiedObject in Instance.copiedObjectsRoot.transform) { Destroy(copiedObject.gameObject); } //Temporary GameObject to disable cloned objects before storing them GameObject objectClone; //Clone each selected object and save it in the copied objects list foreach (GameObject mapObject in selectedObjects) { //Instantiate and disable the copied objects objectClone = Instantiate(mapObject); objectClone.SetActive(false); //Get a reference to the cloned object's MapObject script MapObject mapObjectScript = objectClone.GetComponent <MapObject>(); //Copy the values of the original map object script mapObjectScript.CopyValues(mapObject.GetComponent <MapObject>()); //Set the object as the child of the copied objects root objectClone.transform.parent = Instance.copiedObjectsRoot.transform; } selectionCopied = true; }