5using System.Collections;
13 GameObject e_CameraPlaneObj;
15 float screenVideoRatio = 1.0f;
31 e_CameraPlaneObj = transform.Find(
"CameraPlane").gameObject;
40 if (
dWebCam.
Width() > 200 && !isCorrected) correctScreenRatio();
42 if (e_CameraPlaneObj.activeSelf)
43 e_CameraPlaneObj.GetComponent<Renderer>().material.mainTexture =
dWebCam.
preview;
55 requestCameraPermissions();
69 if (e_CameraPlaneObj.activeSelf) e_CameraPlaneObj.GetComponent<Renderer>().material.mainTexture =
null;
75 void correctScreenRatio()
78 var videoHeight = 480;
79 var ScreenWidth = 640;
80 var ScreenHeight = 480;
83 float screenRatio = 1;
91 videoRatio = videoWidth * 1.0f / videoHeight;
92#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
93 ScreenWidth = Mathf.Max (Screen.width, Screen.height);
94 ScreenHeight = Mathf.Min (Screen.width, Screen.height);
96 ScreenWidth = Screen.width;
97 ScreenHeight = Screen.height;
99 screenRatio = ScreenWidth * 1.0f / ScreenHeight;
101 screenVideoRatio = screenRatio / videoRatio;
104 if (e_CameraPlaneObj !=
null)
108 void requestCameraPermissions()
114 StartCoroutine(waitTimeToOpenCamera());
121 deniedPermissionAndDontAskAgain =>
129 IEnumerator waitTimeToOpenCamera()
131 yield
return new WaitForEndOfFrame();
static void RequestPermission(string permissionName, AndroidPermissionCallback callback)
void StartWork()
start the work.
void StopWork()
Stops the work. when you need to leave current scene ,you must call this func firstly
int Width()
get the width of the camera
int Height()
get the height of the camera
bool isPlaying()
get status of the camera
void Play()
open the camera
void Stop()
Stop this camera.
static string CAMERA_PERMISSION
static bool checkPermissions()