Last active
September 22, 2023 02:07
-
-
Save PhilippCh/af71c00a20786495c4315b3c42e687a2 to your computer and use it in GitHub Desktop.
Adds a context (right-click) menu to Unity's scene hierarchy tab that allows for quick grouping of selected GameObjects under a new parent.
This file contains 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 UnityEditor; | |
using UnityEngine; | |
#if UNITY_EDITOR | |
namespace CelestialStatic.Editor { | |
public class GameObjectGrouping { | |
[MenuItem("GameObject/Group selected GameObjects", false, 0)] | |
public static void GroupSelected(MenuCommand menuCommand) { | |
//Prevent executing multiple times when right-clicking. | |
if (Time.unscaledTime.Equals(_lastMenuCallTimestamp)) { | |
return; | |
} | |
var parent = new GameObject(); | |
var selected = Selection.gameObjects; | |
foreach (var gameObject in selected) { | |
gameObject.transform.SetParent(parent.transform); | |
} | |
Selection.activeGameObject = parent; | |
_lastMenuCallTimestamp = Time.unscaledTime; | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment