我检查了unity的不同版本,它可以与安装在另一台笔记本电脑上的Unity 2018.2.6f1 Personal一起使用。但是我有Unity 2018.2.12f1 Personal,它给出了错误。这是一个统一的错误吗?
TargetSearchResult cloud-image-name无法启用跟踪。 UnityEngine.Debug:LogError(Object) Vuforia.TargetFinder:EnableTracking(TargetSearchResult,GameObject) CloudRec:OnNewSearchResult(TargetSearchResult)(在 资产/脚本/CloudRec.cs:66) Vuforia.ObjectRecoBehaviour:Update()
以上错误指示以下行为问题:
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)m_ObjectTracker.TargetFinder.EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);
技术版本:
Vuforia版本:7.5.20 | Unity 2018.2.12f1个人版
完整代码在这里:
public class CloudRec : MonoBehaviour, ICloudRecoEventHandler
{
private CloudRecoBehaviour mCloudRecoBehaviour;
private bool mIsScanning = false;
private string mTargetMetadata = "";
public ImageTargetBehaviour ImageTargetTemplate;
ObjectTracker m_ObjectTracker;
TargetFinder m_TargetFinder;
// Use this for initialization
void Start()
{
// register this event handler at the cloud reco behaviour
mCloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();
if (mCloudRecoBehaviour)
{
mCloudRecoBehaviour.RegisterEventHandler(this);
}
}
public void OnInitialized()
{
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
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
ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
tracker.TargetFinder.ClearTrackables(false);
}
}
// Here we handle a cloud target recognition event
public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
{
GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;
GameObject augmentation = null;
if (augmentation != null)
augmentation.transform.SetParent(newImageTarget.transform);
if (ImageTargetTemplate)
{
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)m_ObjectTracker.TargetFinder.EnableTracking(targetSearchResult, ImageTargetTemplate.gameObject);
//ImageTracker imageTracker = TrackerManager.Instance.GetTracker<ImageTracker>();
//ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)imageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);
}
if (mIsScanning)
{
mCloudRecoBehaviour.CloudRecoEnabled = true;
}
}
// Update is called once per frame
void Update()
{
}
public void OnInitialized(TargetFinder targetFinder)
{
m_ObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
m_TargetFinder = targetFinder;
}
}
答案 0 :(得分:1)
经过将近一周的搜索,我得到了错误原因。统一运行时会发生错误,但是当我构建到 Android 或 iOS 时,它运行正常。因此,我对代码的怀疑仍然存在,我不得不开箱即用。我决定在同一台机器上测试unity和vuforia的各种版本。克服错误无济于事。最后,我在其他机器上进行了测试,并得到了错误原因。这是因为硬件兼容性。
就我而言,我正在使用不支持ObjectTracking
的 mac pro-2009 mid ,但是我在 MacBook Air上使用了相同的代码和相同版本的技术进行了测试2017 和 Mac Pro 2014年中,一切正常。因此,我将其归结为硬件兼容性问题!