public override void Initialize(Toolset toolSet) { base.Initialize(toolSet); affectedPartsCounter = ActiveItem.GetComponent <TextMeshPro>(); PlacementReferences.AffectedParts = startAffectedParts; affectedPartsCounter.text = PlacementReferences.AffectedParts.ToString(); }
public void UpdateUI() { /* Update health. */ if (healthPanel != null) { Image[] _hpImages = healthPanel.GetComponentsInChildren <Image>(); List <Image> hpImages = new List <Image>(_hpImages); hpImages.RemoveAt(0); if (hpImages.Count > Mathf.Ceil(maxHealth / 2f)) { int newMax = (int)Mathf.Ceil(maxHealth / 2f); Debug.Log(newMax); Debug.Log(hpImages.Count - 1); for (int i = hpImages.Count - 1; newMax <= i; i--) { Debug.Log("i: " + i); Destroy(hpImages[i].gameObject); hpImages.RemoveAt(i); } } else if (hpImages.Count < Mathf.Ceil(maxHealth / 2f)) { int newMax = (int)Mathf.Ceil(maxHealth / 2f); for (int i = hpImages.Count; i < newMax; i++) { Image hpImage = Instantiate <Image>(healthImagePrefab, healthPanel); hpImage.rectTransform.Translate( Vector2.right * i * hpImage.rectTransform.rect.width); hpImages.Add(hpImage); } } int index = 0; for (; index < health / 2; index++) { Image hpImage = hpImages[index]; hpImage.sprite = healthSprites[2]; } if (health % 2 == 1) { Image hpImage = hpImages[index++]; hpImage.sprite = healthSprites[1]; } for (; index < maxHealth / 2; index++) { Image hpImage = hpImages[index]; hpImage.sprite = healthSprites[0]; } } /* Update keys. */ if (keyText != null) { keyText.text = keyCount.ToString("00"); } /* Update bombs. */ if (bombText != null) { bombText.text = bombCount.ToString("00"); } /* Update active item. */ if (activeItemImage != null && activeItemChargeBar != null) { if (activeItem == null) { activeItemImage.gameObject.SetActive(false); activeItemChargeBar.gameObject.SetActive(false); } else { activeItemImage.gameObject.SetActive(true); activeItemImage.sprite = activeItem.GetComponent <SpriteRenderer>().sprite; if (activeItem is DiscreteActiveItem) { DiscreteActiveItem dActiveItem = activeItem as DiscreteActiveItem; activeItemChargeBar.gameObject.SetActive(true); activeItemChargeBar.maxValue = dActiveItem.maxCharge; activeItemChargeBar.wholeNumbers = true; activeItemChargeBar.value = dActiveItem.Charge; } else { activeItemChargeBar.gameObject.SetActive(false); } } } }