我的项目中有三个场景。
第一个只是一个主菜单。
第二个是使用GoogleVR实现的虚拟现实场景
第三个是使用vuforia的AR场景。
不知道为什么,但当我开始VR场景(不是AR)时,vuforia behaviour也加载了,它改变了我的视野。
我试过了,但没起作用。这会停止相机实例,但不会停止vuforia行为。
public void stopAR(){
if (Vuforia.CameraDevice.Instance.IsActive()) {
Vuforia.CameraDevice.Instance.Deinit ();
Vuforia.CameraDevice.Instance.Stop ();
Debug.Log ("AR Stopped");
}
}发布于 2017-10-31 02:24:35
解决了我遵循这个来解决这个问题:
在我不想让Vuforia启动的主摄像头上,添加VuforiaBehavious脚本
取消选中它
好了。
发布于 2018-08-27 16:14:24
对于任何感兴趣的人,我找到了一种完全遵循this example来禁用此行为的方法。
你只需在你的第一个场景中将其添加到一个游戏对象中,并确保它在其他任何事情之前执行(例如,通过脚本执行顺序)。它取消订阅从SceneManager到VuforiaRuntime单例的事件方法调用,该单例将行为添加到每个场景中的每个主摄像机。一旦这样做了,它就再也不会这样做了。
统一2017.3.1p4的测试版本
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的测试版本
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);
}
}发布于 2018-05-29 01:08:23
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;
}
}https://stackoverflow.com/questions/47000398
复制相似问题