首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何阻止Vuforia的行为

如何阻止Vuforia的行为
EN

Stack Overflow用户
提问于 2017-10-29 20:55:33
回答 4查看 4.5K关注 0票数 1

我的项目中有三个场景。

第一个只是一个主菜单。

第二个是使用GoogleVR实现的虚拟现实场景

第三个是使用vuforia的AR场景。

不知道为什么,但当我开始VR场景(不是AR)时,vuforia behaviour也加载了,它改变了我的视野。

我试过了,但没起作用。这会停止相机实例,但不会停止vuforia行为。

代码语言:javascript
复制
public void stopAR(){
    if (Vuforia.CameraDevice.Instance.IsActive()) {
        Vuforia.CameraDevice.Instance.Deinit ();
        Vuforia.CameraDevice.Instance.Stop ();
        Debug.Log ("AR Stopped");
    }
}
EN

回答 4

Stack Overflow用户

发布于 2017-10-31 02:24:35

解决了我遵循这个来解决这个问题:

在我不想让Vuforia启动的主摄像头上,添加VuforiaBehavious脚本

取消选中它

好了。

票数 2
EN

Stack Overflow用户

发布于 2018-08-27 16:14:24

对于任何感兴趣的人,我找到了一种完全遵循this example来禁用此行为的方法。

你只需在你的第一个场景中将其添加到一个游戏对象中,并确保它在其他任何事情之前执行(例如,通过脚本执行顺序)。它取消订阅从SceneManagerVuforiaRuntime单例的事件方法调用,该单例将行为添加到每个场景中的每个主摄像机。一旦这样做了,它就再也不会这样做了。

统一2017.3.1p4的测试版本

代码语言:javascript
复制
using UnityEngine;
using System.Reflection;
using UnityEngine.SceneManagement;
using System;

public class StopAutoAddVuforia : MonoBehaviour
{
     private void Awake() {
         // https://forum.unity.com/threads/use-ar-camera-vuforia-core-in-individual-scene-not-entire-project.498489/
         try {
             EventInfo evSceneLoaded = typeof(SceneManager).GetEvent("sceneLoaded");
             Type tDelegate = evSceneLoaded.EventHandlerType;

             MethodInfo attachHandler = typeof(Vuforia.VuforiaRuntime).GetMethod("AttachVuforiaToMainCamera", BindingFlags.NonPublic | BindingFlags.Static);

             Delegate d = Delegate.CreateDelegate(tDelegate, attachHandler);
             SceneManager.sceneLoaded -= d as UnityEngine.Events.UnityAction<Scene, LoadSceneMode>;
         } catch (Exception e) {
             Debug.LogWarning("Cant remove the AttachVuforiaToMainCamera action. Execption:" + e.Message);
         }

         Destroy(this);
     }
 }

统一2018.2.4f1测试版本

代码语言:javascript
复制
using UnityEngine;
using System.Reflection;
using UnityEngine.SceneManagement;
using System;

 public class StopAutoAddVuforia : MonoBehaviour
 {
     private void Awake() {
         // https://forum.unity.com/threads/use-ar-camera-vuforia-core-in-individual-scene-not-entire-project.498489/
         try {
             EventInfo evSceneLoaded = typeof(SceneManager).GetEvent("sceneLoaded");
             Type tDelegate = evSceneLoaded.EventHandlerType;

             MethodInfo attachHandler = typeof(Vuforia.VuforiaRuntime).GetMethod("AttachVuforiaToMainCamera", BindingFlags.NonPublic | BindingFlags.Instance);

             Delegate d = Delegate.CreateDelegate(typeof(UnityEngine.Events.UnityAction<Scene, LoadSceneMode>), Vuforia.VuforiaRuntime.Instance, attachHandler);
             SceneManager.sceneLoaded -= d as UnityEngine.Events.UnityAction<Scene, LoadSceneMode>;
         } catch (Exception e) {
             Debug.LogError("Cant remove the AttachVuforiaToMainCamera action. Exception " + e.Message);
         }

         Destroy(this);
     }
 }
票数 1
EN

Stack Overflow用户

发布于 2018-05-29 01:08:23

代码语言:javascript
复制
using UnityEngine;
using Vuforia;

public class NoAR : MonoBehaviour
{
    public Camera camera;

    // Use this for initialization
    void Start()
    {
        if(camera.enabled)
            if (camera.GetComponent<VuforiaBehaviour>() != null)
                camera.GetComponent<VuforiaBehaviour>().enabled = false;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47000398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档