ProportionalProgress.cs 640 B

1234567891011121314151617181920
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace Olympus
  4. {
  5. // Reveal a full-sized sliced capsule with a viewport, never resize its artwork.
  6. [ExecuteAlways, RequireComponent(typeof(Image))]
  7. public sealed class ProportionalProgress : MonoBehaviour
  8. {
  9. public RectTransform viewport, artwork;
  10. void LateUpdate()
  11. {
  12. if (!viewport || !artwork) return;
  13. var image=GetComponent<Image>();
  14. var size=image.rectTransform.rect.size;
  15. viewport.sizeDelta=new Vector2(size.x*Mathf.Clamp01(image.fillAmount),size.y);
  16. artwork.sizeDelta=size;
  17. }
  18. }
  19. }