AspectRatioFixer.cs 869 B

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. using System.Collections;
  3. /// <summary>
  4. /// This component is responsible for keeping the width always the same, so that the player
  5. /// will not have more reaction time if he plays on an iPhone 5 (which is 16:9), compared
  6. /// to iPad (which is 4:3)
  7. /// </summary>
  8. public class AspectRatioFixer : MonoBehaviour
  9. {
  10. UIRoot uiRoot;
  11. private static float _scaleChange;
  12. private static int _uiManualHeight;
  13. public static float ScaleChange { get { return _scaleChange; } }
  14. public static int UIManualHeight { get { return _uiManualHeight; } }
  15. void Awake()
  16. {
  17. uiRoot = GetComponent<UIRoot>();
  18. float previousManualHeight = uiRoot.manualHeight;
  19. uiRoot.manualHeight = (int)((GameConstants.GAME_WIDTH / (float)Screen.width) * Screen.height);
  20. _scaleChange = uiRoot.manualHeight / previousManualHeight;
  21. _uiManualHeight = uiRoot.manualHeight;
  22. }
  23. }