整理了下Vuforia 7 版本对应识别功能的函数 基本上和6版本无差异
Vuforia版本获取
string vuforiaVersion = Vuforia.VuforiaUnity.GetVuforiaLibraryVersion();
string unityVersion = UnityEngine.Application.unityVersion;
UnityEngine.Debug.Log("Vuforia " + vuforiaVersion + "\nUnity " + unityVersion);
控制vuforia摄像机对应的Texture渲染
VuforiaRenderer.Instance.Pause(true);//关闭渲染 参数false开始渲染
-
TrackableSettings类主要功能
-
开启扩展追踪
-
获取当前激活识别库名称列表
-
激活指定的识别数据集
-
关闭指定识别数据集
-
动态载入识别数据集
-
卸载所有识别数据集(识别库)
-
设置同时识别Image的个数
-
设置同时识别3D物体的个数
-
代码块如下
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Vuforia;
/// <summary>
/// 追踪功能设置类
/// </summary>
public class TrackableSettings : MonoBehaviour
{
public const string Name = "TrackableSettings";
static TrackableSettings() { }
protected TrackableSettings() { }
protected static volatile TrackableSettings instance = null;
protected readonly object msyncRoot = new object();
protected static readonly object mstaticSyncRoot = new object();
public static TrackableSettings Instance
{
get
{
if (instance == null)
{
lock (mstaticSyncRoot)
{
if (instance == null) instance = new GameObject(Name).AddComponent<TrackableSettings>();
}
}
return instance;
}
}
/// <summary>
/// 识别数据集所在的文件路径
/// </summary>
private string dataSetDirectoryPath = null;
/// <summary>
/// 已经激活的识别数据集
/// </summary>
protected Dictionary<string, string> mCurrentActiveDataSets = new Dictionary<string, string>();
/// <summary>
/// 所有数据集对应的路径
/// </summary>
protected Dictionary<string, string> mCurrentAllDataSets = new Dictionary<string, string>();
/// <summary>
/// 是否使用本地内置识别库
/// </summary>
public bool bLocal = false;
/// <summary>
/// 扩展追踪是否开启
/// </summary>
protected bool mExtTrackingEnabled = false;
private void Awake()
{
//if (m_instance == null) m_instance = this;
//if (gameObject.name == "GameObject") gameObject.name = Name;
}
private void Start()
{
Initialize();
}
private void Initialize()
{
dataSetDirectoryPath = Application.persistentDataPath + "/" + "DataDirectory" + "/";
if (!Directory.Exists(dataSetDirectoryPath))
{
Directory.CreateDirectory(dataSetDirectoryPath);
}
}
/// <summary>
/// 获得扩展追踪开启状态
/// </summary>
/// <returns></returns>
public bool IsExtendedTrackingEnabled()
{
return mExtTrackingEnabled;
}
/// <summary>
/// 开启、关闭扩展追踪模式
/// </summary>
/// <param name="enableExtendedTracking">是否开启</param>
public virtual void SwitchExtendedTracking(bool enableExtendedTracking)
{
//返回可以访问当前所有跟踪的状态管理器实例。
StateManager stateManager = TrackerManager.Instance.GetStateManager();
// 我们遍历所有trackablebehaviours启动或停止扩展跟踪他们所代表的目标。
bool success = true;
foreach (var tb in stateManager.GetTrackableBehaviours())
{
if (tb is DataSetTrackableBehaviour)
{
if (tb.Trackable is ObjectTarget)
{
ObjectTarget target = tb.Trackable as ObjectTarget;
if (enableExtendedTracking)
{
success = target.StartExtendedTracking();
if (success)
Debug.Log("Successfully started Extended Tracking on Target: " + tb.TrackableName);
else
Debug.LogError("Failed to start Extended Tracking on Target: " + tb.TrackableName);
}
else
{
target.StopExtendedTracking();
}
}
}
}
mExtTrackingEnabled = success && enableExtendedTracking;
}
/// <summary>
/// 获取当前激活识别库名称列表
/// </summary>
/// <returns></returns>
public List<string> GetActiveDatasetNameList()
{
ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
List<DataSet> activeDataSets = tracker.GetActiveDataSets().ToList();
List<string> tempList = new List<string>();
for (int i = 0; i < activeDataSets.Count; i++)
{
string datasetPath = activeDataSets.ElementAt(i).Path;
Debug.Log("datasetPath:" + datasetPath);
string datasetName = datasetPath.Substring(datasetPath.LastIndexOf("/") + 1);
Debug.Log("datasetName:" + datasetName);
tempList.Add(datasetName.TrimEnd(".xml".ToCharArray()));
}
return tempList;
}
/// <summary&