Last active
February 23, 2024 10:11
-
-
Save AShim3D/d76e2026c5655b3b34e2 to your computer and use it in GitHub Desktop.
Sort children by name in selected gameobjects. Unity3D 4.5+ (C#).
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 UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class TempTools { | |
[MenuItem ("AShim/SortChildrenByName")] | |
public static void SortChildrenByName() { | |
foreach (GameObject obj in Selection.gameObjects) { | |
List<Transform> children = new List<Transform>(); | |
for (int i = obj.transform.childCount - 1; i >= 0; i--) { | |
Transform child = obj.transform.GetChild(i); | |
children.Add(child); | |
child.parent = null; | |
} | |
children.Sort((Transform t1, Transform t2) => { return t1.name.CompareTo(t2.name); }); | |
foreach (Transform child in children) { | |
child.parent = obj.transform; | |
} | |
} | |
} // SortChildrenByName() | |
} // class TempTools |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Method to sort all the children inside another children