说下我自身对NGUI自适应的一个做法:
1设置UIroot脚本中的Manual Height值为你UI设计时的实际高度值,Scaling Style 设置为Fixed Size。
2设置camera中Projection为Orthographic,设置size的值为1。
3创建一个脚本,写下以下函数
public readonly float StandardWith = 1136; //UI设计时的实际高度值
public readonly float StandardHeight = 640; //UI设计时的实际宽度值
public static void SetUIScale()
{
UIAnchor[] _allUIAnchor = Gameobject.FindObjectsOfType(typeof(UIAnchor))as UIAnchor[];
for(int i = 0; i < _allUIAnchor.Length; i++)
{
_allUIAchor[i].transform.localScale = new Vector3(((float)Screen.width/(float)Screen.height) / ((float)StandardWith / (float)StandardHeight),1,1);
}
}