「Unity/端末サイズ」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→サンプル) |
|||
行17: | 行17: | ||
float deviceSize = mainCamera.orthographicSize; | float deviceSize = mainCamera.orthographicSize; | ||
float deviceScale = 1.0f / scale; | float deviceScale = 1.0f / scale; | ||
+ | if (scale > 1) { | ||
+ | Debug.Log("scale変更不要"); | ||
+ | return; | ||
+ | } | ||
mainCamera.orthographicSize = deviceSize * deviceScale; | mainCamera.orthographicSize = deviceSize * deviceScale; | ||
} | } |
2018年10月2日 (火) 02:35時点における版
サンプル
void Awake() { TermSize.orthographicSizeAuto(); }
TermSize.cs
public class TermSize { public static void orthographicSizeAuto () { // 縦画面 iPhone6 float developAspect = 750.0f / 1334.0f; // 横画面 float developAspect = 1334.0f / 750.0f; float deviceAspect = (float)Screen.width / (float)Screen.height; float scale = deviceAspect / developAspect; Camera mainCamera = Camera.main; float deviceSize = mainCamera.orthographicSize; float deviceScale = 1.0f / scale; if (scale > 1) { Debug.Log("scale変更不要"); return; } mainCamera.orthographicSize = deviceSize * deviceScale; } }