Tanoda
QREncodeTest.cs
Go to the documentation of this file.
1
6
7using UnityEngine;
8using UnityEngine.UI;
9
10public class QREncodeTest : MonoBehaviour
11{
13 public RawImage qrCodeImage;
14 public InputField m_inputfield;
15 public Text infoText;
16
17 public Texture2D codeTex;
18
19 // Use this for initialization
20 void Start()
21 {
22 if (e_qrController != null) e_qrController.onQREncodeFinished += qrEncodeFinished; //Add Finished Event
23 }
24
25 // Update is called once per frame
26 void Update()
27 {
28 }
29
30 void qrEncodeFinished(Texture2D tex)
31 {
32 if (tex != null && tex != null)
33 {
34 var width = tex.width;
35 var height = tex.height;
36 var aspect = width * 1.0f / height;
37 qrCodeImage.GetComponent<RectTransform>().sizeDelta = new Vector2(170, 170.0f / aspect);
38 qrCodeImage.texture = tex;
39 codeTex = tex;
40 }
41 }
42
43 public void setCodeType(int typeId)
44 {
46 Debug.Log("clicked typeid is " + e_qrController.eCodeFormat);
47 }
48
49
50 public void Encode()
51 {
52 if (e_qrController != null)
53 {
54 var valueStr = m_inputfield.text;
55 var errorlog = e_qrController.Encode(valueStr);
56 infoText.color = Color.red;
57 if (errorlog == -13)
58 {
59 infoText.text = "Must contain 12 digits,the 13th digit is automatically added !";
60 }
61 else if (errorlog == -8)
62 {
63 infoText.text = "Must contain 7 digits,the 8th digit is automatically added !";
64 }
65 else if (errorlog == -39)
66 {
67 infoText.text = "Only support digits";
68 }
69 else if (errorlog == -128)
70 {
71 infoText.text = "Contents length should be between 1 and 80 characters !";
72 }
73 else if (errorlog == -1)
74 {
75 infoText.text = "Please select one code type !";
76 }
77 else if (errorlog == 0)
78 {
79 infoText.color = Color.green;
80 infoText.text = "Encode successfully !";
81 }
82 }
83 }
84
85 public void ClearCode()
86 {
87 qrCodeImage.texture = null;
88 m_inputfield.text = "";
89 infoText.text = "";
90 }
91
92 public void SaveCode()
93 {
95 }
96}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
UnityEngine.Color Color
Definition: TestScript.cs:32
int Encode(string valueStr)
Encode the specified string .
QREncodeFinished onQREncodeFinished
InputField m_inputfield
Definition: QREncodeTest.cs:14
Texture2D codeTex
Definition: QREncodeTest.cs:17
QRCodeEncodeController e_qrController
Definition: QREncodeTest.cs:12
void SaveCode()
Definition: QREncodeTest.cs:92
RawImage qrCodeImage
Definition: QREncodeTest.cs:13
void Encode()
Definition: QREncodeTest.cs:50
void setCodeType(int typeId)
Definition: QREncodeTest.cs:43
void ClearCode()
Definition: QREncodeTest.cs:85