不做分享使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
/// <summary> /// Screen adjust. /// GameScene分辨率适配 /// </summary> using UnityEngine; using System.Collections; public class ScreenAdjust : MonoBehaviour { float width = 0f; float height = 0f; float widthRatio = 0f; float heightRatio = 0f; void Awake (){ width = Screen.width; height = Screen.height; widthRatio = width/1800; heightRatio = height/1080; if (widthRatio > heightRatio){ float temp1 = widthRatio/heightRatio; transform.localScale = new Vector3 (temp1, 1, 1); transform.position = new Vector3(-0.377f, transform.position.y,transform.position.z); } else if (widthRatio < heightRatio){ float temp2 = heightRatio/widthRatio; transform.localScale = new Vector3 (1/temp2, 1, 1); if (width > height) transform.position = new Vector3(-0.377f, transform.position.y,transform.position.z); else if (width < height) transform.position = new Vector3(-0.15f, transform.position.y,transform.position.z); } else if (widthRatio == heightRatio){ transform.localScale = new Vector3 (1, 1, 1); transform.position = new Vector3(-0.377f, transform.position.y,transform.position.z); } } } |
- 本文固定链接: http://www.u3d8.com/?p=172
- 转载请注明: 网虫虫 在 u3d8.com 发表过