【发布时间】:2018-06-18 11:44:52
【问题描述】:
我正在 Unity Vuforia 中进行地平面项目。在最新版本的 Vuforia 中,有一个预定义的复选框,而不是导入单独的 DeployStageOnce 脚本。 我想要单独的 DeployStageOnce 脚本。我想研究它并知道它是如何工作的。我在任何地方都找不到脚本。有人有吗?还是链接? 如果有请提供。
非常感谢!
【问题讨论】:
标签: unity3d augmented-reality vuforia
我正在 Unity Vuforia 中进行地平面项目。在最新版本的 Vuforia 中,有一个预定义的复选框,而不是导入单独的 DeployStageOnce 脚本。 我想要单独的 DeployStageOnce 脚本。我想研究它并知道它是如何工作的。我在任何地方都找不到脚本。有人有吗?还是链接? 如果有请提供。
非常感谢!
【问题讨论】:
标签: unity3d augmented-reality vuforia
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;
}
}
【讨论】: