public virtual bool Init(CameraPlusBehaviour cameraPlus, string scriptPath) { _cameraPlus = cameraPlus; Plugin.cameraController.ActiveSceneChanged += OnActiveSceneChanged; return(LoadCameraData(scriptPath)); }
internal void AddWebCamScreen(string webCamName, CameraPlusBehaviour parentBhaviour) { webCamCanvas = new GameObject("WebCamCanvas").gameObject.AddComponent <Canvas>(); webCamCanvas.transform.SetParent(transform); webCamCanvas.renderMode = RenderMode.ScreenSpaceCamera; webCamCanvas.worldCamera = parentBhaviour._cam; webCamCanvas.planeDistance = 1; CanvasScaler canvasScaler = webCamCanvas.gameObject.AddComponent <CanvasScaler>(); canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; canvasScaler.referenceResolution = new Vector2(Screen.width, Screen.height); canvasScaler.matchWidthOrHeight = 1; RawImage raw = new GameObject("RawImage").AddComponent <RawImage>(); raw.transform.SetParent(webCamCanvas.transform); raw.transform.localPosition = Vector3.zero; raw.transform.localEulerAngles = Vector3.zero; rect = raw.GetComponent <RectTransform>(); rect.anchorMin = new Vector2(0.5f, 0.5f); rect.anchorMax = new Vector2(0.5f, 0.5f); rect.pivot = new Vector2(0.5f, 0.5f); rect.localScale = new Vector3(1f, 1f, 1); rect.anchoredPosition = new Vector2(0, 0); rect.sizeDelta = new Vector2(Screen.width, Screen.height); rect.localPosition = new Vector3(0, 0, 0); ChangeWebCamRectScale(parentBhaviour.Config.screenHeight); Init(raw, webCamName); }
private static void EndDragCamera() { if (_targetCamera == null) { return; } _targetCamera.Config.Position = _targetCamera.transform.position; _targetCamera.Config.Rotation = _targetCamera.transform.rotation.eulerAngles; if (!_targetCamera.Config.cameraLock.dontSaveDrag) { _targetCamera.Config.Save(); } _targetCamera = null; }
public static void BeginDragCamera(CameraPlusBehaviour camera) { if (_targetCamera != null) { EndDragCamera(); } _grabbingController = Resources.FindObjectsOfTypeAll <VRLaserPointer>() .LastOrDefault(x => x.gameObject.activeInHierarchy)?.GetComponentInParent <VRController>(); if (_grabbingController == null) { return; } _targetCamera = camera; _targetTransform = camera._cam.transform; _realPos = _targetCamera.Config.Position; _realRot = Quaternion.Euler(_targetCamera.Config.Rotation); _grabPos = _grabbingController.transform.InverseTransformPoint(_targetTransform.position); _grabRot = Quaternion.Inverse(_grabbingController.rotation) * _targetTransform.rotation; }
public void Init(CameraPlusBehaviour camera) { cam = camera; _cameraCube = GameObject.CreatePrimitive(PrimitiveType.Cube); DontDestroyOnLoad(_cameraCube); _cameraCube.transform.localScale = new Vector3(0.15f, 0.15f, 0.22f); _cameraCube.name = "CameraCube"; _cameraCube.layer = PluginConfig.Instance.CameraQuadLayer; _cameraCube.transform.SetParent(transform); _cameraCube.transform.localPosition = Vector3.zero; _cameraCube.transform.localEulerAngles = Vector3.zero; _cameraQuad = GameObject.CreatePrimitive(PrimitiveType.Quad); DontDestroyOnLoad(_cameraQuad); DestroyImmediate(_cameraQuad.GetComponent <Collider>()); _cameraQuad.GetComponent <MeshRenderer>().material = _previewMaterial; _cameraQuad.transform.SetParent(_cameraCube.transform); _cameraQuad.transform.localPosition = new Vector3(-1f * ((cam._cam.aspect - 1) / 2 + 1), 0, 0.22f); _cameraQuad.transform.localEulerAngles = new Vector3(0, 180, 0); _cameraQuad.transform.localScale = new Vector3(cam._cam.aspect, 1, 1); _cameraQuad.layer = PluginConfig.Instance.CameraQuadLayer; }
internal void AddCalibrationScreen(CameraPlusBehaviour camplus, Camera camera) { _targetBehaviour = camplus; _webCamCanvas = new GameObject("WebCamCanvas").AddComponent <Canvas>(); _webCamCanvas.gameObject.transform.SetParent(this.transform); _webCamCanvas.renderMode = RenderMode.ScreenSpaceCamera; _webCamCanvas.worldCamera = camera; _webCamCanvas.planeDistance = 1; CanvasScaler canvasScaler = _webCamCanvas.gameObject.AddComponent <CanvasScaler>(); canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; canvasScaler.referenceResolution = new Vector2(Screen.width, Screen.height); canvasScaler.matchWidthOrHeight = 1; RawImage raw = new GameObject("RawImage").AddComponent <RawImage>(); raw.transform.SetParent(_webCamCanvas.transform); raw.transform.localPosition = Vector3.zero; raw.transform.localEulerAngles = Vector3.zero; var rect = raw.gameObject.GetComponent <RectTransform>(); rect.anchorMin = new Vector2(0.5f, 0.5f); rect.anchorMax = new Vector2(0.5f, 0.5f); rect.pivot = new Vector2(0.5f, 0.5f); rect.localScale = new Vector3(-1f, 1f, 1); rect.anchoredPosition = new Vector2(0, 0); rect.sizeDelta = new Vector2(Screen.width / 4, Screen.height / 4); rect.localPosition = new Vector3(0, 0, 0); _webCamTexture = new WebCamTexture(camplus.Config.webCamera.name); raw.texture = _webCamTexture; Material rawMaterial = new Material(Plugin.cameraController.Shaders["BeatSaber/BlitCopyWithDepth"]); rawMaterial.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 0)); rawMaterial.SetFloat("_CullMode", 0); raw.material = rawMaterial; _webCamTexture.Play(); _cursorImage = new GameObject("CursorImage").AddComponent <RawImage>(); _cursorImage.transform.SetParent(_webCamCanvas.transform); _cursorImage.transform.localPosition = Vector3.zero; _cursorImage.transform.localEulerAngles = Vector3.zero; _cursorImage.texture = CustomUtils.LoadTextureFromResources("CameraPlus.Resources.Xross.png"); Material cursorMat = new Material(Plugin.cameraController.Shaders["ChromaKey/Unlit/Cutout"]); cursorMat.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 0)); cursorMat.SetColor("_ChromaKeyColor", Color.white); cursorMat.SetFloat("_ChromaKeyHueRange", 0.5f); _cursorImage.material = cursorMat; _rectCursor = _cursorImage.GetComponent <RectTransform>(); _rectCursor.anchorMin = new Vector2(0.5f, 0.5f); _rectCursor.anchorMax = new Vector2(0.5f, 0.5f); _rectCursor.pivot = new Vector2(0.5f, 0.5f); _rectCursor.localScale = new Vector3(1f, 1f, 1); _rectCursor.anchoredPosition = new Vector2(0, 0); _rectCursor.sizeDelta = new Vector2(Screen.width / 8, Screen.height / 4.5f); _rectCursor.localPosition = new Vector3(0, 0, -0.1f); _calText = new GameObject("CalibrationText").AddComponent <HMUI.CurvedTextMeshPro>(); _calText.transform.SetParent(_webCamCanvas.transform); _calText.transform.localPosition = Vector3.zero; _calText.transform.localEulerAngles = Vector3.zero; _calText.alignment = TMPro.TextAlignmentOptions.Bottom; _calText.fontSize = 24; _calText.text = "Pull the trigger in front of the webcam."; var cakRect = _calText.gameObject.GetComponent <RectTransform>(); cakRect.anchorMin = new Vector2(0.5f, 0.5f); cakRect.anchorMax = new Vector2(0.5f, 0.5f); cakRect.pivot = new Vector2(0.5f, 0.5f); cakRect.localScale = new Vector3(1f, 1f, 1); cakRect.anchoredPosition = new Vector2(0, 0); cakRect.sizeDelta = new Vector2(Screen.width / 4, Screen.height / 3); cakRect.localPosition = new Vector3(0, 0, -0.1f); }