パネルのサイズを固定にして、その配下に固定で、画像やテキストを配置。
パネルのスケールを変更するのみで、比率に応じた倍率にする。
ここでは640x480に固定。倍率は小さい方に合わせる。画面いっぱいに黒画面などを置いて、縦の空きや横の空きをごまかす。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PanelScaler : MonoBehaviour
{
void Awake()
{
//Application.targetFrameRate=20;
ScaleChange();
}
void ScaleChange(){
const float fixed_width=640f;
const float fixed_height=480f;
var sw=Screen.width/fixed_width;
var sh=Screen.height/fixed_height;
var scale=Mathf.Min(sw,sh);
Debug.Log(scale);
gameObject.transform.localScale=new Vector3(scale,scale,1);
}
}
パッケージ
https://github.com/gnjo/UnitySamples