Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sequence {
- private static GameObject[] _items;
- public static GameObject[] items {
- get {
- if (_items == null)
- {
- _items = FindObjectsWithTag("Sequence Item");
- _items.Sort(new SequenceObjectComparer());
- }
- return _items;
- }
- }
- }
- public class SequenceObjectComparer : IComparer<GameObject>
- {
- public int Compare (GameObject a, GameObject b)
- {
- int a_id = ParseNumberAtEnd(a.name);
- int b_id = ParseNumberAtEnd(b.name);
- if (a_id > b_id) {
- return 1;
- } else {
- return -1;
- }
- }
- public static int ParseNumberAtEnd(string text)
- {
- for (int i = text.Length-1; i >= 0; i--)
- {
- if (!Character.IsDigit(text[i]))
- {
- if (i == text.Length - 1)
- {
- Debug.LogError("No digits at end of GameObject's name: "+text);
- }
- string digits = text.Substring(i+1);
- return int.Parse(digits);
- }
- }
- // Text is entirely made of digits!
- return int.Parse(text);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment