2_判断设备是否支持AR

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();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值