// UpdateUI is only called through the SelectionScript when a unit is selected or deselected. // Currently this system only works with one unit at a time. My assumption is that we'll change // change the selectionScript to sort the things that you've selected, and only let it select // one type of object, like units / buildings, etc. public void UpdateUI(List <SelectableUnitComponent> selectedObjects) { Debug.Log(selectedObjects.Count); if (selectedObjects.Count > 0) { if (selectedObjects[0].GetComponent <Unit>() != null) { // if unit is builder if (selectedObjects[0].GetComponent <Builder>() != null) { ButtonCache barracksButton = Instantiate(buttonPrefab, topPanel.transform).GetComponent <ButtonCache>(); barracksButton.textComponent.text = "Barracks"; if (onCallPreviewBuilding != null) { barracksButton.buttonComponent.onClick.AddListener(delegate { onCallPreviewBuilding(BuildingType.Barracks); }); } buttons.Add(barracksButton.buttonComponent); } } if (selectedObjects[0].GetComponent <Building>() != null) { // if building is barracks if (selectedObjects[0].GetComponent <Barracks>() != null) { ButtonCache meleeButton = Instantiate(buttonPrefab, topPanel.transform).GetComponent <ButtonCache>(); meleeButton.textComponent.text = "Melee"; if (onCallCreateUnit != null) { meleeButton.buttonComponent.onClick.AddListener(delegate { onCallCreateUnit(selectedObjects[0].GetComponent <ProductionBuilding>().spawnPoint.transform.position, UnitType.Melee); }); } buttons.Add(meleeButton.buttonComponent); } } if (selectedObjects[0].GetComponent <Monster>() != null) { } if (selectedObjects[0].GetComponent <Upgrade>() != null) { } } else { foreach (Button button in buttons) { Destroy(button.gameObject); } buttons.Clear(); } }
protected void EditorSetOnClickListener(ButtonCache cache) { if (null == cache || !cache.Button) { return; } var button = cache.Button; if (button is Button) { UnityExtension.SetOnClickObjectPersistantListener((Button)button, this, "OnClick", this.OnClick, cache.GameObject); } }
protected override void OnEditorSetting() { base.OnEditorSetting(); this.blindBase = new UICache(this.FindObject("Blind")); this.touchLocked = new UICache(this.FindObject("TouchLock")); this.contentBase = new UICache(this.FindObjectInChildrenWithOptional("ContentBase;")); var contentObj = this.ContentBase.GameObject; this.EditorSetOnClickListener(this.btnOk = new ButtonCache(contentObj.FindObject("BtnOk"))); this.EditorSetOnClickListener(this.btnCancel = new ButtonCache(contentObj.FindObject("BtnCancel"))); this.EditorSetOnClickListener(this.btnX = new ButtonCache(contentObj.FindObject("BtnX"))); }