Created
January 3, 2018 11:32
-
-
Save seckincengiz/6c4dc39574f4870e0cf0b0b5b3f970c4 to your computer and use it in GitHub Desktop.
Group unity objects in edit mode | (CTRL + G) | Unity3D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
[ExecuteInEditMode] | |
public class GroupUnityObjects : Editor | |
{ | |
[MenuItem("Edit/Group %g", false)] | |
public static void Group() | |
{ | |
if (Selection.transforms.Length > 0) | |
{ | |
GameObject group = new GameObject("Group"); | |
// Set Pivot | |
Vector3 pivotPosition = Vector3.zero; | |
foreach (Transform g in Selection.transforms) | |
{ | |
pivotPosition += g.transform.position; | |
} | |
pivotPosition /= Selection.transforms.Length; | |
group.transform.position = pivotPosition; | |
// Undo action | |
Undo.RegisterCreatedObjectUndo(group, "Group"); | |
foreach (GameObject s in Selection.gameObjects) | |
{ | |
Undo.SetTransformParent(s.transform, group.transform, "Group"); | |
} | |
Selection.activeGameObject = group; | |
} | |
else | |
{ | |
Debug.LogWarning("No selection!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! Exactly what I was looking for.
Add
group.transform.parent = Selection.transforms[0].parent;
after line 12 to make grouping inside groups possible