关闭

高通AR-关于切换相机跟踪图片的控制

标签: Unity高通ar
258人阅读 评论(0) 收藏 举报
分类:
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">        当跟踪到图片,并且显示模型的时候,调用SetTrackerSwitch(false)函数,模型会保持显示,移开图片,不会对模型产生影响.此时如果调用SetTrackerSwitch(true),就会回到正常状态。</span>

    

using UnityEngine;
using System.Collections;
using Vuforia;
public class MyTrackableEventHandler : MonoBehaviour, ITrackableEventHandler
{

    #region PRIVATE_MEMBER_VARIABLES

    private TrackableBehaviour mTrackableBehaviour;
    bool _trackerSwitch = true; //作为可否跟踪的开关.

    //private ImageTargetAbstractBehaviour mImageTarget;
    #endregion // PRIVATE_MEMBER_VARIABLES



    #region UNTIY_MONOBEHAVIOUR_METHODS



    void Start()
    {
        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
        }
        //mImageTarget = GetComponent<ImageTargetAbstractBehaviour>();
    }

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS



    #region PUBLIC_METHODS
    /// <summary>
    /// 设置跟踪开关的状态
    /// </summary>
    /// <param name="sitchValue"></param>
    public void SetTrackerSwitch(bool sitchValue)
    {
        _trackerSwitch = sitchValue;
        Fix();
    }

    /// <summary>
    /// 改变跟踪开关为相反值
    /// </summary>
    public void ChangeTrackerSwitch()
    {
        _trackerSwitch = !_trackerSwitch;
        Fix();
    }

    /// <summary>
    /// 跟踪开关改变后进行的调整.
    /// </summary>
    void Fix()
    {
        if(_trackerSwitch == true)
        {
            mTrackableBehaviour.enabled = true;
            OnTrackingLost();
        }
        else
        {
            mTrackableBehaviour.enabled = false; 
        }
    }
    /// <summary>
    /// Implementation of the ITrackableEventHandler function called when the
    /// tracking state changes.
    /// </summary>
    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            OnTrackingFound();
        }
        else
        {
            OnTrackingLost();
        }
    }

    #endregion // PUBLIC_METHODS



    #region PRIVATE_METHODS


    private void OnTrackingFound()
    {
        if (_trackerSwitch == false) return;
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
        Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = true;
        }

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    }


    private void OnTrackingLost()
    {
        if (_trackerSwitch == false) return;

        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
        Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }

        // Disable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = false;
        }

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    }

    #endregion // PRIVATE_METHODS
}

0
0

猜你在找
【直播】计算机视觉原理及实战—屈教授
【套餐】深度学习入门视频课程—唐宇迪
【套餐】Hadoop生态系统零基础入门--侯勇蛟
【套餐】嵌入式Linux C编程基础--朱有鹏
【套餐】2017软考系统集成项目——任铄
【套餐】Android 5.x顶级视频课程——李宁
【直播】广义线性模型及其应用——李科
【直播】从0到1 区块链的概念到实践
【直播】机器学习之凸优化——马博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1912次
    • 积分:68
    • 等级:
    • 排名:千里之外
    • 原创:5篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档