//Class to control creation of Dynamic Buttons
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class DynamicButtonController : MonoBehaviour {
//Variables
public GameObject uiObject;
List<CheckIn> checkInList;
float dy = -77.0f;
//List<string> testString;
/*void Start(){
testString = new List<string>();
for(int x = 0; x < 5; x++){
testString.Add("#" + x);
}
CreateButtons();
}*/
public void CreateButtons(){
//Creates a starting vector for the first button
Vector3 startingVector
= new Vector3
(260
.0f, 480
.0f,
-30
.0f
); Debug.Log("--->End Vector");
//populates the list
checkInList = CheckInCollection.GetCheckInCollection();
//loop to create the buttons
for(int i = 0; i < checkInList.Count; /*testString.Count;*/ i++){
Debug.Log("--->i: " + i);
//adds a new gameobject to the panel
GameObject newButton = NGUITools.AddChild(this.gameObject, uiObject);
Debug.Log("--->newButton" + i);
//Assigns a button name so it can be found later
newButton.name = checkInList[i].name; /*testString[i];*/
//instantiates a new ui object
UILabel newButtonLabel = newButton.GetComponentInChildren<UILabel>();
Debug.Log("--->newButtonLabel");
//sets the label of the uiobject to the list value in i.name
newButtonLabel.text = checkInList[i].name; /*testString[i];*/
//Sets the location of the button
newButton
.transform.localScale = new Vector3
(2f, 2f, 1f
); //if to check if first element
if(i == 0){
newButton.transform.localPosition = startingVector;
Debug.Log("--->transform" + i);
}
//all buttons after the first
else{
newButton
.transform.localPosition = new Vector3
(startingVector
.x,
(dy
*i
)+startingVector
.y, startingVector
.z); Debug.Log("--->transform" + i);
}
}
}
}