I want to show a number of things like pictures in several pages.In one page ,I’d like to show 16 pics,and if the num pics were more than 16,they would create another page automatically.
So to speak,in each part of our forum(like UnityGUI,Gossip,Unity Support),the number of each page is specified,the more topics ,the more pages.And the page num increase automatically.
does unity can realize collate copies like that?
if so,then how to do it?
You could do this by keeping references to the items in an array. The number of pages is the number of items divided by the number that will fit on a page (16 in this case):-
var items: GameObject; // Doesn't have to be GameObject, just an example
var itemsPerPage: int = 16;
function OnGUI() {
...
var numPages: int = items.Length / itemsPerPage;
...
}
Displaying the items for a particular page is a matter of finding the range of items to display from the array. Generally, this means finding the first item for the page and assuming the next fifteen items after are all for that page. However, the last page may not have sixteen items, so you must take that into account:-
function OnGUI() {
...
var currentPage: int = <value from a GUI control or whatever>;
var firstPageItem: int = currentPage * itemsPerPage;
var lastPageItem: int = Math.Min(firstPageItem + itemsPerPage -1, items.Length - 1);
for (i = firstPageItem; i <= lastPageItem; i++) {
// Display items[i] somehow...
}
}
Note that this relies on the pages being numbered from zero in the same way as the array indices. Usually, you would want to show the user page numbers that start from one, so you need to add one to the number that the user sees.
As for displaying the page number choices, a selection grid might be a good way to go, but there are other possibilities, of course. For example, you may want to have objects in the scene that can be clicked to act as buttons, or whatever.