在失去目标的Vuforia上消失

时间:2018-10-16 01:50:38

标签: image hide target vuforia-cloud-recognition

我有一个可以检测图像并从云中播放视频的应用程序,只要检测到目标,它就可以隐藏游戏对象并在图像上播放视频(纹理),这样就可以正常工作。但是这里的问题是,当失去图像目标时,视频不会停止,或者游戏对象没有隐藏,我不知道怎么了。你能帮我吗?

这是脚本的完整代码,我认为这可以处理隐藏和取消隐藏系统

using UnityEngine;
using Vuforia;
using UnityEngine.Video;
using UnityEngine.UI;
using System.Collections;


/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
/// 
/// Changes made to this file could be overwritten when upgrading the                     Vuforia version. 
/// When implementing custom event handler behavior, consider inheriting     from this class instead.
/// </summary>
public class DefaultTrackableEventHandler : MonoBehaviour,         ITrackableEventHandler
{
#region PROTECTED_MEMBER_VARIABLES

protected TrackableBehaviour mTrackableBehaviour;

#endregion // PROTECTED_MEMBER_VARIABLES

#region UNITY_MONOBEHAVIOUR_METHODS
public GameObject VideoPlayer_Canvas;
public VideoPlayerScript videoPlayerInstance;
public GameObject GoogleADS;
public GoogleMobileAdsDemoScript gmObj;


protected virtual void Start()
{

    mTrackableBehaviour = GetComponent<TrackableBehaviour>();
    if (mTrackableBehaviour)
        mTrackableBehaviour.RegisterTrackableEventHandler(this);
}

protected virtual void OnDestroy()
{
    if (mTrackableBehaviour)
        mTrackableBehaviour.UnregisterTrackableEventHandler(this);
}

#endregion // UNITY_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)
    {
        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
        OnTrackingFound();
    }
    else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
             newStatus == TrackableBehaviour.Status.NO_POSE)
    {
        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
        OnTrackingLost();
    }
    else
    {
        // For combo of previousStatus=UNKNOWN + newStatus=UNKNOWN|NOT_FOUND
        // Vuforia is starting, but tracking has not been lost or found yet
        // Call OnTrackingLost() to hide the augmentations
        OnTrackingLost();
    }
}

#endregion // PUBLIC_METHODS

#region PROTECTED_METHODS

protected virtual void OnTrackingFound()
{
    Debug.Log("on track ");
           var rendererComponents = GetComponentsInChildren<Renderer>(true);
            var colliderComponents = GetComponentsInChildren<Collider>(true);
            var canvasComponents = GetComponentsInChildren<Canvas>(true);

           // Enable rendering:
            foreach (var component in rendererComponents)
               component.enabled = true;

           // Enable colliders:
           foreach (var component in colliderComponents)
              component.enabled = true;

           // Enable canvas':
            foreach (var component in canvasComponents)
                component.enabled = true;
    VideoPlayer_Canvas.SetActive(true);
    videoPlayerInstance.AfterScanning();
        Video_Player.Video_Player_Inst.Video_Play_Enable();

    Debug.Log("on track fround");

}


protected virtual void OnTrackingLost()
{
    var rendererComponents = GetComponentsInChildren<Renderer>(false);
    var colliderComponents = GetComponentsInChildren<Collider>(false);
    var canvasComponents = GetComponentsInChildren<Canvas>(false);

    // Disable rendering:
    foreach (var component in rendererComponents)
        component.enabled = false;

    // Disable colliders:
    foreach (var component in colliderComponents)
        component.enabled = false;

    // Disable canvas':
    foreach (var component in canvasComponents)
        component.enabled = false;
    Video_Player.Video_Player_Inst.Video_Stop();
    VideoPlayer_Canvas.SetActive(false);
    VideoPlayer_Canvas.gameObject.GetComponent<Canvas>().enabled = false;


}

#endregion // PROTECTED_METHODS
}

0 个答案:

没有答案