void OnCaptured(CaptureCamera captureCamera) { RawImage.enabled = true; RawImage.texture = captureCamera.CaptureImage; LetterBoxCamera letterBoxCamera = captureCamera.GetComponent <LetterBoxCamera>(); if (letterBoxCamera != null) { RawImage.rectTransform.SetSize(letterBoxCamera.CurrentSize); //ズームが1ではなく、このイメージを描画するカメラのキャプチャ画像かどうか if (letterBoxCamera.Zoom2D != 1) { int layerMask = 1 << this.gameObject.layer; if ((letterBoxCamera.CachedCamera.cullingMask & layerMask) != 0) { Vector2 pivot = letterBoxCamera.Zoom2DCenter; pivot.x /= letterBoxCamera.CurrentSize.x; pivot.y /= letterBoxCamera.CurrentSize.y; pivot = -pivot + Vector2.one * 0.5f; RawImage.rectTransform.pivot = pivot; RawImage.rectTransform.localScale = Vector3.one / letterBoxCamera.Zoom2D; } } } else { RawImage.rectTransform.SetSize(Screen.width, Screen.height); } //カメラのキャプチャコンポーネントを無効にする captureCamera.OnCaptured.RemoveListener(OnCaptured); captureCamera.enabled = false; }
//カメラのキャプチャ画像を、Imageとして設定 internal void CaptureCamera(Camera camera) { RawImage.enabled = false; //カメラのキャプチャコンポーネントを有効に CaptureCamera captureCamera = camera.GetComponentCreateIfMissing <CaptureCamera>(); captureCamera.enabled = true; captureCamera.OnCaptured.AddListener(OnCaptured); }
void OnCaptured(CaptureCamera captureCamera) { RawImage.enabled = true; RawImage.texture = captureCamera.CaptureImage; LetterBoxCamera letterBoxCamera = captureCamera.GetComponent <LetterBoxCamera>(); if (letterBoxCamera != null) { RawImage.rectTransform.SetSize(letterBoxCamera.CurrentSize); } else { RawImage.rectTransform.SetSize(Screen.width, Screen.height); } //カメラのキャプチャコンポーネントを無効にする captureCamera.OnCaptured.RemoveListener(OnCaptured); captureCamera.enabled = false; }