Created
April 25, 2018 17:12
-
-
Save StewMcc/fe97a5607faafd508080c50e0ca44c30 to your computer and use it in GitHub Desktop.
Simple editor extensions for gameobjects.
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
/// <summary> | |
/// GameObject manipulation extensions. | |
/// </summary> | |
public class GameObjectExtensions : MonoBehaviour { | |
private static Transform selectedRoot = null; | |
/// <summary> | |
/// Flattens all children to parent level, can be an expensive as recursive. | |
/// </summary> | |
[MenuItem("GameObject/LittleLot/FlattenHierarchy", priority = 100)] | |
public static void FlattenHierarchy() { | |
Transform[] selectedTransforms = Selection.transforms; | |
for (int i = 0; i < selectedTransforms.Length; i++) { | |
selectedRoot = selectedTransforms[i].parent; | |
FlattenChildren(selectedTransforms[i]); | |
UnityEditor.EditorUtility.DisplayProgressBar("FlattenHierarchy", | |
" Flattening: " + selectedRoot.name, | |
i / selectedTransforms.Length); | |
} | |
} | |
/// <summary> | |
/// Removes All the mesh colliders from the selected object and its children. | |
/// </summary> | |
[MenuItem("GameObject/LittleLot/RemoveAllMeshColliders", priority = 100)] | |
public static void RemoveAllColliders() { | |
GameObject[] selectedGameObjects = Selection.gameObjects; | |
MeshCollider collider = null; | |
for (int i = 0; i < selectedGameObjects.Length; i++) { | |
collider = null; | |
collider = selectedGameObjects[i].GetComponent<MeshCollider>(); | |
if (collider) { | |
DestroyImmediate(collider); | |
} | |
} | |
} | |
private static void FlattenChildren(Transform parent) { | |
Transform child; | |
while (parent.childCount > 0) { | |
child = parent.GetChild(0); | |
child.SetParent(selectedRoot, true); | |
child.name = string.Format("{0}_{1}", parent.name, child.name); | |
FlattenChildren(child); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment