unity 根据平板 或者 手机 确立横竖屏

/*              #########                       
              ############                     
              #############                    
             ##  ###########                   
            ###  ###### #####                  
            ### #######   ####                 
           ###  ########## ####                
          ####  ########### ####               
         ####   ###########  #####             
        #####   ### ########   #####           
       #####   ###   ########   ######         
      ######   ###  ###########   ######       
     ######   #### ##############  ######      
    #######  #####################  ######     
    #######  ######################  ######    
   #######  ###### #################  ######   
   #######  ###### ###### #########   ######   
   #######    ##  ######   ######     ######   
   #######        ######    #####     #####    
    ######        #####     #####     ####     
     #####        ####      #####     ###      
      #####       ###        ###      #        
        ###       ###        ###              
         ##       ###        ###               
__________#_______####_______####______________
    身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
                我们的未来没有BUG           
* ==============================================================================
* Filename: Txt 
* Created:  2019
* Author:   Light
* Purpose:  
* ==============================================================================
*/

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.iOS;

public class Txt : MonoBehaviour
{
    public Text text;

    void Start()
    {

#if UNITY_ANDROID
        float physicscreen = Mathf.Sqrt(Screen.width * Screen.width + Screen.height * Screen.height) / Screen.dpi;
        if (physicscreen >= 7f)
        {
            Debug.Log("安卓平板");
            text.text = "安卓平板";
            Screen.orientation = ScreenOrientation.Landscape;
        }
        else
        {
            Debug.Log("安卓手机");
            text.text = "安卓手机";
            Screen.orientation = ScreenOrientation.PortraitUpsideDown;
        }
#elif UNITY_IPHONE
        string iP_genneration = Device.generation.ToString();
        if (iP_genneration.Substring(0, 3) == "iPa")
        {
            Debug.Log("苹果平板");
            text.text = "苹果平板";
        }
        else
        {
            Debug.Log("苹果手机");
            text.text = "苹果手机";
        }
#endif

    }


}

 

posted @ 2019-03-08 10:21  一只默默奮鬥的程序菌  阅读(564)  评论(0编辑  收藏  举报