RootPanelScaler.cs 665 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. using System.Collections;
  3. public class RootPanelScaler : MonoBehaviour {
  4. public const int ORIGIN_WIDTH = 560;
  5. public const int ORIGIN_HEIGHT = 420;
  6. public const int ORIGIN_BATTLE_HEIGHT = 480;
  7. // Use this for initialization
  8. void Awake ()
  9. {
  10. float height = 0;
  11. if(GameObject.FindObjectOfType<BattleController>() != null)
  12. height = ORIGIN_BATTLE_HEIGHT;
  13. else
  14. height = ORIGIN_HEIGHT;
  15. float s = (float)Screen.height/height;
  16. RectTransform rectTrans = GetComponent<RectTransform>();
  17. rectTrans.localScale = new Vector3(s, s, 1f);
  18. float width = Screen.width/s;
  19. rectTrans.sizeDelta = new Vector2(width, height);
  20. }
  21. }