facebook twitter hatena line email

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

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(サンプル)
(ipad判定)
(同じ利用者による、間の5版が非表示)
行10: 行10:
 
         // 縦画面 iPhone6
 
         // 縦画面 iPhone6
 
         float developAspect = 750.0f / 1334.0f;
 
         float developAspect = 750.0f / 1334.0f;
         // 横画面
+
         // 横画面 iPhone6
         float developAspect = 1334.0f / 750.0f;
+
         // float developAspect = 1334.0f / 750.0f;
 
         float deviceAspect = (float)Screen.width / (float)Screen.height;
 
         float deviceAspect = (float)Screen.width / (float)Screen.height;
 
         float scale = deviceAspect / developAspect;
 
         float scale = deviceAspect / developAspect;
行26: 行26:
  
 
参考:http://www.project-unknown.jp/entry/2017/01/05/212837
 
参考:http://www.project-unknown.jp/entry/2017/01/05/212837
 +
 +
==ipad判定==
 +
<pre>
 +
public static bool IsIPad {
 +
    get {
 +
        return SystemInfo.deviceModel.Contains ("iPad");
 +
    }
 +
}
 +
</pre>
 +
参考:http://westhillapps.blog.jp/archives/35736621.html
 +
===縦ipad判定===
 +
<pre>
 +
public static bool IsIPadDeviceAspect() {
 +
    float deviceAspect = (float)Screen.width / (float)Screen.height; // 2048 / 2732 = 0.74963397
 +
    if (deviceAspect > 0.749f && deviceAspect <= 0.751f) {
 +
        return true;
 +
    }
 +
    return false;
 +
}
 +
</pre>

2019年3月9日 (土) 04:58時点における版

サンプル

void Awake()
{
       TermSize.orthographicSizeAuto();
}

TermSize.cs

public class TermSize {
   public static void orthographicSizeAuto () {
       // 縦画面 iPhone6
       float developAspect = 750.0f / 1334.0f;
       // 横画面 iPhone6
       // 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;
    }
}

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

ipad判定

public static bool IsIPad {
    get {
        return SystemInfo.deviceModel.Contains ("iPad");
    }
}

参考:http://westhillapps.blog.jp/archives/35736621.html

縦ipad判定

public static bool IsIPadDeviceAspect() {
    float deviceAspect = (float)Screen.width / (float)Screen.height; // 2048 / 2732 = 0.74963397
    if (deviceAspect > 0.749f && deviceAspect <= 0.751f) {
        return true;
    }
    return false;
}