Tried to write up a bit of code to load all resources into and object array and use that with the selectiongrid. The program keeps complaining about GUIcontext when the array is a bunch of loaded textures. Anyone got a working code snippet in javascript that shows the proper way to load and use any array? I think if I were writting this in C++ the problem is that the loadall function is loading a generic obkect array, but the overloaded selectiongrid function is expecting an array of texture or GUIContent.
If you’re a total hero, what I actually need to see an example where like 100 images are loaded in and the selection grid shows 20 at a time. I think I can do that on my own after I get past the first hurdle.
What I would do having to display images in the selection grid, is keeping all textures in the collection, not as Textures, but as GUIContent, since they also allow text:
private List<GUIContent> _allItems = new List<GUIContent>();
Then I would fill this list during the initialization:
for (int i=0; i<100; i++) {
_allItems.Add(new GUIContent(_text[i], _textures[i]));
}
I would use another collection for items currently displayed:
private List<GUIContent> _items = new List<GUIContent>();
And whenever the user scrolls the grid, I would use an offset and re-fill this collection:
I’ll work with that tonight and see if it helps me get past my hurdle. The key problem is that loadAll populates and array not of the type that selectiongrid is expecting. So, it sounds like I need to manually populate a new array rather than use typeof or something like it.
As you can see, Resources.LoadAll returns an array of Objects. You cannot cast it to Texture[ ]. You got to iterate through this array and push values into another array (of Texture[ ] type).