using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
/// <summary>
/// 创建人:
/// 创建时间:2022-2-11
/// 功能描述:判断当前手机类型,以及是否安装AR
/// </summary>
public class JudgePhoneType : MonoBehaviour
{
ARSession mARSession;
void Start()
{
}
void Update()
{
}
/// <summary>
/// 判断手机类型
/// </summary>
private void SelectPhoneType()
{
//使用unity中检测设备类型SystemInfo.deviceModel方法,这个是只读的字符串类型。如果得到的字符串开头是“iPad”那就是苹果平板,如果得到的是“iPhone”那就是苹果手机。其他就是安卓了,安卓手机类型太多,得到的字符串大多不一样
//SystemInfo.deviceModel判断设备类型
}
/// <summary>
/// 根据ARSessionState枚举类型,检测AR应用当年状态
/// </summary>
/// <returns></returns>
IEnumerator CheckSupport()
{
Debug.Log("检查设备...");
yield return ARSession.CheckAvailability();
if (ARSession.state == ARSessionState.NeedsInstall)
{
Debug.Log("设备支持AR,但需要更新");
Debug.Log("尝试更新...");
yield return ARSession.Install();
}
if (ARSession.state == ARSessionState.Ready)
{
Debug.Log("设备支持AR!");
Debug.Log("启动AR...");
mARSession.enabled = true;
}
else
{
switch (ARSession.state)
{
case ARSessionState.None:
break;
case ARSessionState.Unsupported:
Debug.Log("设备不支持AR");
break;
case ARSessionState.CheckingAvailability:
break;
case ARSessionState.NeedsInstall:
Debug.Log("更新失败");
break;
case ARSessionState.Installing:
break;
case ARSessionState.Ready:
break;
case ARSessionState.SessionInitializing:
break;
case ARSessionState.SessionTracking:
break;
default:
break;
}
// 启动非AR的替代方案
}
}
IEnumerator Install()
{
yield return ARSession.Install();
}
}
2_判断设备是否支持AR
于 2022-08-30 23:46:12 首次发布