将 Unity 中的 Vuforia 从版本 9 升级到版本 10 时出错

Errors when upgrading Vuforia in Unity from version 9 to version 10

The type or namespace name 'SmartTerrain' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'PositionalDeviceTracker' could not be found (are you missing a using directive or an assembly reference?)

这些错误不在版本 9 中,但在版本 10 中它们影响项目流程请帮助我

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Vuforia;
public class ARManager : MonoBehaviour
{
    public PlaneFinderBehaviour finder;
    SmartTerrain smartTerrain;
    PositionalDeviceTracker positionalDeviceTracker;
    ...........

tl;dr: 这些类型不再存在,因为不再需要它们。


我将从 Vuforia - Migration Guide for Vuforia Engine Unity Projects 开始。

一般来说,对于任何软件库,主要版本之间的事情和 API 变化并非不可能 - 事实上,这种重大变化是发布新主要版本的主要原因之一!

This page documents the changes between Vuforia Engine version 9.8 and version 10 as the API has fundamentally changed. Use this overview to learn about the native changes and for migrating your existing projects to the new API.

所以请阅读要使用的内容或 API 中的更改内容 => 必须更改您的代码才能采用 - 或坚持使用该版本9 如果它对你有用并且你不需要最新的功能 ;)

在您的具体情况下

Ground Plane

Some more advanced Ground Plane APIs have changed. Apps that were using not just the game objects above, but additional runtime scripting APIs might have to be adapted.

The Smart Terrain Tracker has been removed. It no longer needs to be managed manually. Consequently, checking for Ground Plane support at runtime has changed.

Vuforia Engine 9.8:

SmartTerrain smartTerrain = TrackerManager.Instance.GetTracker<SmartTerrain>();
if (smartTerrain == null)
    Debug.Log("SmartTerrain returned null. GroundPlane not supported on this device.");

Vuforia Engine 10.0:

if (VuforiaBehaviour.Instance.World.AnchorsSupported == false)
    Debug.Log("GroundPlane not supported on this device.");

Device Tracking

Access to device tracking has been simplified and is now available centrally through VuforiaBehaviour.Instance.DevicePoseBehaviour.

Resetting Device Tracking

Vuforia Engine 9.8:

var deviceTracker = TrackerManager.Instance.GetTracker<PositionalDeviceTracker>();
deviceTracker.Reset();

Vuforia Engine 10.0:

VuforiaBehaviour.Instance.DevicePoseBehaviour.Reset();

Registering to updates to the device tracking status

Vuforia Engine 9.8:

private void Start()
{
    DeviceTrackerARController.Instance.RegisterDevicePoseStatusChangedCallback(OnDevicePoseStatusChanged);
}
void OnDevicePoseStatusChanged(Vuforia.TrackableBehaviour.Status status, Vuforia.TrackableBehaviour.StatusInfo statusInfo)
{
    Debug.Log("OnDevicePoseStatusChanged(" + status + ", " + statusInfo + ")");

    …
}

Vuforia Engine 10.0:

private void Start()
{
    VuforiaBehaviour.Instance.DevicePoseBehaviour.OnTargetStatusChanged += OnDevicePoseStatusChanged; 
}
void OnDevicePoseStatusChanged(ObserverBehaviour behaviour, TargetStatus targetStatus)
{
    Debug.Log("OnDevicePoseStatusChanged(" + targetStatus.Status + ", " + targetStatus.StatusInfo + ")");
}

Enabling and disabling Device Tracking

Vuforia Engine 9.8:

public void ToggleDeviceTracking(bool enableDeviceTracking)
{
    var posDeviceTracker = TrackerManager.Instance.InitTracker<PositionalDeviceTracker>();
    if (enableDeviceTracking)
        posDeviceTracker.Start();
    else
        posDeviceTracker.Stop();
}

Vuforia Engine 10.0:

public void ToggleDeviceTracking(bool enableDeviceTracking)
{
    VuforiaBehaviour.Instance.DevicePoseBehaviour.enabled = enableDeviceTracking; 
    
}