UIFitLayout.cs 548 B

1234567891011121314151617
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace DevilLink2.UI
  4. {
  5. public sealed class UIFitLayout : MonoBehaviour
  6. {
  7. private void LateUpdate() { Apply(); }
  8. public void Apply()
  9. {
  10. var rect = (RectTransform)transform; var parent = transform.parent as RectTransform;
  11. if (!parent) return;
  12. rect.sizeDelta = new Vector2(ScreenLayout.Width, ScreenLayout.Height);
  13. rect.localScale = Vector3.one * ScreenLayout.FitScale(parent.rect.width, parent.rect.height);
  14. }
  15. }
  16. }