I've never used LINQ, but it looks like the way to go, for this operation. How do you do it?
(If you know of a good beginner's tutorial on LINQ, that looks like something that could be used with Unity, please let me know.)
I've never used LINQ, but it looks like the way to go, for this operation. How do you do it?
(If you know of a good beginner's tutorial on LINQ, that looks like something that could be used with Unity, please let me know.)
You'd do something like:
var ordered = yourList.OrderBy(x=>x.name);
Or as you've mentioned:
yourList = yourList.OrderBy(x=>x.name).ToList();
where yourList is IEnumerable, eg, List< Transform> or GameObject[]
http://msdn.microsoft.com/en-us/vcsharp/aa336746
http://www.dotnetperls.com/linq
Edit: good old List.Sort for an inline sort:
yourList.Sort((x,y) => x.name.CompareTo(y.name));
The Q in LINQ stands for Query. It’s designed as a way to query data in-language. Querying for all objects with x = 1 and ordered by y, that’s perfect. It returns an enumeration of object references, which you can query further, convert to an array, etc. But it will not modify the original data.