Esempio n. 1
0
        public void StartPreview(DeviceCamera genericCamera, Action startCallback, Action frameCallback)
        {
            this.startCallback = startCallback;
            this.frameCallback = frameCallback;
            var camera = genericCamera as DeviceCameraLegacy;

            // Create preview
            if (PreviewTexture && this.camera != camera)
            {
                WebCamTexture.Destroy(PreviewTexture);
                PreviewTexture = null;
            }
            if (!PreviewTexture)
            {
                if (camera.PreviewResolution.x == 0)
                {
                    PreviewTexture = new WebCamTexture(camera.Device.name);
                }
                else
                {
                    PreviewTexture = new WebCamTexture(
                        camera.Device.name,
                        camera.PreviewResolution.x,
                        camera.PreviewResolution.y,
                        (int)Mathf.Max(camera.Framerate, 30)
                        );
                }
                this.camera = camera as DeviceCameraLegacy;
            }
            // Start preview
            firstFrame = true;
            PreviewTexture.Play();
            DispatchUtility.onFrame += Update;
        }
Esempio n. 2
0
 public void Play()
 {
     // Create dispatch
     if (dispatch == null)
     {
         dispatch = new MainDispatch();
         dispatch.Dispatch(Update);
     }
     // Create preview
     if (!PreviewTexture)
     {
         string name       = WebCamTexture.devices[camera].name;
         var    resolution = Device.GetPreviewResolution(camera);
         var    rate       = Mathf.Max(30, (int)Device.GetFramerate(camera));
         PreviewTexture = resolution.width == 0 ?  new WebCamTexture(name) : new WebCamTexture(name, resolution.width, resolution.height, rate);
     }
     // Start preview
     firstFrame = true;
     PreviewTexture.Play();
 }