public void Init()
 {
     startCVCam = false;
     if (rawImage)
     {
         if (cvCameraMat == null)
         {
             cvCameraMat = GetComponent <CVCameraMat> ();
         }
         if (cvCameraMat != null)
         {
             if (cvCameraMat.isInited())
             {
                 if (!cvCameraMat.isPlaying())
                 {
                     cvCameraMat.Play();
                 }
                 else
                 {
                     if (texture != null)
                     {
                         startCVCam = true;
                     }
                     else
                     {
                         OnCVCameraMatInited();
                     }
                 }
             }
             else
             {
                 cvCameraMat.Init();
             }
         }
     }
     else
     {
         Debug.LogError("NotFound:rawImage");
     }
 }
Exemple #2
0
    private void webCamInit()
    {
        if (initDone)
        {
            Dispose();
        }

        if (!String.IsNullOrEmpty(requestDeviceName))
        {
            for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++)
            {
                webCamDevice = WebCamTexture.devices [cameraIndex];
                if (webCamDevice.name == requestDeviceName)
                {
                    webCamTexture = new WebCamTexture(requestDeviceName, requestWidth, requestHeight);
                }
            }
        }

        if (webCamTexture == null)
        {
            if (WebCamTexture.devices.Length > 0)
            {
                //スマホならインカメ -> 1
                //webCamDevice = WebCamTexture.devices [1];
                //macなら1つのカメラ -> 0
                                #if UNITY_EDITOR
                webCamDevice = WebCamTexture.devices [0];
                                #else
                var euler = transform.localRotation.eulerAngles;
                transform.localRotation = Quaternion.Euler(euler.x, euler.y, euler.z - 90);
                webCamDevice            = WebCamTexture.devices [1];
                                #endif
                webCamTexture = new WebCamTexture(webCamDevice.name, requestWidth, requestHeight);
            }
            else
            {
                webCamTexture = new WebCamTexture(requestWidth, requestHeight);
            }

            /*
             * if (WebCamTexture.devices.Length > 0) {
             *
             *      //スマホならインカメ -> 1
             *      webCamDevice = WebCamTexture.devices [1];
             * } else {
             *      //macなら1つのカメラ -> 0
             *      webCamDevice = WebCamTexture.devices [0];
             * }
             * webCamTexture = new WebCamTexture (webCamDevice.name, requestWidth, requestHeight);
             * webCamTexture = new WebCamTexture (requestWidth, requestHeight);
             */
        }
        if (webCamTexture)
        {
            webCamTexture.Play();

            GameObject  coroutineObj = new GameObject("waitWebCamTexture");
            CVCameraMat coroutine    = coroutineObj.AddComponent <CVCameraMat> ();
            coroutine.StartCoroutine(waitWebCamFrame(coroutineObj));
        }
        else
        {
            webCamInit();
        }
    }