Для чтения с веб камеры.
using UnityEngine;
using System.Collections;
using System.Threading;
using com.google.zxing.qrcode;
public class SecurityTest : MonoBehaviour {
WebCamTexture camTexture;
Thread qrThread;
Color32[] c;
sbyte[] d;
int w, h, wxh;
int x, y, z;
bool isQuit;
public void Start () {
camTexture = new WebCamTexture ();
OnEnable ();
qrThread = new Thread (DecodeQR);
qrThread.Start ();
}
public void OnEnable () {
if (camTexture != null) {
camTexture.Play ();
w = camTexture.width;
h = camTexture.height;
wxh = w * h;
}
}
public void OnDisable () {
if (camTexture != null) {
camTexture.Pause ();
}
}
public void OnDestroy () {
qrThread.Abort ();
camTexture.Stop ();
}
public void OnApplicationQuit () {
isQuit = true;
}
public void Update () {
c = camTexture.GetPixels32 ();
}
public void DecodeQR () {
while(true) {
if(isQuit) break;
try {
d = new sbyte[wxh];
z = 0;
for(y = h - 1; y >= 0; y--) {
for(x = 0; x < w; x++) {
d[z++] = (sbyte)(((int)c[y * w + x].r) << 16 | ((int)c[y * w + x].g) << 8 | ((int)c[y * w + x].b));
}
}
Debug.Log (new QRCodeReader().decode(d, w, h).Text);
}
catch {
continue;
}
}
}
public void OnGUI () {
GUI.DrawTexture(new Rect (0, 0, Screen.width, Screen.height), camTexture, ScaleMode.ScaleToFit);
}
}