using UnityEngine;
using System.Collections;
public class CLevelSelectionBuilder : MonoBehaviour
{
public int totalLevels;
public GameObject itemsParent; //the parent of all itemLevel(s)
public GameObject itemLevelPrefab; //itemLevel
public GameObject page1;
public GameObject page2;
public GameObject page3;
public GameObject page4;
void Start ()
{
CUtility.ValidateNextLevel(); //make sure the relevant level is opened.
totalLevels = CUtility.totalLevels;
CreateItems
( new Vector3
(-345f,188f,0f
),totalLevels
); }
void CreateItems( Vector3 startPivot, int totalLevels )
{
int maxPerSet = 12;
int col = 4;
Vector3 pivot = startPivot;
Vector3 currentPivot = startPivot;
//int curRowIndex = 1;
for( int i=1;i<=totalLevels;i++){
if( i % maxPerSet == 0 ){
//set pivot
CreateItem( i, currentPivot);
pivot
= new Vector3
( currentPivot
.x+235f, pivot
.y,pivot
.z ); currentPivot = pivot;
}else if( i % col == 0 ){
CreateItem( i, currentPivot );
currentPivot
= new Vector3
( pivot
.x,currentPivot
.y-213f,currentPivot
.z); }else{
//set item
CreateItem( i, currentPivot );
currentPivot
= new Vector3
( currentPivot
.x + 235,currentPivot
.y,currentPivot
.z); }
}
}
private void CreateItem( int pLevelNum,Vector3 itemPosition )
{
GameObject page = null;
if( pLevelNum>0 && pLevelNum <=12 )
page = page1;
if( pLevelNum>12 && pLevelNum <=24 )
page = page2;
if( pLevelNum>24 && pLevelNum <=36 )
page = page3;
if( pLevelNum>36 && pLevelNum <=48 )
page = page4;
GameObject go = NGUITools.AddChild( page,itemLevelPrefab );
go.transform.localPosition = itemPosition;
ILevelItem iitem
= (ILevelItem
)go
.GetComponent(typeof(ILevelItem
)); if( iitem!=null )
iitem.SetItem( pLevelNum );
go
.AddComponent(typeof(UIDragPanelContents
));
}
}