我正在Unity Vuforia的Ground Plane项目上工作。在最新版本的Vuforia中,有一个预定义的复选框,而不是导入单独的DeployStageOnce脚本。 我想要单独的DeployStageOnce脚本。我想研究它并知道它是如何工作的。我无法在任何地方找到脚本。有人有吗?还是一个链接? 如果你有,请提供。
非常感谢!
答案 0 :(得分:0)
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;
}
}