LoginSignup
0
1

More than 1 year has passed since last update.

Unity ScalerPanelベースサイズに応じたサイズ変更

Last updated at Posted at 2021-09-14

パネルのサイズを固定にして、その配下に固定で、画像やテキストを配置。

パネルのスケールを変更するのみで、比率に応じた倍率にする。
ここでは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
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1