赞
踩
刚看到这玩意我是懵逼的,网上一查这玩意根据你买的不同可运行java、android、windows等,那仔细一想,不就是两个系统之间的数据传递了,数据的中转我们用mysql就行。大致原理如下:
1、Unity端3D物体发生变化导致订单随之变化并生成条形码。
2、手持通过扫描条形码展示相对应的订单信息
3、找到核心,其实就是订单ID
4、unity货物变化后立马更新订单表,并根据订单ID生成条形码,随后手持设备扫描条形码得到订单ID,根据ID在数据库中去关联你想要展示的数据即可。
这是一个扩展应用,没有很大的难度,只需要搞清楚zxing库的原理以及你需求实现的思路就行。
步骤如下
1、将zxing.dll放入工程plugins下。
2、复制当前unity版本安装目录下的System.Drawing.dll也放入plugins目录下。必须是当前版本,否则崩溃的你找不到东南西北。
3、调用ZXingUitil类中的QrCreat方法即可返回条形码的texture。
4、得到Texture后你想咋搞就咋搞,GUI、NGUI、UGUI为你所用。
效果如下图:
代码如下:
- using UnityEngine;
- using System.Collections;
-
- using System.Drawing;
- using ZXing.QrCode;
- using ZXing;
- using ZXing.Common;
- using ZXing.Rendering;
- using ZXing.QrCode.Internal;
- using System;
- /// <summary>
- /// zxing 工具类,用来生成订单信息条形码
- /// 李佼
- /// </summary>
- public class ZXingUitil : MonoBehaviour
- {
-
- private int _width = 370;
- private int _height = 100;
- private Texture2D _texure2d;
- private bool _success;
-
- public static ZXingUitil instance;
- EncodingOptions options = null;
- BarcodeWriter writer = null;
-
- void Awake()
- {
- instance = this;
- }
-
- void Start()
- {
- _texure2d = new Texture2D(_width, _height);
-
- options = new EncodingOptions
- {
- Width = _width,
- Height = _height
- };
- writer = new BarcodeWriter();
- writer.Format = BarcodeFormat.ITF;
- writer.Options = options;
- }
- /// <summary>
- /// 传入条形码内容 返回条码图,条形码须为偶数位
- /// </summary>
- /// <param name="barcode"></param>
- /// <returns></returns>
- public Texture2D QrCreat(string barcode)
- {
- try
- {
- Bitmap bitmap = writer.Write(barcode);
- _texure2d.LoadImage(ImageToByte(bitmap));
- return _texure2d;
- }
- catch (Exception e)
- {
- Debug.LogError("z xing error");
- return null;
- }
- }
-
- public Texture2D QrCreat(string barcode, Vector2 imageVec)
- {
- _texure2d = new Texture2D((int)imageVec.x, (int)imageVec.y);
- Bitmap bitmap = writer.Write(barcode);
- _texure2d.LoadImage(ImageToByte(bitmap));
- return _texure2d;
- }
-
- private byte[] ImageToByte(Image img)
- {
- ImageConverter converter = new ImageConverter();
- return (byte[])converter.ConvertTo(img, typeof(byte[]));
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。