Unity之NGUI适配

本适配需要修改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;
    }


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值