我正在尝试正确获取trackingState但我没有得到“Hook ARFrameUpdatedEvent”的含义而是 UnityARCamera.trackingState“......我该怎么做?
提前谢谢。
[Obsolete("Hook ARFrameUpdatedEvent instead and get
UnityARCamera.trackingState")]
public int GetARTrackingQuality()
{
return GetTrackingQuality();
}
答案 0 :(得分:1)
您可以通过注册以下delegate
回调来获取跟踪状态,例如:
void Start ()
{
//1. Register For The ARFrame Updated Event
UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
UnityARSessionNativeInterface.ARSessionFailedEvent += ARSessionFailedEvent;
}
然后你会创建函数来处理回调,例如:
/// <summary>
/// Called Each Time The ARCamera Is Updated
/// </summary>
/// <param name="camera">Camera.</param>
public void ARFrameUpdated (UnityARCamera camera)
{
//1. Track The ARSession
if (camera.trackingState == ARTrackingState.ARTrackingStateLimited) {
logTrackingReason (camera.trackingReason);
} else {
logTrackingState (camera.trackingState);
}
logLighting (camera.lightData.arLightEstimate.ambientIntensity);
}
/// <summary>
/// Determines If The Current Lighting Conditions Are Appropriate For The ARSession
/// </summary>
/// <param name="lightEstimate">Light estimate.</param>
public void logLighting (float lightEstimate)
{
if (lightEstimate < 100) {
arTrackingStatus = "Lighting Is To Dark";
}
}
/// <summary>
/// Informs The User About The Current Tracking State
/// </summary>
/// <param name="trackingState">Tracking state.</param>
public void logTrackingState (ARTrackingState trackingState)
{
switch (trackingState) {
case ARTrackingState.ARTrackingStateNormal:
arTrackingStatus = "Tracking Ready";
break;
case ARTrackingState.ARTrackingStateNotAvailable:
arTrackingStatus = "Tracking Unavailable";
break;
}
}
/// <summary>
/// Informs The User About The Current Tracking Status
/// </summary>
/// <param name="reason">Reason.</param>
public void logTrackingReason (ARTrackingStateReason reason)
{
switch (reason) {
case ARTrackingStateReason.ARTrackingStateReasonExcessiveMotion:
arTrackingStatus = "Please Slow Your Movement";
break;
case ARTrackingStateReason.ARTrackingStateReasonInsufficientFeatures:
arTrackingStatus = "Try To Point At A Flat Surface";
break;
case ARTrackingStateReason.ARTrackingStateReasonInitializing:
arTrackingStatus = "Initializing";
break;
}
}
/// <summary>
/// Prints The ARSession Failed Event
/// </summary>
/// <param name="error">Error.</param>
public void ARSessionFailedEvent (string error)
{
print (error);
}
完成此操作后,您可以在Update方法中处理这些内容,如下所示:
void Update ()
{
print (arTrackingStatus);
}
希望它有所帮助...