/* ######### ############ ############# ## ########### ### ###### ##### ### ####### #### ### ########## #### #### ########### #### #### ########### ##### ##### ### ######## ##### ##### ### ######## ###### ###### ### ########### ###### ###### #### ############## ###### ####### ##################### ###### ####### ###################### ###### ####### ###### ######### ######## ###### ####### ###### ###### ######### ###### ####### ## ###### ###### ###### ###### # ###### ##### ##### ###### ##### ##### #### ##### #### ##### ### ##### ### ### # ### ### ### ## ### ### __________#_______### #_______ # # # #______________ body is a bodhi tree, the heart like a mirror, always wipe off, do not make dust. There is no bug in our future * ==============================================================================* Filename:camroc ode* Created: $time $* author:wyc* Purpose: Scanning two-dimensional images * ============================================================== ================*/usingUnityengine;usingSystem.Collections;usingUnityengine.ui;usingZXing; Public classCamrocode:monobehaviour {[Header ("UI")] Publicimage Image; PublicRawimage cameratexture; PublicText txt; Privatecolor32[] data; Private BOOLIsscan; Privatewebcamtexture webcameratexture; PrivateBarcodereader Barcodereader; Private floatTimer =0; IEnumerator Start () {Barcodereader=NewBarcodereader (); yield returnapplication.requestuserauthorization (Userauthorization.webcam); if(Application.hasuserauthorization (Userauthorization.webcam)) {webcamdevice[] devices=webcamtexture.devices; stringDeviceName = devices[0].name; Webcameratexture=NewWebcamtexture (DeviceName, -, -); Cameratexture.texture=webcameratexture; Webcameratexture.play (); Isscan=true; } } intwidth; voidScreenchange ()//Screen Toggle { if(Width = =screen.width)return; Width=Screen.width; if(Width >screen.height) {cameraTexture.transform.localEulerAngles=Vector3.zero; } Else{cameraTexture.transform.localEulerAngles=NewVector3 (0,0, - -); } } voidUpdate () {if(isscan) {timer+=Time.deltatime; if(Timer >0.5f)//0.5 seconds to scan .{startcoroutine (Scanqrcode ()); Timer=0; } } //Screenchange ();} IEnumerator Scanqrcode () {Data=webcameratexture.getpixels32 (); DECODEQR (Webcameratexture.width, webcameratexture.height); yield return NewWaitforendofframe (); } Private voidDECODEQR (intWidthintheight) { varBR =Barcodereader.decode (data, width, height); if(BR! =NULL) { //Txt.text = br. Text; //Isscan = false;startcoroutine (Load (Br. Text)); }} IEnumerator Load (stringtext) {Txt.text="being loaded"; //Request wwwwww www =NewWWW (text); yield returnwww; if(WWW! =NULL&&string. IsNullOrEmpty (Www.error)) {//Get TextureTexture2d texture =www.texture; //Create a SpriteSprite Sprite = sprite.create (texture,NewRect (0,0, Texture.width, Texture.height),NewVector2 (0.5f,0.5f)); Image.sprite=Sprite; Txt.text="Download Success"; } }}
Scan QR code to load Web images