private void OnUnitProduced(Type product, IInfoPanelElement entity) { if (UnitProduced != null) { UnitProduced(this, (ProductionBuildingModel)entity, product); } }
public void SetEntity(IInfoPanelElement entity) { clearButtons(); if (entity == null) { this.gameObject.SetActive(false); } else { this.gameObject.SetActive(true); _entityLabel.text = entity.GetInfoTitle(); _entityImage.sprite = entity.GetThumbnailImage(); var imageRectTransform = _entityImage.GetComponent <RectTransform>(); //imageRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _entityImage.sprite.rect.width); //imageRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _entityImage.sprite.rect.height); _productionPanel.gameObject.SetActive(entity.HasProduction()); if (entity.HasProduction()) { _productionButtons = new List <Button>(); foreach (var product in entity.GetProductList()) { var go = Instantiate(_productEntryPrefab); var rt = go.GetComponent <RectTransform>(); rt.SetParent(_productionPanel, false); var imageGO = go.transform.Find("Image"); // Getting name by removing "Model" from the typename. // Again, no error check. var sprite = ResourcesManager.Instance.GetSprite(product.Name.Substring(0, product.Name.Length - 5)); imageGO.GetComponent <Image>().sprite = sprite; var button = go.GetComponent <Button>(); //rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, sprite.rect.width); //rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, sprite.rect.height); Type type = product; button.onClick.AddListener(() => { if (UnitProduced != null) { UnitProduced(type, entity); } EventSystem.current.SetSelectedGameObject(null); }); _productionButtons.Add(button); } } } }