层次:
ARCamera
Image target
-Canvas
首先启动Canvas不显示(很好)
找到跟踪图像目标,画布显示
但是如果跟踪图像目标丢失,画布总是显示为卡住。
我是更改脚本并看到另一个教程
所以,我是从 defaultTrackableEventHandler.cs 复制脚本到 canvas.cs
这是来自 DefaultTrackableEventHandler.cs的脚本canvas.cs
我的画布名称是“信息”(如果需要)。
/*==============================================================================
Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.
All Rights Reserved.
Confidential and Proprietary - Qualcomm Connected Experiences, Inc.
==============================================================================*/
using UnityEngine;
namespace Vuforia
{
/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
/// </summary>
public class canvas : MonoBehaviour,
ITrackableEventHandler
{
#region PRIVATE_MEMBER_VARIABLES
private TrackableBehaviour mTrackableBehaviour;
#endregion // PRIVATE_MEMBER_VARIABLES
#region UNTIY_MONOBEHAVIOUR_METHODS
void Start()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
#endregion // UNTIY_MONOBEHAVIOUR_METHODS
#region PUBLIC_METHODS
/// <summary>
/// Implementation of the ITrackableEventHandler function called when the
/// tracking state changes.
/// </summary>
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
OnTrackingFound();
}
else
{
OnTrackingLost();
}
}
#endregion // PUBLIC_METHODS
#region PRIVATE_METHODS
private void OnTrackingFound()
{
Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);
// Enable canvas objects
foreach (Canvas component in canvasComponents)
{
component.enabled = true;
}
}
private void OnTrackingLost()
{
Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);
// Disable canvas objects
foreach (Canvas component in canvasComponents)
{
component.enabled = false;
}
}
#endregion // PRIVATE_METHODS
}
}
答案 0 :(得分:2)
转到您的资产下的DefaultTrackableEventHandler.cs
- &gt; Vuforia - &GT;脚本文件夹。
你会发现两种方法,即OnTrackingFound(),OnTrackingLost()。
在OnTrackingFound()下,添加以下代码。
Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);
//Enable canvas:
foreach(Canvas component in canvasComponents)
{
component.enabled=true;
}
在OnTrackingLost()下,添加以下行
Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);
// Disable canvas:
foreach (Canvas component in canvasComponents)
{
component.enabled = false;
}
注意:确保您的Canvas必须位于项目层次结构中的ImageTarget文件夹中!
那就是它!你定了!检查一下!