public static Transform GroupLocally(Transform[] targets, string name = "Group") { var transformType = InferTransformTypeOrFail(targets); var group = CreateGroup(name, transformType); Undo.RegisterCreatedObjectUndo(group, "Group"); var shallowestTarget = TransformOperations.FindShallowest(targets); Undo.SetTransformParent(group.transform, shallowestTarget.transform.parent, "Group"); foreach (var target in targets) { Undo.SetTransformParent(target.transform, group.transform, "Group"); } if (transformType == typeof(RectTransform)) { TransformOperations.CenterOnPivots(group.transform); } else { TransformOperations.CenterOnBounds(group.transform); } return(group.transform); }
public static void CreateParent(GameObject[] targets, Rect activatorPosition) { Validate(targets); var transformTargets = targets.Select(t => t.transform).ToArray(); if (!TransformOperations.WarnRestructurable(transformTargets)) { return; } var shallowestTarget = TransformOperations.FindShallowest(transformTargets); CreateMenu ( activatorPosition, created => { Undo.SetTransformParent(created.transform, shallowestTarget.transform.parent, "Create Parent"); foreach (var target in targets) { Undo.SetTransformParent(target.transform, created.transform, "Create Parent"); } TransformOperations.CenterOnBounds(created.transform); Selection.activeGameObject = created; Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } ); }
public static Transform GroupLocally(Transform[] targets, string name = "Group") { var transformType = InferTransformTypeOrFail(targets); var firstSiblingIndex = targets.Select(t => t.GetSiblingIndex()).Min(); var group = CreateGroup(name, transformType); Undo.RegisterCreatedObjectUndo(group, "Group"); var shallowestTarget = TransformOperations.FindShallowest(targets); Undo.SetTransformParent(group.transform, shallowestTarget.transform.parent, "Group"); foreach (var target in targets.OrderBy(t => t.GetSiblingIndex())) { Undo.SetTransformParent(target.transform, group.transform, "Group"); } Undo.RecordObject(group.transform, "Group"); group.transform.SetSiblingIndex(firstSiblingIndex); if (transformType == typeof(RectTransform)) { TransformOperations.CenterOnPivots(group.transform); } else { TransformOperations.CenterOnBounds(group.transform); } return(group.transform); }
public static Transform GroupLocally(Transform[] targets, string name = "Group") { var transformType = InferTransformTypeOrFail(targets); var scene = TransformOperations.FindCommonScene(targets); var haveCommonScene = scene != null; scene = scene ?? EditorSceneManager.GetActiveScene(); var firstSiblingIndex = targets.Select(t => t.GetSiblingIndex()).Min(); var group = CreateGroup(name, transformType); Undo.RegisterCreatedObjectUndo(group, "Group"); Undo.MoveGameObjectToScene(group.gameObject, scene.Value, "Group"); if (haveCommonScene) { var shallowestTarget = TransformOperations.FindShallowest(targets); Undo.SetTransformParent(group.transform, shallowestTarget.transform.parent, "Group"); } foreach (var target in targets.OrderBy(t => t.GetSiblingIndex())) { Undo.SetTransformParent(target.transform, null, "Group"); Undo.MoveGameObjectToScene(target.gameObject, scene.Value, "Group"); Undo.SetTransformParent(target.transform, group.transform, "Group"); } Undo.RecordObject(group.transform, "Group"); if (haveCommonScene) { group.transform.SetSiblingIndex(firstSiblingIndex); } if (transformType == typeof(RectTransform)) { TransformOperations.CenterOnPivots(group.transform); } else { TransformOperations.CenterOnBounds(group.transform); } return(group.transform); }
private static void CenterOnBounds(MenuCommand menuCommand) { var target = GetTarget(menuCommand); GuiCallback.Enqueue(() => { TransformOperations.CenterOnBounds(target); }); }