public override void OnInspectorGUI() { PathGuide connectedObjects = target as PathGuide; if (connectedObjects == null) { return; } if (GUILayout.Button("Duplicate Node (D)", GUILayout.Width(255))) { connectedObjects.Duplicate(connectedObjects); } }
public void Duplicate(PathGuide toDupe) { #if UNITY_EDITOR Undo.SetCurrentGroupName("Duplicate Curve Node"); GameObject dupe = Instantiate(toDupe.gameObject); Undo.RegisterCreatedObjectUndo(dupe, ""); dupe.transform.parent = toDupe.transform.parent; dupe.transform.position = toDupe.transform.position; int index = (toDupe.transform.GetSiblingIndex() == 0) ? 0 : toDupe.transform.GetSiblingIndex() + 1; dupe.transform.SetSiblingIndex(index); Undo.RegisterFullObjectHierarchyUndo(dupe.transform.parent.gameObject, ""); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); Selection.activeGameObject = dupe; GetOwnerPath().RefreshChildIndexes(); #endif }
void OnSceneGUI() { Event e = Event.current; if (e.type == EventType.KeyDown && e.keyCode == KeyCode.D) { PathGuide connectedObjects = target as PathGuide; if (connectedObjects == null) { return; } connectedObjects.Duplicate(connectedObjects); Debug.Log("Dupe"); } }