【问题标题】:DeployStageOnce Script for Vuforia Unity用于 Vuforia Unity 的 DeployStageOnce 脚本
【发布时间】:2018-06-18 11:44:52
【问题描述】:

我正在 Unity Vuforia 中进行地平面项目。在最新版本的 Vuforia 中,有一个预定义的复选框,而不是导入单独的 DeployStageOnce 脚本。 我想要单独的 DeployStageOnce 脚本。我想研究它并知道它是如何工作的。我在任何地方都找不到脚本。有人有吗?还是链接? 如果有请提供。

非常感谢!

【问题讨论】:

    标签: unity3d augmented-reality vuforia


    【解决方案1】:
    using System;
    using UnityEngine;
    using Vuforia;
    public class DeployStageOnce : MonoBehaviour {
    
        public GameObject AnchorStage;
        private PositionalDeviceTracker _deviceTracker;
        private GameObject _previousAnchor;
    
        public void Start ()
        {
            if (AnchorStage == null)
            {
                Debug.Log("AnchorStage must be specified");
                return;
            }
            AnchorStage.SetActive(false);
        }
        public void Awake()
        {
            VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
        }
        public void OnDestroy()
        {
            VuforiaARController.Instance.UnregisterVuforiaStartedCallback(OnVuforiaStarted);
        }
        private void OnVuforiaStarted()
        {
            _deviceTracker = TrackerManager.Instance.GetTracker<PositionalDeviceTracker>();
        }
        public void OnInteractiveHitTest(HitTestResult result)
        {
            if (result == null || AnchorStage == null)
            {
                Debug.LogWarning("Hit test is invalid or AnchorStage not set");
                return;
            }
            var anchor = _deviceTracker.CreatePlaneAnchor(Guid.NewGuid().ToString(), result);
            if (anchor != null)
            {
                AnchorStage.transform.parent = anchor.transform;
                AnchorStage.transform.localPosition = Vector3.zero;
                AnchorStage.transform.localRotation = Quaternion.identity;
                AnchorStage.SetActive(true);
            }
            if (_previousAnchor != null)
            {
                Destroy(_previousAnchor);
            }
            _previousAnchor = anchor;
        }
    }
    

    【讨论】:

    • 你是如何提取代码的?有没有办法可以提取和研究 vuforia Unity 中的其他代码?
    猜你喜欢
    • 2017-05-27
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多