已编辑
我将我的 Unity 版本
2018.3.8f1
和 Vuforia 版本更改为8.0.10
并且它有效。但是有人知道如何在最新版本中工作吗?
我正在按照本教程在 Unity 中实现 Cloud Reco。
我的SimpleCloudHandler.cs
脚本中的错误:
错误 CS0246:找不到类型或命名空间名称“ICloudRecoEventHandler”(您是否缺少 using 指令或程序集引用?)
我的 Unity 版本是2018.3.14f1
我的 Vuforia 版本是8.1.7
我遵循教程的代码:
using Vuforia;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleCloudHandler : MonoBehaviour, ICloudRecoEventHandler
{
private CloudRecoBehaviour mCloudRecoBehaviour;
private bool mIsScanning = false;
private string mTargetMetadata = "";
public ImageTargetBehaviour ImageTargetTemplate;
public void OnInitialized(TargetFinder targetFinder) {
Debug.Log ("Cloud Reco initialized");
}
public void OnInitError(TargetFinder.InitState initError) {
Debug.Log ("Cloud Reco init error " + initError.ToString());
}
public void OnUpdateError(TargetFinder.UpdateState updateError) {
Debug.Log ("Cloud Reco update error " + updateError.ToString());
}
public void OnStateChanged(bool scanning) {
mIsScanning = scanning;
if (scanning)
{
// clear all known trackables
var tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
tracker.TargetFinder.ClearTrackables(false);
}
}
// Here we handle a cloud target recognition event
public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult) {
TargetFinder.CloudRecoSearchResult cloudRecoSearchResult =
(TargetFinder.CloudRecoSearchResult)targetSearchResult;
// do something with the target metadata
mTargetMetadata = cloudRecoSearchResult.MetaData;
// stop the target finder (i.e. stop scanning the cloud)
mCloudRecoBehaviour.CloudRecoEnabled = false;
// Build augmentation based on target
if (ImageTargetTemplate) {
// enable the new result with the same ImageTargetBehaviour:
ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
ImageTargetBehaviour imageTargetBehaviour =
(ImageTargetBehaviour)tracker.TargetFinder.EnableTracking(
targetSearchResult, ImageTargetTemplate.gameObject);
}
}
void OnGUI() {
// Display current 'scanning' status
GUI.Box (new Rect(100,100,200,50), mIsScanning ? "Scanning" : "Not scanning");
// Display metadata of latest detected cloud-target
GUI.Box (new Rect(100,200,200,50), "Metadata: " + mTargetMetadata);
// If not scanning, show button
// so that user can restart cloud scanning
if (!mIsScanning) {
if (GUI.Button(new Rect(100,300,200,50), "Restart Scanning")) {
// Restart TargetFinder
mCloudRecoBehaviour.CloudRecoEnabled = true;
}
}
}
// Start is called before the first frame update
void Start()
{
mCloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();
if (mCloudRecoBehaviour){
mCloudRecoBehaviour.RegisterEventHandler(this);
}
}
// Update is called once per frame
void Update()
{
}
}