屏幕自适应 参考链接 屏幕适配参考
& Scaling Style(UIRoot上)
主要用Constrained设置(content width和content height)进行整体布局------Constrained On Mobiles(NGUI做好了不同的适配)
或者如果是选取了Flexiable且横屏状态下,就需要动态改变适配的高度(一般是PC端)
public class NewBehaviourScript : MonoBehaviour {
public int ManualWidth = 1280;
public int ManualHeight = 720;
void Awake () {
UIRoot uiRoot = gameObject.GetComponent<UIRoot>();
if (uiRoot != null)
{ //屏幕高宽比大于设计高宽比,即高大(有黑边),则改变高(根据宽的比来改变)!
if (System.Convert.ToSingle(Screen.height) / Screen.width > System.Convert.ToSingle(ManualHeight) / ManualWidth)
uiRoot.minimumHeight = Mathf.RoundToInt(System.Convert.ToSingle(ManualWidth) / Screen.width * Screen.height);
else
uiRoot.minimumHeight = ManualHeight;
}
}
}
//屏幕高宽比大于设计高宽比,即高大(有黑边),则改变高(根据宽的比来改变)!
if (System.Convert.ToSingle(Screen.height) / Screen.width > System.Convert.ToSingle(ManualHeight) / ManualWidth)