1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| using UnityEngine; using UnityEditor;
class CreateParentForTransforms : ScriptableObject { [MenuItem("MenuUtility/Create Parent For Selection")] static void MenuInsertParent() { Transform[] selection = Selection.GetTransforms( SelectionMode.TopLevel | SelectionMode.Editable); GameObject newParent = ObjectFactory.CreateGameObject("Parent"); Undo.RegisterCreatedObjectUndo(newParent, "Create Parent For Selection"); foreach (Transform t in selection) { Undo.SetTransformParent(t, newParent.transform, "Create Parent For Selection 1"); } }
[MenuItem("MenuUtility/Create Parent For Selection", true)] static bool ValidateSelection() { return Selection.activeTransform != null; } }
|