答案 0 :(得分:1)
您无法设置参考分辨率,但可以使用UISclleMode:恒定像素大小来计算和设置比例因子。
void SetReferenceResolution(Vector2 m_ReferenceResolution,float m_MatchWidthOrHeight = 1f)
{
private const float kLogBase = 2;
float logWidth = Mathf.Log(screenSize.x / m_ReferenceResolution.x, kLogBase);
float logHeight = Mathf.Log(screenSize.y / m_ReferenceResolution.y, kLogBase);
float logWeightedAverage = Mathf.Lerp(logWidth, logHeight, m_MatchWidthOrHeight);
GetComponent<Canvas>().scaleFactor = Mathf.Pow(kLogBase, logWeightedAverage);
}
答案 1 :(得分:0)
就像CanvasScaler
的所有其他属性一样,您可以在脚本之类的脚本中简单地使用CanvasScaler.referenceResolution
属性
GetComponent<CanvasScaler>().referenceResolution = new Vector2(xSize, ySize);
答案 2 :(得分:0)
UI缩放模式:
Constant Pixel Size
简单模板:
public class Scale : MonoBehaviour {
public float scale = 1f; // 1 by default
public void Update()
{
GetComponent<Canvas>().scaleFactor = scale;
}
}