示例#1
0
        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);
        }
示例#2
0
        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 CenterOnPivots(MenuCommand menuCommand)
        {
            var target = GetTarget(menuCommand);

            GuiCallback.Enqueue(() => { TransformOperations.CenterOnPivots(target); });
        }