123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using System.Text.RegularExpressions;
- using System.Data.SqlClient;
- using TMPro;
- using System;
- using ZXing;
- using ZXing.QrCode;
- using System.Net;
- public class qr : MonoBehaviour
- {
- [SerializeField] RawImage rowImage;
- [SerializeField] TextMeshProUGUI 測試;
-
-
- private WebCamTexture myCam;//接收攝影機返回的圖片數據
- private BarcodeReader barcodeReader;
- public CanvasScaler canvasScaler;
- // Start is called before the first frame update
- void Awake()
- {
-
- Main.Global.鏡頭啟動=false;
- barcodeReader = new BarcodeReader();
- int num = Main.Global.camfps;
- StartCoroutine(open_Camera(num));
-
- }
- void Start()
- {
-
- float screenWidth = Screen.width;
- float screenHeight = Screen.height;
- float rate = screenWidth/screenHeight;
- if (rate>1.6)
- {
- canvasScaler.matchWidthOrHeight = 1f;
- }
- else
- {
- canvasScaler.matchWidthOrHeight = 0f;
- }
-
-
-
- }
-
-
- void Update()
- {
- if (Main.Global.鏡頭啟動=true)
- {
- DecodeQR();
- }
-
- }
- public void exit_click()
- {
-
- change_Secen(0);
-
- }
-
- private void DecodeQR()
- {
-
- Result res = barcodeReader.Decode(myCam.GetPixels32(), myCam.width, myCam.height);
-
-
-
- if (res != null)
- {
- Main.Global.PI=res.ToString();
- 測試.text="readQR="+Main.Global.PI;
- StartCoroutine(QR登入());
- }
- else
- {
- 測試.text="readfalse";
- }
-
- }
- IEnumerator QR登入()
- {
- string strcon = "QR";
- string name = Main.Global.PI;
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&ID={1}&se={2}", strcon, name,se);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- else
- {
- 測試.text+="connect_sucess"+" ";
- }
- string htm2 = request.downloadHandler.text;
- //Debug.Log(htm2);
- Main.Global.鏡頭啟動=false;
- if (htm2=="登入失敗")
- {
- // 測試.text+=htm2;
- change_Secen(0);
-
- }
- else
- {
- Main.Global.PA=htm2;
- 測試.text+=htm2+" ";
- StartCoroutine(判斷密碼());
-
-
- }
- }
- IEnumerator 判斷密碼()
- {
-
- string strcon = "登入1";
- string name = Main.Global.PA;
-
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&帳號={1}&se={2}", strcon, name, se);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- string str = request.downloadHandler.text.ToString();
- Main.Global.PB=str;
- 測試.text+=str+" ";
- change_Secen(1);
-
-
- }
- private IEnumerator open_Camera(int fps)
- {
- yield return Application.RequestUserAuthorization(UserAuthorization.WebCam); //授權開啟鏡頭
- if (Application.HasUserAuthorization(UserAuthorization.WebCam))
- {
- //設置攝影機要攝影的區域
- myCam = new WebCamTexture(WebCamTexture.devices[0].name, Screen.width, Screen.height, fps);/* (攝影機名稱, 攝影機要拍到的寬度, 攝影機要拍到的高度, 攝影機的FPS) */
- rowImage.texture = myCam;
- myCam.Play();//開啟攝影機
- Main.Global.鏡頭啟動=true;
- }
- }
- public void change_Secen(int _screenNum)
- {
-
- myCam.Stop();
- SceneManager.LoadScene(_screenNum);
- }
- }
|