I have a javascript that holds some items for my game. The items all have a script attached, and variables that determine how many there are and what type of item it is.
I was wondering if it was possible to use Sort() to arrange the items in the array so that I could sort it by type, and then by the object’s name, both are contained within the script.
I’ve looked at the documentation for sort, and it’s not very helpful.
http://unity3d.com/support/documentation/ScriptReference/Array.Sort.html
searching on the internet, I’ve been able to find some hints that what I want might be possible, but nothing that is really usable.
Alright this seems like it might work, can you use it in javascript? I have a very long script that I'm using and to rewrite it in C# would be less than ideal.
– anon65678232This works in javascript too, check out the blog post in the answer. var myList = new List.<Type>();
– anon48142526When I try and change my array to a generic list it says that "List does not devote a valid type." Is this a pro feature, or do I have to do something besides just declare it?
– anon65678232Also, I found this on while looking up more on Javascript Arrays http://www.javascriptkit.com/javatutors/arraysort2.shtml however to sort strings, you need to compare them, unity does not allow this. "Missing Method Extension String.opLess than" (or something along those lines) Is there a way to make this work?
– anon65678232