void Start() { this.fill = transform.Find("Bar/Fill").GetComponent <Image>(); this.countText = transform.Find("Count/Text").GetComponent <Text>(); this.width = transform.Find("Bar").GetComponent <RectTransform>().rect.width; this.spacing = this.width / maxInterval; //Initalize seperators based on our specified spacing for (int i = 1; i < maxInterval; i++) { GameObject sep = Instantiate(this.seperatorPrefab, transform.position, transform.rotation, transform.Find("Bar/Lines").transform); sep.GetComponent <RectTransform>().localPosition = new Vector3(-this.width / 2.0f + spacing * i, 0, 0); } this.buttons = new List <ActionSelectButton>(); GameObject mainbutton = Instantiate(this.actionSelButtonPrefab, this.transform); RectTransform buttonRect = mainbutton.GetComponent <RectTransform>(); buttonRect.localPosition = new Vector3(24, -25, 0); buttonRect.anchorMin = new Vector2(1, 1); buttonRect.anchorMax = new Vector2(1, 1); buttonRect.sizeDelta = new Vector2(50, 50); this.mainBldgButton = mainbutton.GetComponent <ActionSelectButton>(); this.mainBldgButton.Init(); this.mainBldgButton.SetAction(this.bldgAction); }
public void UpdateActionInfo(List <ActionAvail> aaList) { //Todo delete old buttons first foreach (pAction action in this.actions) // For each action we're specifying, find place it based on cost { ActionAvail aa = aaList.Find(x => x.actionParam.action == action); // What happens if we don't find it? //Determine which parameter we care about int cost = aa.actionParam.factionCost; ActionSelectButton button = this.buttons.Find(x => x.action == action); if (button == null) // If we don't have a button, spawn one and init { GameObject go = Instantiate(this.actionSelButtonPrefab, transform.position, transform.rotation, transform.Find("Bar/Buttons").transform); button = go.GetComponent <ActionSelectButton>(); button.Init(); button.SetAction(action); this.buttons.Add(button); } if (button.cost != cost) //Move button if needed { button.gameObject.GetComponent <RectTransform>().localPosition = new Vector3(-this.width / 2.0f + this.spacing * cost, 0, 0); button.cost = cost; } } }
//Remove -- probably not needed, why add a button to remove it? public void ActionSelectButtonGrpRmv(ActionSelectButton asb) { this.lasb.Remove(asb); }
//############################################# //Functions to control all action select buttons //Add public void ActionSelectButtonGrpAdd(ActionSelectButton asb) { this.lasb.Add(asb); }