123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- 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 System.IO;
- using ZXing;
- using ZXing.QrCode;
- using System.Net;
- using SimpleJSON;
- using System.ComponentModel;
-
- public class Main : MonoBehaviour
- {
- [SerializeField] GameObject 下載面板;
- [SerializeField] TextMeshProUGUI 下載文字;
- [SerializeField] TextMeshProUGUI 下載進度;
- [SerializeField] Slider 進度條;
- public CanvasScaler canvasScaler;
- [SerializeField] GameObject 細板;
- [SerializeField] GameObject 寬板;
- [SerializeField] TextMeshProUGUI 資料庫;
- [SerializeField] TextMeshProUGUI 執行檔;
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
- private string loadingText = "";
- private int dotCount = 0;
-
- [SerializeField] Image backgroundImage;
- [SerializeField] Sprite[] backgroundSprites;
- string 資料庫版本號 = "";
- string 執行檔版本號 = "";
- private ScreenOrientation currentOrientation;
- string 更新路徑;
- string 更新;
-
- void Start()
- {
- Screen.autorotateToPortrait = true;
- Screen.orientation = ScreenOrientation.AutoRotation;
- if (Main.Global.螢幕方向=="直")
- {
- canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
- canvasScaler.matchWidthOrHeight=Main.Global.固比;
- }
- else
- {
- canvasScaler.referenceResolution = new Vector2(Main.Global.固高, Main.Global.固寬);
- canvasScaler.matchWidthOrHeight=Main.Global.固比1;
- }
- if (Main.Global.螢幕格式=="胖")
- {
- 寬板.SetActive(true);
- 細板.SetActive(false);
- }
- else
- {
- 細板.SetActive(true);
- 寬板.SetActive(false);
- }
-
- currentOrientation = Screen.orientation;
- if (backgroundSprites != null && backgroundSprites.Length > 0)
- {
- // 隨機選擇一張圖片
- int randomIndex = UnityEngine.Random.Range(0, backgroundSprites.Length);
- Sprite selectedSprite = backgroundSprites[randomIndex];
- // 將選擇的圖片設定為背景
- backgroundImage.sprite = selectedSprite;
- }
- StartCoroutine(AnimateText());
- 更新路徑="";
- 更新="";
- 讀取面板.SetActive(true);
- 讀取版本號();
- 判斷版本號();
- }
- void Update()
- {
- if (Main.Global.版本號比對=="ture")
- {
- if (Screen.orientation != currentOrientation)
- {
- if (Screen.orientation == ScreenOrientation.LandscapeLeft)
- {
- Main.Global.螢幕方向="橫";
- change_Secen(3);
- }
- if (Screen.orientation == ScreenOrientation.Portrait)
- {
- Main.Global.螢幕方向="直";
- change_Secen(1);
- }
- }
- }
- }
- public void 讀取版本號()
- {
- using (SqlConnection connection = new SqlConnection(Main.Global.sql))
- {
- try
- {
- connection.Open();
-
- string query = "SELECT 手機認證版本號 FROM 版本號管理 ";
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- if (reader.Read()) // 檢查是否有資料
- {
- 資料庫版本號 = reader.GetString(0); // 假設版本號在結果集中的第一列
- }
- }
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
- }
- finally
- {
- connection.Close();
- }
- }
- }
- public void 判斷版本號()
- {
- 執行檔版本號=Application.version;
- if (資料庫版本號 != "")
- {
- if (資料庫版本號 == 執行檔版本號)
- {
- 讀取面板.SetActive(false);
- Main.Global.版本號比對="ture";
- }
- else
- {
- 讀取面板.SetActive(false);
- 下載面板.SetActive(true);
- 下載文字.text="版本不符合,檔案下載中";
- WebClient client = new WebClient();
- string url = "http://106.1.48.106:8080/HX_APP/BIFENG.apk";
- string path = Application.persistentDataPath+"/BIFENG.apk";
- if (File.Exists(path))
- {
- File.Delete(path);
- }
- StartCoroutine(DownloadFile(url, path));
- }
- }
- 資料庫.text+=資料庫版本號;
- 執行檔.text+=執行檔版本號;
-
- }
-
-
- IEnumerator AnimateText()
- {
- string qqq = 讀取.text.ToString();
- while (true)
- {
- yield return new WaitForSeconds(0.5f);
-
- if (dotCount < 3)
- {
- loadingText += ".";
- dotCount++;
- }
- else
- {
- loadingText = "";
- dotCount = 0;
- }
-
- 讀取.text = qqq+loadingText;
- }
- }
-
- IEnumerator DownloadFile(string url, string path)
- {
- using (WWW www = new WWW(url))
- {
- while (!www.isDone)
- {
- float progress = Mathf.Clamp01(www.progress / 0.9f);
- 進度條.value = progress;
- int bar = (int)(progress*100);
- 下載進度.text=bar.ToString()+"%";
- yield return null;
- }
-
- if (string.IsNullOrEmpty(www.error))
- {
- System.IO.File.WriteAllBytes(path, www.bytes);
- //Debug.Log("Download complete!");
- 進度條.value = 1f;
-
-
- yield return new WaitForSeconds(1f);
-
- InstallApk(path);
- }
- else
- {
- Debug.LogError("Download error: " + www.error);
- }
- }
- }
- public void 書架()
- {
- Main.Global.PA1="";
- Main.Global.PA2="";
- Main.Global.PA3="";
- Main.Global.PA4="";
- if (Main.Global.螢幕方向=="直")
- {
- change_Secen(2);
- }
- else
- {
- change_Secen(4);
- }
- }
-
- public void 風水()
- {
- Main.Global.資料庫名稱="風水";
- Main.Global.PA1="";
- Main.Global.PA2="";
- Main.Global.PA3="";
- Main.Global.PA4="";
- if (Main.Global.螢幕方向=="直")
- {
- change_Secen(5);
- }
- else
- {
- change_Secen(6);
- }
- }
- public void 擇日()
- {
- Main.Global.資料庫名稱="擇日";
- Main.Global.PA1="";
- Main.Global.PA2="";
- Main.Global.PA3="";
- Main.Global.PA4="";
- if (Main.Global.螢幕方向=="直")
- {
- change_Secen(5);
- }
- else
- {
- change_Secen(6);
- }
- }
- public void 命名()
- {
- Main.Global.資料庫名稱="命名";
- Main.Global.PA1="";
- Main.Global.PA2="";
- Main.Global.PA3="";
- Main.Global.PA4="";
- if (Main.Global.螢幕方向=="直")
- {
- change_Secen(5);
- }
- else
- {
- change_Secen(6);
- }
- }
- public void 流年()
- {
- Main.Global.資料庫名稱="流年";
- Main.Global.PA1="";
- Main.Global.PA2="";
- Main.Global.PA3="";
- Main.Global.PA4="";
- if (Main.Global.螢幕方向=="直")
- {
- change_Secen(5);
- }
- else
- {
- change_Secen(6);
- }
- }
- public void 日誌()
- {
- change_Secen(7);
- }
- public void 彈跳面板關閉()
- {
- 彈跳面板.SetActive(false);
- 彈跳文字.text = "";
- }
- public static bool InstallApk(string apkPath)
- {
- AndroidJavaClass javaClass = new AndroidJavaClass("com.test.install.Install");
- return javaClass.CallStatic<bool>("InstallApk", apkPath);
- }
- public static class Global
- {
- public static string 資料庫名稱,螢幕方向, sql,螢幕格式,登入人IP, 年,日期, 職稱, 系統語言 ,使用者名稱, 密碼, 進入, 離開, 資料庫版本號, 執行檔版本號,版本號比對,預設伺服器路徑,版本號,選擇組別,阿帕契路徑,阿帕契,CC判別,合約內容,合約編號,級別,ID,查詢日期,人員,連動客戶;
- public static bool 判斷是否連線, 啟動完畢,系統分區控制,登入位置,鏡頭啟動,有無清單 ,讀取完畢, 首次登入, 讀取年份, 快速登入, show1, show2, show3, show4, show5, show6, show7,展示帳號登入,qwe,印尼內網;
- public static int 部門編號,camfps;
- public static float rate, rate_ , 固比, 固比1, 固寬,固高;
- //public static TimeSpan 運行天數;
- public static string PA, PB, PC, PD, PE, PF, PG, PH, PI, PJ, PK, PA1, PA2, PA3, PA4, PA5, PA6, PA9, PA20;
- //public static bool[] 電表異常BL = new bool[999];
- // public static Sprite[] Wnum;
- // public static Sprite[] Bnum;
- public static string[] 系統語言資料;
- // public static string[] CC判斷=new string[999];
- public static Dictionary<string, string> 系統語言字典 = new Dictionary<string, string>() { };
- public static string[,] PHP = new string[5,2];
- }
- public void change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
- public void 截圖()
- {
- string fileName = string.Format("{0}/screenshot_{1}.png", Application.persistentDataPath, System.DateTime.Now.ToString("yyyyMMdd_HHmmss"));
- ScreenCapture.CaptureScreenshot(fileName);
- }
-
-
- }
|