Unity_AR_Vuforia实现识别图视频播放

1.右键 创建imageTarget

Unity_AR_Vuforia实现识别图视频播放_第1张图片

2.在 imageTarget下 创建一个

Unity_AR_Vuforia实现识别图视频播放_第2张图片

3.给 Quad 添加一个 Video Player 

Unity_AR_Vuforia实现识别图视频播放_第3张图片

4.把 视频拖拽到 Video Player上

Unity_AR_Vuforia实现识别图视频播放_第4张图片

实现 识别到了 播放   识别丢失暂停

复制一份 Default Trackable Event Handler 里的代码

创建一个新的脚本 命名为 VideoImageTarget

将复制的 代码 粘贴到 VideoImageTarget 类里面

注意修改类名

需要添加到代码如下:

   //识别到了时
     protected virtual void OnTrackingFound()
    {
        var rendererComponents = GetComponentsInChildren(true);
        var colliderComponents = GetComponentsInChildren(true);
        var canvasComponents = GetComponentsInChildren(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 使视频播放
        GetComponentInChildren().Play();
    }

//识别丢失时
    protected virtual void OnTrackingLost()
    {
        var rendererComponents = GetComponentsInChildren(true);
        var colliderComponents = GetComponentsInChildren(true);
        var canvasComponents = GetComponentsInChildren(true);

        // 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;
        //获取子物体的VideoPlayer 使视频暂停
        GetComponentInChildren().Pause();
    }

 

你可能感兴趣的:(AR,Unity3D)