最近在写Ar项目,研究了一段时间Vuforia+zxing实现二维码扫描,走了许多弯路,浪费了很多时间,因此,分享一下代码,方便那些想要用vuforia+zxing来实现二维码扫描同学。
直接贴代码:
using UnityEngine;
using FairyGUI;
using ZXing;
using ZXing.Client.Result;
using Vuforia;
using System;
//扫描二维码
public class UIScanning : MonoBehaviour
{
private GObject _ArVerifyQRUI_btn_back_name;
private GComponent _mainView;
private GLoader _mGloader;
private GTextInput _ArVerifyQRUI_et_code_name;
private Vuforia.Image.PIXEL_FORMAT m_PixelFormat = Vuforia.Image.PIXEL_FORMAT.RGB888;
private bool m_RegisteredFormat = false;
private bool m_LogInfo = true;
public VuforiaBehaviour vuforia;
public static event Action<ParsedResult, string> Scanned = delegate { };
public static event Action<string> ScannedQRCode = delegate { };
public static event Action<string> ScannedBarCode = delegate { };
bool decoding;
bool init;
BarcodeReader barcodeReader = new BarcodeReader();
void Awake()
{
UIPackage.AddPackage("fairyui_scan_main/scense_2/ArScanMain");
}
void Start()
{
Global.seleteScene(5);
_mainView = this.GetComponent<UIPanel>().ui;
_ArVerifyQRUI_btn_back_name = _mainView.GetChild("ArVerifyQRUI_btn_back_name");
_ArVerifyQRUI_btn_back_name.visible = true;
_ArVerifyQRUI_btn_back_name.onClick.Add(onClickBack);
_mGloader = _mainView.GetChild("ArVerifyQRUI_Iimages").asLoader;
_ArVerifyQRUI_et_code_name = _mainView.GetChild("ArVerifyQRUI_et_co