// Select a site button (i.e. "Luxor", "Mar Saba", etc.) public void SelectSiteButton(SiteButton siteButton) { // Initialize this list. siteElementButtons = new List <SiteElementButton>(); // Get all the data types associated with that site. List <SiteElementSet> dataSets = siteButton.associatedSite.dataSets; siteButton.associatedSite.associatedPOI.SetSelected(true); // Create a button for each data type. for (int i = 0; i < dataSets.Count; i++) { // This specific data set. SiteElementSet dataSet = dataSets[i]; // Create the new button from component. Add the SiteElementButton script and give it a name. SiteElementButton newButton = (GameObject.Instantiate(siteElementButtonPrefab) as GameObject).AddComponent <SiteElementButton>(); newButton.gameObject.name = dataSet.setType; // Be sure to set the data. newButton.SetData(dataSet); // Determine this button's x and y position. float newXPos = i * (newButton.buttonSize.x + horizontalBuffer); float newYPos = -siteButton.buttonSize.y / 1.5f + verticalBuffer; //Determine size of site element button newButton.GetComponentInChildren <RectTransform>().sizeDelta = new Vector2(35, 10); // Set the parent and position of the button. newButton.transform.SetParent(siteButton.transform); newButton.transform.localPosition = new Vector3(newXPos, newYPos, 0.0f); // Add this button to the list. siteElementButtons.Add(newButton); // Set the button color to inactive. newButton.SetButtonColor(buttonInactiveColor); // Set data button font size and color newButton.GetComponentInChildren <Text>().fontSize = dataButtonTextSize; newButton.GetComponentInChildren <Text>().color = buttonTextColor; newButton.GetComponentInChildren <Text>().font = latoBold; } // If there are any data types, highlight the first one. if (dataSets.Count > 0) { selectedElementIndex = 0; siteElementButtons[selectedElementIndex].SetButtonColor(buttonActiveColor); } }
// Instantiate buttons on the UI. public void CreateButtons() { // Set up lists to hold sites. siteButtons = new List <SiteButton>(); // Get all the sites from the site manager. List <Site> allSites = siteManager.sites; // Create a button for each site. for (int i = 0; i < allSites.Count; i++) { // The current site. Site site = allSites[i]; // Instantiate the button from prefab, and add the SiteButton component. Name it the site name. SiteButton newButton = (GameObject.Instantiate(buttonPrefab) as GameObject).AddComponent <SiteButton>(); newButton.gameObject.name = site.siteName; newButton.GetComponentInChildren <Text>().color = buttonTextColor; newButton.GetComponentInChildren <Text>().fontSize = siteButtonTextSize; newButton.GetComponentInChildren <Text>().font = latoBlack; newButton.GetComponentInChildren <RectTransform>().sizeDelta = new Vector2(35, 40); // Set the associated site. newButton.SetSite(site); // Determine the x position this button should go. float newXPos = siteButtonStartPos.x - (allSites.Count / 2 * (newButton.buttonSize.x + horizontalBuffer)) + (i * (newButton.buttonSize.x + horizontalBuffer)); // Set the parent and position of the button. newButton.transform.SetParent(this.transform); newButton.transform.localPosition = new Vector3(newXPos, siteButtonStartPos.y, 0.0f); // Add this button to the list. siteButtons.Add(newButton); // Color the button unselected. newButton.SetButtonColor(buttonInactiveColor); // newButton.SetDescription(site, latoBold); } // If there are any buttons, select the middle one (show a highlight). if (siteButtons.Count > 0) { selectedSiteIndex = siteButtons.Count / 2; siteButtons[selectedSiteIndex].SetButtonColor(buttonActiveColor); StartCoroutine(SetActivePOIWhenReady()); } }