超全的Unity提供安卓开发相关的API

一:屏幕相关操作

类:Screen

属性Screen.height     //屏幕高度

           Screen.width      //屏幕宽度

           Screen.currentResolution  //屏幕分辨率

           Screen.dpi         //屏幕DPI

           Screen.fullScreen    //是否全屏

           Screen.orientation        //屏幕旋转(可以自己设置)

           Screen.sleepTimeout    //屏幕的休眠时间(仅支持移动平台)、

类:Input

属性:Input.touchSupported        //是否支持触摸

           Input.multiTouchEnabled   //是否支持多点触摸

           Input.stylusTouchSupported        //是否支持笔触

           Input.touchPressureSupported        //是否支持压感

           Input.mousePresent        //是否支持鼠标

           Input.anyKey        //任意键按下

二,获取系统信息

类:Input

属性:Input.compass.rawVector        //获取电子罗盘

           Input.gyro.gravity        //获取陀螺仪

           Input.location.status        //获取位置服务

           Input.devicOrientation        //获取设备方向

类:Application

属性:Application.systemLanguage        //获取系统语言

三,获取手机电池的状态

1.电量信息 0—1        0:没电        1:满电

float batteryLevel = SystemInfo.batteryLevel

2.电池状态

//UnKnown 未识别状态

//Charging 正在充电

//Discharging 没有插线也没有充电

//NotCharging 插着线,没充电

//Full 电量满了

BatteryStatus batteryStatus = SystemInfo.batteryStatus

四,系统的返回键

Input.GetKeyDown(KeyCode.Escape)        //Unity提供的返回键

Input.backButtonLeavesApp                // 把返回键的授权还给系统

五,在Unity中申请调用相机的权限

携程函数:
 

IEnumerator  DeviceCameraPlay()

{

        //申请调用相机的权限

        yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);

        //是否拥有了权限

        if(Application.HasUserAuthorization(UserAuthorzation(UserAuthorization.WebCam)))

        {

                //获取设备个数

                if(WenCamTexture.devices.Length>0)

                {

                        //获取设备的名字

                        string devicesName = WebCamTexture.devices[0].name;     

                        //创建相机贴图

                        WebCamTexture webCamTexture =new WebCamTeture(devicesName,Screen.width,Screen.height);  

                        //显示相机画面

                        camShow.texture = webCamTexture;

                        //启用相机

                        webCamTexture.Play();

                }

                else

                {

                        Debug.Log(“设备没有相机”);

                }

        }

}

猜你喜欢

转载自blog.csdn.net/lel18570471704/article/details/119478903