public void ToggleBackgrounds(bool val) { ARCompanion.InitBackground(); GameObject camObject = ARCompanion.xrcamBehaviour.planeObject; if (val == true) { ARCompanion.xrcamBehaviour.InitCameraPlane("None"); EnvironmentHider.HideEnvironmentObjects(true, true); } else { ARCompanion.xrcamBehaviour.InitCameraPlane(SelectedWebcam); } camObject.SetActive(val); }
public void InitCameraPlane(string camname = "") { var config = Settings.instance; if (planeObject == null) { planeContainer = new GameObject(); planeContainer.name = "_ARContainer"; planeObject = GameObject.CreatePrimitive(PrimitiveType.Plane); planeObject.transform.SetParent(planeContainer.transform); planeObject.name = "ARCameraPlane"; } if (camname == "None" || config.SelectedWebcam == "None") { EnvironmentHider.HideEnvironmentObjects(true, true); planeObject.SetActive(false); return; } planeObject.SetActive(true); Renderer planeRenderer = planeObject.GetComponent <Renderer>(); if (planeMat == null || !planeMat.HasProperty("_Tex")) { Stream abStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ARCompanion.Resources.ARCam"); byte[] assetbin = new byte[abStream.Length]; abStream.Read(assetbin, 0, (int)abStream.Length); shaderAssetBundle = AssetBundle.LoadFromMemory(assetbin); planeShader = shaderAssetBundle.LoadAllAssets <Shader>().First(); planeMat = shaderAssetBundle.LoadAllAssets <Material>().First(); } planeRenderer.material = planeMat; planeMat.SetTexture("_Tex", webcamTexture); planeMat.color.ColorWithAlpha(0); webcamName = camname; planeObject.transform.localEulerAngles = new Vector3(90, 0, 180); if (shaderAssetBundle != null) { shaderAssetBundle.Unload(false); } RefreshWebcam(); }
private void Update() { try { var config = Settings.instance; if (planeObject == null || planeContainer == null || planeMat == null) { InitCameraPlane(config.SelectedWebcam); } if (webcamTexture != null || ARCompanion.openvrCameraManager != null) { if (Input.GetKeyDown(KeyCode.J)) { RefreshWebcam(); } if (Camera.main != null || planeContainer == null) { SetCamOffsets(); planeContainer.transform.parent = Camera.main.transform; } ARCompanion.xrcamBehaviour.planeContainer.SetActive(true); } string curscene = SceneManager.GetActiveScene().name; switch (curscene) { case "MenuViewControllers": case "GameCore": EnvironmentHider.HideEnvironmentObjects(SceneManager.GetActiveScene().name == "MenuViewControllers", config.SelectedWebcam == "None"); break; default: break; } } catch (Exception) { throw; } }
[UIAction("hideobj-refresh")] private void RefreshHiddenObjects() => EnvironmentHider.HideEnvironmentObjects(true);
private void RefreshWebcam(string cameraName = "") { var config = Settings.instance; string newwebcam = cameraName == "" ? config.SelectedWebcam : cameraName; bool hmdHasCamera = false; if (XRSettings.loadedDeviceName == "OpenVR") { OpenVR.TrackedCamera.HasCamera(OpenVR.k_unTrackedDeviceIndex_Hmd, ref hmdHasCamera); if (ARCompanion.openvrCameraManager != null) { ARCompanion.openvrCameraManager.enabled = (hmdHasCamera && newwebcam == "SteamVR"); } } if (newwebcam == "Auto") { WebCamDevice[] avaliableWebCams = WebCamTexture.devices; InputDevice controllerRef = InputDevices.GetDeviceAtXRNode(XRNode.RightHand); string preset = ""; string inputRefName = ""; if (controllerRef != null && controllerRef.name != null) { inputRefName = controllerRef.name; } foreach (var camera in WebCamTexture.devices) { switch (camera.name) { case "HTC Vive": config.SelectedWebcam = camera.name; newwebcam = camera.name; preset = inputRefName.Contains("Vive. Controller MV") ? "Vive Wands (HTC Vive)" : "Knuckles (HTC Vive)"; break; case "eTronVideo": config.SelectedWebcam = camera.name; newwebcam = camera.name; preset = "Knuckles (Valve Index)"; break; case "VIVE Pro Camera": config.SelectedWebcam = camera.name; newwebcam = camera.name; preset = "None"; break; default: break; } } new CameraOffsetMenu().SetPreset(preset); planeObject.SetActive(true); planeObject.transform.rotation = Quaternion.Euler(90, 0, 180); ARCompanion.openvrCameraManager.enabled = false; } EnvironmentHider.HideEnvironmentObjects(true, newwebcam == "Auto" || newwebcam == "None" || !(config.HideGameEnv || config.HideMenuEnv)); if (newwebcam != "Auto") { webcamTexture.Stop(); webcamTexture.deviceName = newwebcam; webcamTexture.Play(); } else { Logger.Log("No headset cameras could be found.", IPA.Logging.Logger.Level.Info); } }