Tanoda
pb_DuplicateButton.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
3using System.Collections.Generic;
4
5namespace GILES
6{
8 {
9 protected override void Start()
10 {
11 base.Start();
12
13 pb_Selection.AddOnSelectionChangeListener( OnSelectionChanged );
14 OnSelectionChanged(null);
15 }
16
17 public override string tooltip { get { return "Duplicate Selection"; } }
18
19 public void DoDuplicate()
20 {
21 List<GameObject> newObjects = new List<GameObject>();
22 List<IUndo> undo = new List<IUndo>() { new UndoSelection() };
23
24 foreach(GameObject go in pb_Selection.gameObjects)
25 {
26 GameObject inst = (GameObject) pb_Scene.Instantiate(go);
27 newObjects.Add(inst);
28 undo.Add(new UndoInstantiate(inst));
29 }
30
31 Undo.RegisterStates(undo, "Duplicate Object");
32
33 pb_Selection.SetSelection(newObjects);
34 }
35
36 private void OnSelectionChanged(IEnumerable<GameObject> go)
37 {
39 }
40 }
41}
static void RegisterStates(IEnumerable< IUndo > targets, string message)
Definition: Undo.cs:226
static UnityEngine.GameObject Instantiate(UnityEngine.GameObject original)
Definition: pb_Scene.cs:133
static List< GameObject > gameObjects
A list of the currently selected GameObjects.
Definition: pb_Selection.cs:56
static void AddOnSelectionChangeListener(Callback< IEnumerable< GameObject > > del)
Definition: pb_Selection.cs:34
static void SetSelection(IEnumerable< GameObject > selection)
Definition: pb_Selection.cs:92
static GameObject activeGameObject
Definition: pb_Selection.cs:82