facebook twitter hatena line email

「Unity/端末サイズ」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「 void Awake() { // 縦画面 iPhone6 float developAspect = 750.0f / 1334.0f; // 横画面 float developAspect = 1334.0f / 750.0f; float deviceAspect...」)
 
行1: 行1:
 +
==サンプル==
 +
void Awake()
 +
{
 +
        TermSize.orthographicSizeAuto();
 +
}
  
  void Awake() {
+
TermSize.cs
    // 縦画面 iPhone6
+
  public class TermSize {
    float developAspect = 750.0f / 1334.0f;
+
    public static void orthographicSizeAuto () {
    // 横画面
+
        // 縦画面 iPhone6
    float developAspect = 1334.0f / 750.0f;
+
        float developAspect = 750.0f / 1334.0f;
    float deviceAspect = (float)Screen.width / (float)Screen.height;
+
        // 横画面
    float scale = deviceAspect / developAspect;
+
        float developAspect = 1334.0f / 750.0f;
    Camera mainCamera = Camera.main;
+
        float deviceAspect = (float)Screen.width / (float)Screen.height;
    float deviceSize = mainCamera.orthographicSize;
+
        float scale = deviceAspect / developAspect;
    float deviceScale = 1.0f / scale;
+
        Camera mainCamera = Camera.main;
    mainCamera.orthographicSize = deviceSize * deviceScale;
+
        float deviceSize = mainCamera.orthographicSize;
 +
        float deviceScale = 1.0f / scale;
 +
        mainCamera.orthographicSize = deviceSize * deviceScale;
 +
    }
 
  }
 
  }
  
 
参考:http://www.project-unknown.jp/entry/2017/01/05/212837
 
参考:http://www.project-unknown.jp/entry/2017/01/05/212837

2018年9月29日 (土) 02:21時点における版

サンプル

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;
       mainCamera.orthographicSize = deviceSize * deviceScale;
    }
}

参考:http://www.project-unknown.jp/entry/2017/01/05/212837