ReferenceViewport.cs 677 B

123456789101112131415
  1. using UnityEngine;
  2. namespace Olympus {
  3. [ExecuteAlways]
  4. public sealed class ReferenceViewport : MonoBehaviour
  5. {
  6. void LateUpdate()
  7. {
  8. var rect=(RectTransform)transform;var parent=rect.parent as RectTransform;if(!parent)return;
  9. float keyboard=Application.isPlaying&&TouchScreenKeyboard.visible?TouchScreenKeyboard.area.height/Mathf.Max(1,Screen.height)*parent.rect.height:0;
  10. float height=Mathf.Max(400,parent.rect.height-keyboard);
  11. float scale=Mathf.Min(parent.rect.width/750,height/1334);
  12. rect.localScale=Vector3.one*scale;rect.anchoredPosition=new Vector2(0,keyboard*.5f);
  13. }
  14. }
  15. }