本适配需要修改UIRoot源码,Maximum为960
public void UpdateScale (bool updateAnchors = true)
{
if (mTrans != null)
{
float calcActiveHeight = activeHeight;
if (calcActiveHeight > 0f)
{
float scale = GetScreenScale();
if( scale > 1f )
{
scale = 1f;
}
float size = 2f / calcActiveHeight;
size = size * scale;
Vector3 ls = mTrans.localScale;
if (!(Mathf.Abs(ls.x - size) <= float.Epsilon) ||
!(Mathf.Abs(ls.y - size) <= float.Epsilon) ||
!(Mathf.Abs(ls.z - size) <= float.Epsilon))
{
mTrans.localScale = new Vector3(size, size, size);
if (updateAnchors) BroadcastMessage("UpdateAnchors");
}
}
}
}
protected float GetScreenScale()
{
Vector3 screenSize = GetScreenSize();
float rateNow = screenSize.x / screenSize.y;
float rateOrg = 960f / 640f;
return rateOrg / rateNow;
}
protected Vector3 GetScreenSize()
{
Camera cam = UICamera.mainCamera;
Transform root = mTrans;
Vector3 vSize = new Vector3( 960f, 640f, 0.0f );
Vector3 vCache = vSize;
vSize.x *= root.localScale.x;
vSize.y *= root.localScale.y;
vSize = cam.WorldToScreenPoint( vSize );
vSize.x = vCache.x * vCache.x / 960 * Screen.width / ( vSize.x - Screen.width * 0.5f );
vSize.y = vCache.y * vCache.y / 640 * Screen.height / ( vSize.y - Screen.height * 0.5f );
return vSize;
}