Beispiel #1
0
    public void switchCam()
    {
        RawImage displayImage = camDisplayCanvas.transform.FindChild("CameraImage").gameObject.GetComponent <RawImage> ();

        pCamera.Stop();
        //#if UNITY_IOS
        if (whichCamera == WHICHCAMERA.Front && backCamName != "")
        {
            pCamera     = new WebCamTexture(backCamName, 1920, 1080);
            whichCamera = WHICHCAMERA.Back;
            displayImage.transform.localScale = new Vector3(1, -1, 1);
        }
        else if (whichCamera == WHICHCAMERA.Back && frontCamName != "")
        {
            pCamera     = new WebCamTexture(frontCamName, 1920, 1080);
            whichCamera = WHICHCAMERA.Front;
            displayImage.transform.localScale = new Vector3(1, 1, 1);
        }
        else
        {
            Debug.Log("Can Not Switch.");
            return;
        }


        displayImage.texture = pCamera;
        pCamera.Play();
        //#endif
    }
Beispiel #2
0
    void startCamera()
    {
        pCamera = new WebCamTexture();

        //#if UNITY_IPHONE
        WebCamDevice[] devices = WebCamTexture.devices;
        for (int i = 0; i < devices.Length; i++)
        {
            if (devices[i].isFrontFacing)
            {
                frontCamName = devices[i].name;
            }
            else
            {
                backCamName = devices[i].name;
            }
        }
        if (frontCamName != "")
        {
            pCamera     = new WebCamTexture(frontCamName, 1920, 1080);
            whichCamera = WHICHCAMERA.Front;
        }
        else
        {
            pCamera     = new WebCamTexture(backCamName, 1920, 1080);
            whichCamera = WHICHCAMERA.Back;
        }
        //#endif

        camDisplayCanvas.transform.FindChild("CameraImage").gameObject.GetComponent <RawImage> ().texture = pCamera;
        pCamera.Play();
    }