Unity ScalerPanelベースサイズに応じたサイズ変更
パネルのサイズを固定にして、その配下に固定で、画像やテキストを配置。
パネルのスケールを変更するのみで、比率に応じた倍率にする。
ここでは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
Author And Source
この問題について(Unity ScalerPanelベースサイズに応じたサイズ変更), 我々は、より多くの情報をここで見つけました https://qiita.com/UnityFoo/items/1bba9194e6a5f58d1539著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .