AR Foudation案例解析(三) ------ Check Support(主要检查是否安装了ARCore)

本文解析了Unity中ARFoundation的ARSession状态检查与ARCore安装流程。通过检查AR支持状态,确保设备能够正确运行AR应用。代码示例展示了如何在不同状态下进行处理,包括尝试安装、启动AR会话及提供非AR体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.环境

案例网址 : https://github.com/Unity-Technologies/arfoundation-samples.git
官方文档网址 : https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@2.2/api/UnityEngine.XR.ARFoundation.html
Unity版本 : 2019.3.0
SDK版本 :

17787668-48fcee3a953d8786.png

二.案例解析

1.功能

这个示例显示了如何在启用ARSession之前检查AR支持。 特别是对于ARCore,设备可以支持ARCore,但不能安装它。此示例将检测此情况并提示用户安装ARCore。要自己测试此功能,请使用支持的设备并卸载ARCore。(设置>搜索“ARCore”并卸载或禁用它。)

2.代码解析

检查代码如下 :

 IEnumerator CheckSupport()
    {
        SetInstallButtonActive(false);

        Log("Checking for AR support...");

        yield return ARSession.CheckAvailability();

        if (ARSession.state == ARSessionState.NeedsInstall)
        {
            Log("Your device supports AR, but requires a software update.");
            Log("Attempting install...");
            yield return ARSession.Install();
        }

        if (ARSession.state == ARSessionState.Ready)
        {
            Log("Your device supports AR!");
            Log("Starting AR session...");

            // To start the ARSession, we just need to enable it.
            m_Session.enabled = true;
        }
        else
        {
            switch (ARSession.state)
            {
                case ARSessionState.Unsupported:
                    Log("Your device does not support AR.");
                    break;
                case ARSessionState.NeedsInstall:
                    Log("The software update failed, or you declined the update.");

                    // In this case, we enable a button which allows the user
                    // to try again in the event they decline the update the first time.
                    SetInstallButtonActive(true);
                    break;
            }

            Log("\n[Start non-AR experience instead]");

            //
            // Start a non-AR fallback experience here...
            //
        }
    }

安装arcore代码如下 :

  IEnumerator Install()
    {
        SetInstallButtonActive(false);

        if (ARSession.state == ARSessionState.NeedsInstall)
        {
            Log("Attempting install...");
            yield return ARSession.Install();

            if (ARSession.state == ARSessionState.NeedsInstall)
            {
                Log("The software update failed, or you declined the update.");
                SetInstallButtonActive(true);
            }
            else if (ARSession.state == ARSessionState.Ready)
            {
                Log("Success! Starting AR session...");
                m_Session.enabled = true;
            }
        }
        else
        {
            Log("Error: ARSession does not require install.");
        }
    }

其实主要是ARSessionState属性,翻译如下 :

名称描述
CheckingAvailability系统正在检查AR的可用性。 。
Installing正在安装AR软件。 。
NeedsInstallAR受支持,但需要额外安装。 。
NoneAR系统尚未初始化。可用性未知。 。
ReadyAR已得到支持并准备就绪。
SessionInitializingAR会话正在初始化(即,启动)。这通常意味着AR正在运行,但尚未收集有关环境的足够信息。
SessionTrackingAR会话正在运行并且正在跟踪(即,设备能够确定其在世界中的位置和方向)。
Unsupported当前设备不支持AR。
17787668-4eca4da34eb71a37.png
课程介绍 本套课程从技术理念到项目实践,教大家系统掌握ARKit技术开发,随心打造iOS端AR增强现实应用。由一开始的开发环境搭建,到Unity ARKit Plugin、ARFoundation ARKit等不同时期技术的讲解。从平面模型放置、识别图片、手势交互、3D物体识别、面部AR贴纸、光照估计、环境探针、多人AR技术,甚至包含ARKit3.0的动作捕捉技术等。除了以上课程内容,更加入了随着技术更新与时俱进更新的ARKit连载技术教学内容。课程收益 轻松理解ARKit的技术原理,从零到一创建自己的第一个AR项目。学习UnityARKit Plugin经典技术,了解ARKit中的常见概念和原理。学会在 ARFoundation 中使用ARKit,进行企业级AR项目开发。学会如何在AR项目里播放模型动画,通过触屏手势交互实现模型的旋转和缩放。 了解ARKit的图片识别,掌握AR卡片、AR书籍的实现方法。 学会使用面部增强技术,实现热门短视频应用的AR贴纸效果,实现面部表情追踪。学会使用ARKit物体检测技术,实现3D物体识别,可以广泛应用于工业、建筑、古董、玩具手办、艺展览等不同场景。学习ARKit中的经典交互案例,优化AR项目的用户体验。熟练使用环境纹理、光照估计技术,让AR内容随当前现实场景自动变化调节,看起来更加真实。基于WorldMap、CollaborativeSession AR技术,实现AR场景的持久化及多人AR体验效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千喜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值