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; }
public void StopPreview() { DispatchUtility.onFrame -= Update; PreviewTexture.Stop(); WebCamTexture.Destroy(PreviewTexture); PreviewTexture = null; previewBuffer = null; camera = null; startCallback = frameCallback = null; }