using System.Collections; using System.Collections.Generic; using TMPro; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using Google; using System; using Unity.Collections.LowLevel.Unsafe; using System.Data; using UnityEngine.SceneManagement; using System.Linq; using System.Threading.Tasks; using Lunar; using HtmlAgilityPack; using UnityEngine.Networking; using SimpleJSON; using System.Data.SqlClient; public class login : MonoBehaviour { public Sprite playSprite; public Sprite pauseSprite; public GameObject buttonPrefab1; public Transform buttonParent1; public GameObject buttonceneter1; public ScrollRect buttonscroll1; public RectTransform contentRectTransform; [SerializeField] TextMeshProUGUI[] 新聞標題; [SerializeField] TextMeshProUGUI[] 新聞日期; [SerializeField] Button[] 新聞按鈕; [SerializeField] TextMeshProUGUI[] 氣象標題; [SerializeField] Button[] 氣象按鈕; [SerializeField] Button 綁定紐; [SerializeField] GameObject 編輯頁, 編輯頁1, 編輯頁2,編輯_pl,新增_pl, 首頁_pl,下排紐, 編輯頁3; [SerializeField] Button 刪除,登出,保存; [SerializeField] TextMeshProUGUI 編輯文字,信箱_lb, 今日日期, 農曆日期, 沖煞, 宜, 忌, 節氣, 侯; [SerializeField] GameObject 登入頁; [SerializeField] GameObject 登入1; [SerializeField] GameObject 登入2; [SerializeField] GameObject 輸入面; [SerializeField] TextMeshProUGUI 輸入問題; [SerializeField] GameObject 輸入1; [SerializeField] GameObject 輸入2; [SerializeField] GameObject 主畫面; [SerializeField] GameObject 貼文面; [SerializeField] GameObject 介紹面; [SerializeField] GameObject 更新面; [SerializeField] TMP_InputField 密碼; [SerializeField] GameObject 錯誤訊息2_lb; [SerializeField] TextMeshProUGUI UID; [SerializeField] TextMeshProUGUI 編輯問題; [SerializeField] TMP_InputField 初姓名; [SerializeField] TMP_InputField 初電話; [SerializeField] TMP_InputField 初地址; [SerializeField] TMP_InputField 姓名; [SerializeField] TMP_InputField 電話; [SerializeField] TMP_InputField 地址; [SerializeField] FirebaseManager firebaseManager; [SerializeField] TextMeshProUGUI 彈跳文字; [SerializeField] GameObject 彈跳面板; public CanvasScaler canvasScaler; float screenWidth; float screenHeight; private ScreenOrientation currentOrientation; [SerializeField] GameObject 讀取面板; [SerializeField] TextMeshProUGUI 讀取; [SerializeField] GameObject 刪除面板; public string WebUrl = "244610800088-mgl15q9eq32dothu32ug3epbaof9aevh.apps.googleusercontent.com"; private string loadingText = ""; private int dotCount = 0; private string 編輯判斷 = ""; DataTable 貼文; private List posts = new List(); // 已生成的贴文列表 private int currentIndex = 1; private float 總高 = 0; private bool isLoadingPost = false; private string 預刪除單號 = ""; private string 介紹 = ""; private string 圖片資料庫名稱 = ""; private string 錄音資料庫名稱 = ""; private bool 檢查 = false; UniWebView webView1; DataTable 網頁; void Start() { StartCoroutine(SetupLayout()); //SQL_CommString.SQL_連線字串_圖片_SQL(); //SQL_CommString.SQL_連線字串_錄音_SQL(); //Main.Global.使用者UID="RmzmaqTfoFa6gwyZ6tqcBSgQLxd2"; //Main.Global.使用者暱稱="脩"; } IEnumerator SetupLayout() { StartCoroutine(AnimateText()); 讀取面板.SetActive(true); Screen.autorotateToPortrait = false; Screen.orientation = ScreenOrientation.Portrait; screenWidth = Screen.width; screenHeight = Screen.height; float rate = 900.0f / 1900.0f; if (canvasScaler == null) { canvasScaler = GetComponent(); } if (Screen.width < Screen.height) { Main.Global.rate = screenWidth / screenHeight; Main.Global.rate_ = 1 / Main.Global.rate; if (Main.Global.rate > rate) { canvasScaler.matchWidthOrHeight = 1f; } else { canvasScaler.matchWidthOrHeight = 0f; } } else { Main.Global.rate_ = screenWidth / screenHeight; Main.Global.rate = 1 / Main.Global.rate_; if (Main.Global.rate > rate) { canvasScaler.matchWidthOrHeight = 1f; } else { canvasScaler.matchWidthOrHeight = 0f; } } // 等待一帧以确保布局更新已完成 yield return null; 讀取sql(); bool isConnected = ConnectToDatabase(Main.Global.伺服器); if (isConnected) { SQL_CommString.SQL_連線字串_正式_SQL(Main.Global.伺服器); SQL_game_sys.SQL_版本號(); 讀取面板.SetActive(false); if (SQL_Module.dr.Read()) { string 版本號1 = SQL_Module.dr["安卓系統版本號"].ToString(); string 版本號2 = SQL_Module.dr["安卓送審版本號"].ToString(); if (Application.version != 版本號1 && Application.version != 版本號2) { 登入頁.SetActive(false); 主畫面.SetActive(false); 貼文面.SetActive(false); 介紹面.SetActive(false); 更新面.SetActive(true); } else { Debug.Log(貼文面.GetComponent().rect.width); if (Main.Global.回貼) { 登入頁.SetActive(false); 主畫面.SetActive(false); 貼文面.SetActive(true); 介紹面.SetActive(false); 更新面.SetActive(false); 下排紐.SetActive(true); 編輯_pl.SetActive(false); 新增_pl.SetActive(true); 首頁_pl.SetActive(true); } else { 登入頁.SetActive(true); 主畫面.SetActive(false); 貼文面.SetActive(false); 介紹面.SetActive(false); 更新面.SetActive(false); 登入1.SetActive(true); 登入2.SetActive(false); 下排紐.SetActive(false); } firebaseManager.auth.StateChanged += AuthStateChanged; } } DataSet ds = new(); SQL_game_sys.SQL_網頁讀取(); SQL_Module.da.Fill(ds); 網頁 = ds.Tables[0]; } else { 彈跳面板.SetActive(true); 讀取面板.SetActive(false); 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員"; 登入頁.SetActive(false); 主畫面.SetActive(false); 貼文面.SetActive(false); 介紹面.SetActive(false); 更新面.SetActive(false); 下排紐.SetActive(false); } } public bool ConnectToDatabase(string server) { string ConString = "server=" + server + ",4567;database=小農日記;uid=b70340;pwd=Lee0911274990;Connect Timeout=5"; try { // 尝试连接数据库 using (SqlConnection connection = new SqlConnection(ConString)) { connection.Open(); // 如果连接成功,则返回 true return true; } } catch (Exception ex) { // 如果连接失败,则在控制台中输出异常信息 Debug.Log("连接到数据库时出现异常:" + ex.Message); // 返回 false 表示连接失败 return false; } } public void 讀取sql() { string connectionString = "Data Source=mssql-147629-0.cloudclusters.net,12711;Initial Catalog=GCM-IP-DATE02;User ID=GCMIP02;Password=F52dfgS5ZVD"; using (SqlConnection connection = new SqlConnection(connectionString)) { try { connection.Open(); string query = "SELECT 客戶,IP FROM 客戶IP讀取 Where 客戶=N'菩芸伺服器'"; using (SqlCommand command = new SqlCommand(query, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) // 假設只取前兩筆資料 { // 取得類別和位址資料 Main.Global.伺服器 = reader["IP"].ToString(); } } } } catch (Exception ex) { Debug.LogError("Error connecting to the database: " + ex.Message); 彈跳面板.SetActive(true); 讀取面板.SetActive(false); 登入頁.SetActive(false); 主畫面.SetActive(false); 貼文面.SetActive(false); 介紹面.SetActive(false); 更新面.SetActive(false); 下排紐.SetActive(false); 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員"; } finally { connection.Close(); } } } public void 離開APP() { Application.Quit(); } private void 家網頁(string 網址) { var webViewGameObject = new GameObject("UniWebView"); webView1 = webViewGameObject.AddComponent(); webView1.Load(網址); webView1.Frame = new Rect(0, 0, screenWidth, screenHeight-150); webView1.Show(); } 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; } } private void post計算() { 總高= 0; foreach (var buttonObj in posts) { RectTransform panelRectTransform = buttonObj.GetComponent(); // 获取 RectTransform Vector2 panelSizeDelta = panelRectTransform.sizeDelta; // 获取大小 總高 += panelSizeDelta.y; // 加总大小 } RectTransform contentRectTransform = buttonParent1.GetComponent(); contentRectTransform.sizeDelta = new Vector2(contentRectTransform.sizeDelta.x, 總高); } void OnScrollValueChanged(Vector2 value) { if (isLoadingPost) { return; // 如果正在加载贴文,则退出方法 } //Debug.Log(buttonscroll1.velocity.y); //Debug.Log(buttonscroll1.normalizedPosition.y); if (buttonscroll1.velocity.y > 0 && buttonscroll1.normalizedPosition.y > 0.9f && currentIndex > 1) { // 向上滚动,生成新的贴文并卸载底部的贴文 bool 首位 = true; isLoadingPost = true; RemovePost(首位); currentIndex--; CreatePost(currentIndex - 1, 首位); post計算(); isLoadingPost = false; } else if (buttonscroll1.velocity.y < 0 && buttonscroll1.normalizedPosition.y < 0.1f && currentIndex < GetTotalPostsCount() - 2) { // 向下滚动,生成新的贴文并卸载顶部的贴文 bool 首位 = false; isLoadingPost = true; RemovePost(首位); currentIndex++; CreatePost(currentIndex+1, 首位); post計算(); isLoadingPost = false; } Vector2 newPosition = buttonscroll1.content.anchoredPosition; } void CreatePost(int i, bool 首位) { if (i < 0 || i >= GetTotalPostsCount()) return; // 从预制体创建贴文对象 GameObject buttonObj = Instantiate(buttonPrefab1, buttonParent1); buttonObj.name = "Post_" + i; ScrollRect scroll = buttonObj.transform.Find("相片")?.GetComponent(); RectTransform content = scroll.content; Image copy = content.Find("圖")?.GetComponent(); 圖片資料庫名稱=貼文.Rows[i][12].ToString(); 錄音資料庫名稱=貼文.Rows[i][13].ToString(); SQL_CommString.SQL_連線字串_錄音_SQL(Main.Global.伺服器,錄音資料庫名稱); SQL_CommString.SQL_連線字串_圖片_SQL(Main.Global.伺服器,圖片資料庫名稱); 圖片讀取(貼文.Rows[i][0].ToString(), copy, content, scroll); copy.gameObject.SetActive(false); TextMeshProUGUI count = buttonObj.transform.Find("相片數")?.GetComponent(); PhotoScrollView scrollView = scroll.AddComponent(); scrollView.largeScrollView =buttonscroll1; scrollView.smallScrollView =scroll; // 设置 ScrollRect 变量 scrollView.pageIndicatorText = count; // 设置 TextMeshProUGUI 变量 scrollView.swipeThreshold = 200f; // 设置 swipeThreshold 变量 scrollView.snapSpeed = 10f; // 设置 snapSpeed 变量 scrollView.threshold = 100f; scrollView.InitAfterMainScriptStarts(); TextMeshProUGUI name = buttonObj.transform.Find("暱稱")?.GetComponent(); TextMeshProUGUI place = buttonObj.transform.Find("地點")?.GetComponent(); TextMeshProUGUI time = buttonObj.transform.Find("時間")?.GetComponent(); TextMeshProUGUI detail = buttonObj.transform.Find("內容")?.GetComponent(); Image radio = buttonObj.transform.Find("顯示錄音")?.GetComponent(); TextMeshProUGUI rtime = radio.transform.Find("時間")?.GetComponent(); Button bt = radio.transform.Find("按鈕")?.GetComponent