C# 如何阻止Vuforia行为
我的项目中有三个场景 第一个只是主菜单 第二个是使用GoogleVR的虚拟现实场景 第三个是使用vuforia的AR场景 不知道为什么,但当我启动VR场景(不是AR)时,vuforia Behavior也被加载,它改变了我的视野 有一种方法可以防止vuforia在加载应用程序时启动,而在加载AR场景时才启动 我试过了,但没有成功。这会停止摄影机实例,但不会停止vuforia行为C# 如何阻止Vuforia行为,c#,unity3d,augmented-reality,vuforia,C#,Unity3d,Augmented Reality,Vuforia,我的项目中有三个场景 第一个只是主菜单 第二个是使用GoogleVR的虚拟现实场景 第三个是使用vuforia的AR场景 不知道为什么,但当我启动VR场景(不是AR)时,vuforia Behavior也被加载,它改变了我的视野 有一种方法可以防止vuforia在加载应用程序时启动,而在加载AR场景时才启动 我试过了,但没有成功。这会停止摄影机实例,但不会停止vuforia行为 public void stopAR(){ if (Vuforia.CameraDevice.Instance
public void stopAR(){
if (Vuforia.CameraDevice.Instance.IsActive()) {
Vuforia.CameraDevice.Instance.Deinit ();
Vuforia.CameraDevice.Instance.Stop ();
Debug.Log ("AR Stopped");
}
}
[已解决]
我遵循这个方法来解决这个问题:
在我不希望Vuforia启动的主摄像头上,添加VuforiaBehavious脚本
取消选中它
完成。使用UnityEngine;
使用Vuforia;
公共类NoAR:单一行为
{
公共摄像机;
//用于初始化
void Start()
{
如果(照相机已启用)
if(camera.GetComponent()!=null)
camera.GetComponent().enabled=false;
}
}
对于任何感兴趣的人,我找到了一种完全按照以下方式禁用此行为的方法
您只需将其添加到第一个场景中的游戏对象中,并确保它在执行任何其他操作之前执行(例如,通过脚本执行顺序)。它取消订阅从的事件方法调用到向每个场景中的每个主摄影机添加行为的单例。一旦这样做了,它就不应该再这样做了
Unity 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);
}
}
使用UnityEngine;
运用系统反思;
使用UnityEngine.SceneManagement;
使用制度;
公共类StopAutoAddVuforia:MonoBehavior
{
私人空间{
// https://forum.unity.com/threads/use-ar-camera-vuforia-core-in-individual-scene-not-entire-project.498489/
试一试{
EventInfo evSceneLoaded=typeof(SceneManager).GetEvent(“sceneLoaded”);
类型tDelegate=evSceneLoaded.EventHandlerType;
MethodInfo attachHandler=typeof(Vuforia.VuforiaRuntime).GetMethod(“AttachVuforiaAtomainCamera”,BindingFlags.NonPublic | BindingFlags.Static);
Delegate d=Delegate.CreateDelegate(tDelegate,attachHandler);
SceneManager.sceneLoaded-=d作为UnityEngine.Events.UnityAction;
}捕获(例外e){
Debug.LogWarning(“无法删除附件VUFORIATOMAINCAMERA操作。执行选项:”+e.Message);
}
摧毁(这个);
}
}
Unity 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);
}
}
使用UnityEngine;
运用系统反思;
使用UnityEngine.SceneManagement;
使用制度;
公共类StopAutoAddVuforia:MonoBehavior
{
私人空间{
// https://forum.unity.com/threads/use-ar-camera-vuforia-core-in-individual-scene-not-entire-project.498489/
试一试{
EventInfo evSceneLoaded=typeof(SceneManager).GetEvent(“sceneLoaded”);
类型tDelegate=evSceneLoaded.EventHandlerType;
MethodInfo attachHandler=typeof(Vuforia.VuforiaRuntime).GetMethod(“AttachVuforiaAtomainCamera”,BindingFlags.NonPublic | BindingFlags.Instance);
Delegate d=Delegate.CreateDelegate(typeof(UnityEngine.Events.UnityAction)、Vuforia.VuforiaRuntime.Instance、attachHandler);
SceneManager.sceneLoaded-=d作为UnityEngine.Events.UnityAction;
}捕获(例外e){
Debug.LogError(“无法删除附件VuforiatomainCamera操作.异常”+e.Message);
}
摧毁(这个);
}
}
[SOLVED]您只需使用VuforiaBehavior组件启用/禁用Vuforia摄像头即可
void StartCamera () {
vuforiaBehavior.enabled = true;
}
void StopCamera () {
vuforiaBehavior.enabled = false;
}
这意味着您在场景中有Vuforia组件。如果没有,它将不会加载,你的主菜单就是证明。谷歌虚拟现实也会改变你的视野,因为它只适用于一种设置。所以,也许改变来自那里。感谢answare。你说的Vuforia组件是什么意思?在我的AR场景中,我有ARCamera,但在主菜单场景和VR场景中,我只有主摄像头。我想它会加载,因为在我的播放器设置中,我已经检查了增强现实。但这是必须的。基本上,当相机打开时,你可以看到Vuforia行为精灵,因此我决定将精灵启用设置为false,这样你就可以在没有AR相机的情况下使用主相机。它对你有用吗????
void StartCamera () {
vuforiaBehavior.enabled = true;
}
void StopCamera () {
vuforiaBehavior.enabled = false;
}