void Update() { // Update() half as often m_alternateUpdate = !m_alternateUpdate; if (m_alternateUpdate) { return; } if (!m_isScanning || !m_rawImage || !m_webCam || !m_webCam.PreviewImage || !m_webCam.PreviewImage.texture) { return; } try { CameraManager.Instance._camera.TakePicture(m_rawImage.texture.width, m_rawImage.texture.height, (tex2D) => { if (tex2D == null) { return; } var pixels = tex2D.GetPixels32(); if (pixels == null || tex2D.width <= 16) { Debug.Log("No pixels loaded."); return; } Result result = m_barcodeReader.Decode(pixels, tex2D.width, tex2D.height); if (result == null) { return; } var shareToken = ShareTokenManager.Instance.ParseOutToken(result.Text); if (shareToken != null) { Debug.Log("Share TOKEN: " + shareToken); m_webCam.StopCamera(); this.TokenScanned.Invoke(shareToken); m_isScanning = false; } else { Debug.LogWarning("qr code found, not a share token. qr text: " + result.Text); } }); } catch (Exception e) { Debug.LogError(e); } }
public void Stop() { if (m_webCam) { m_webCam.StopCamera(); } m_isScanning = false; }