I had to implement sorting items by their price for one of my UITables. I named all of GameObjects in that table according to their price(like 5100), but because you can't compare strings as integers(2111 is bigger than 11111 string-style), I had to implement a comparison of strings as integers using int.TryParse. Here is the example methods(in class MiscTools, doesnt matter):
public static int CompareTransformsByNames(Transform first, Transform second)
{
return GetIntFromString(first.name).CompareTo(GetIntFromString(second.name));
}
public static int GetIntFromString(string number)
{
int output;
if (!int.TryParse(number, out output))
{
Debug.Log(string.Format("Unsupported string formant in sorting: {0}", number));
return 0;
}
return output;
}
And this is how it is used:
myTable.children.Sort(MiscTools.CompareTransformsByNames);
myTable.Reposition();
I also tried LINQ approach:
myTable.children.OrderBy(x => MiscTools.GetIntFromString(x.name));
myTable.Reposition();
Both variants work like a charm in editor, table is sorted right, but on devices(both iOS and Android) it does no sorting at all, without any exceptions or anything. I know the only place the table gets sorted is line 66 of UITable.cs(
if (sorted) mChildren.Sort(SortByName);
) but "sorted" flag is off on all tables.
What could possible be a reason of such strange behaviour on devices specifically?