Unity3d GUI适应分辨率

float sourceWidth = 1024f;
    float sourceHeight = 768f;
    float m_fScaleWidth;
    float m_fScaleHeight;

    void OnGUI()
    {
        m_fScaleWidth = Screen.width / sourceWidth;
        m_fScaleHeight = Screen.height / sourceHeight;
        GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity,new Vector3(m_fScaleWidth, m_fScaleHeight, 1));

        GUI.Button(new Rect(0, 0, 1024, 768), "");
    }

猜你喜欢

转载自www.cnblogs.com/ldxsuanfa/p/10713104.html