123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437 |
- 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<GameObject> posts = new List<GameObject>(); // 已生成的贴文列表
- 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<CanvasScaler>();
- }
- 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<RectTransform>().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<UniWebView>();
- 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>(); // 获取 RectTransform
- Vector2 panelSizeDelta = panelRectTransform.sizeDelta; // 获取大小
- 總高 += panelSizeDelta.y; // 加总大小
- }
- RectTransform contentRectTransform = buttonParent1.GetComponent<RectTransform>();
- 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<ScrollRect>();
- RectTransform content = scroll.content;
- Image copy = content.Find("圖")?.GetComponent<Image>();
- 圖片資料庫名稱=貼文.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<TextMeshProUGUI>();
-
- PhotoScrollView scrollView = scroll.AddComponent<PhotoScrollView>();
- 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>();
- TextMeshProUGUI place = buttonObj.transform.Find("地點")?.GetComponent<TextMeshProUGUI>();
- TextMeshProUGUI time = buttonObj.transform.Find("時間")?.GetComponent<TextMeshProUGUI>();
- TextMeshProUGUI detail = buttonObj.transform.Find("內容")?.GetComponent<TextMeshProUGUI>();
- Image radio = buttonObj.transform.Find("顯示錄音")?.GetComponent<Image>();
- TextMeshProUGUI rtime = radio.transform.Find("時間")?.GetComponent<TextMeshProUGUI>();
- Button bt = radio.transform.Find("按鈕")?.GetComponent<Button>();
- Slider timeSlider = radio.transform.Find("時間軸")?.GetComponent<Slider>();
- Button bt1 = buttonObj.transform.Find("刪除")?.GetComponent<Button>();
- int iii = i;
- bt1.onClick.AddListener(() =>
- {
- 預刪除單號=貼文.Rows[iii][0].ToString();
- 貼文面.SetActive(false);
- 刪除面板.SetActive(true);
- });
-
- name.text =Main.Global.使用者暱稱;
- place.text=貼文.Rows[i][9].ToString()+貼文.Rows[i][10].ToString();
- time.text=ConvertToCustomFormat(貼文.Rows[i][1].ToString());
- float contentHeight = 0f;
- if (貼文.Rows[i][8].ToString() != "")
- {
- radio.gameObject.SetActive(true);
- AudioPlayer audio = buttonObj.AddComponent<AudioPlayer>();
- audio.timeText = rtime;
- audio.progressBar = timeSlider;
- audio.playPauseButton = bt;
- audio.playSprite = playSprite;
- audio.pauseSprite = pauseSprite;
- SQL_game_sys.SQL_讀取錄音(貼文.Rows[i][0].ToString());
- if (SQL_Module.dr.Read())
- {
- byte[] imageData = (byte[])SQL_Module.dr["錄音檔"];
- audio.LoadAudioClip(imageData);
- }
-
- if (貼文.Rows[i][2].ToString() != "")
- {
- RectTransform contentRectTransform = detail.rectTransform;
- contentRectTransform.anchoredPosition += new Vector2(0, -100);
- }
- contentHeight += 100f;
- }
- else
- {
- radio.gameObject.SetActive(false);
- }
- if (貼文.Rows[i][2].ToString() != "")
- {
- detail.gameObject.SetActive(true);
- detail.text =貼文.Rows[i][2].ToString();
- contentHeight += detail.preferredHeight;
- }
- else
- {
- detail.gameObject.SetActive(false);
- }
- RectTransform panelRectTransform = buttonObj.GetComponent<RectTransform>();
- RectTransform parentRectTransform = 貼文面.GetComponent<RectTransform>();
-
- // 获取当前预制体的大小
- Vector2 panelSizeDelta = panelRectTransform.sizeDelta;
-
- // 将预制体的大小设置为与父对象一样宽,高度增加 contentHeight
- panelRectTransform.sizeDelta = new Vector2(parentRectTransform.rect.width, panelSizeDelta.y + contentHeight);
-
- // 设置 anchoring 和 pivot,使得预制体顶部对齐父对象的顶部
- panelRectTransform.anchorMin = new Vector2(0, 1);
- panelRectTransform.anchorMax = new Vector2(1, 1);
- panelRectTransform.pivot = new Vector2(0.5f, 1);
- // 将生成的贴文添加到列表中
- if (首位)
- {
- buttonObj.transform.SetAsFirstSibling();
- posts.Insert(0, buttonObj);
- }
- else
- {
- posts.Add(buttonObj);
- buttonObj.transform.SetAsLastSibling();
- }
-
- }
-
- // 卸载贴文
- void RemovePost(bool 首位)
- {
-
- if (首位)
- {
- int lastIndex = posts.Count - 1;
- RectTransform panelRectTransform = posts[lastIndex].GetComponent<RectTransform>(); // 获取 RectTransform
- Vector2 panelSizeDelta = panelRectTransform.sizeDelta;
-
- Destroy(posts[lastIndex]); // 销毁末位的游戏对象
- posts.RemoveAt(lastIndex);
- Vector2 newPosition = buttonscroll1.content.anchoredPosition;
- newPosition.y += panelSizeDelta.y;
- buttonscroll1.content.anchoredPosition = newPosition;
- }
- else
- {
- RectTransform panelRectTransform = posts[0].GetComponent<RectTransform>(); // 获取 RectTransform
- Vector2 panelSizeDelta = panelRectTransform.sizeDelta;
-
- Destroy(posts[0]); // 销毁首位的游戏对象
- posts.RemoveAt(0);
-
- Vector2 newPosition = buttonscroll1.content.anchoredPosition;
- newPosition.y -= panelSizeDelta.y;
- buttonscroll1.content.anchoredPosition = newPosition;
- }
- }
-
- // 获取总贴文数量
- int GetTotalPostsCount()
- {
- // 这里需要根据实际情况获取贴文的总数
- return 貼文.Rows.Count;
- }
- string FormatTime(float time)
- {
- // 格式化時間
- int minutes = Mathf.FloorToInt(time / 60);
- int seconds = Mathf.FloorToInt(time % 60);
- return string.Format("{0:00}:{1:00}", minutes, seconds);
- }
- private string ConvertToCustomFormat(string dateTimeString)
- {
- // 解析年、月、日、时、分、秒
- string year = dateTimeString.Substring(0, 4);
- string month = dateTimeString.Substring(4, 2);
- string day = dateTimeString.Substring(6, 2);
- string hour = dateTimeString.Substring(9, 2);
- string minute = dateTimeString.Substring(11, 2);
- string second = dateTimeString.Substring(13, 2);
-
- // 使用解析的部分来构建所需的日期时间格式
- string formattedDateTime = $"{year}/{month}/{day}-{hour}:{minute}:{second}";
-
- return formattedDateTime;
- }
- private void 圖片讀取(string 單號, Image copy, RectTransform content, ScrollRect 滾動框)
- {
- DataSet ds1 = new();
- SQL_game_sys.SQL_讀取圖片(單號);
- SQL_Module.da.Fill(ds1);
- DataTable data = ds1.Tables[0];
- float sum = 0;
- if (data.Rows.Count > 1)
- {
- 滾動框.horizontal = true;
- }
- else
- {
- 滾動框.horizontal = false;
- }
- for (int i = 0; i < data.Rows.Count; i++)
- {
- GameObject buttonObj = Instantiate(copy.gameObject) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(sum, 0);
- buttonObj.GetComponent<RectTransform>().sizeDelta = new Vector2(滾動框.GetComponent<RectTransform>().rect.width, buttonObj.GetComponent<RectTransform>().sizeDelta.y);
- buttonObj.transform.SetParent(content, false);
- RawImage image = buttonObj.GetComponentInChildren<RawImage>();
- byte[] imageData = (byte[])data.Rows[i][1];
- Texture2D texture = new Texture2D(1, 1);
- texture.LoadImage(imageData);
- image.texture = texture;
- if (texture.width > texture.height)
- {
- // 照片的寬度大於高度,按照寬度等比例縮放
- float scaleFactor = 滾動框.GetComponent<RectTransform>().rect.width / texture.width;
- image.rectTransform.sizeDelta = new Vector2(滾動框.GetComponent<RectTransform>().rect.width, texture.height * scaleFactor);
- }
- else
- {
- // 照片的高度大於寬度,按照高度等比例縮放
- float scaleFactor = 滾動框.GetComponent<RectTransform>().rect.width / texture.height;
- image.rectTransform.sizeDelta = new Vector2(texture.width * scaleFactor, 880);
- }
- sum += 滾動框.GetComponent<RectTransform>().rect.width;
- }
- content.sizeDelta = new Vector2(sum, content.sizeDelta.y);
-
- }
-
- public async void SignInWithGoogle()
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text="";
- try
- {
- GoogleSignIn.Configuration = new GoogleSignInConfiguration
- {
- WebClientId = WebUrl,
- RequestIdToken = true
- };
- var googlesigntask = GoogleSignIn.DefaultInstance.SignIn();
- await googlesigntask;
- if (googlesigntask.IsFaulted)
- {
- return;
- }
- else
- {
- GoogleSignInUser signInUser = googlesigntask.Result;
- string googleIdToken = signInUser.IdToken;
- string googleAccessToken = signInUser.AuthCode;
- string rdpassword = GenerateRandomPassword();
- string password = await CheckAndRegister_google(rdpassword);
- string res = await firebaseManager.Google登入(googleIdToken, googleAccessToken,password);
- if (res[..1] =="0")
- {
- 查詢暱稱();
- }
- else if (res[..1] =="1")
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text=res[2..];
- }
- }
- }
- catch (Exception ex)
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text=ex.Message;
- GoogleSignIn.DefaultInstance?.SignOut();
- }
- }
- public async void 登入(){
- //SQL_game_sys.SQL_使用者_是否APPLE登入(密碼.text);
- //if(SQL_Module.dr.Read()){
- // string str;
- // if(SQL_Module.dr[0].ToString()=="True"){
- // str = SQL_Module.dr[1].ToString();
- // }else{
- // str = 密碼.text+"@gcmsmart.com";
- // }
- // Debug.Log(str);
- // string res = await firebaseManager.登入(str,密碼.text);
- // if (res[..1] =="0"){
- // 查詢暱稱();
- // }
- // else if (res[..1] =="1"){
- // 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text=res[2..];
- // }
- //}
- string str = 密碼.text+"@gcmsmart.com";
- string res = await firebaseManager.登入(str, 密碼.text);
- if (res[..1] =="0")
- {
- 查詢暱稱();
- }
- else if (res[..1] =="1")
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text=res[2..];
- }
- }
- public void ID登入()
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text="";
- 密碼.text="";
- 登入1.SetActive(false);
- 登入2.SetActive(true);
- }
- public void ID登入Y()
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text="";
- if (密碼.text != "")
- {
- SQL_game_sys.SQL_使用者_重複搜尋(密碼.text);
- if (SQL_Module.dr.Read())
- {
- 登入();
- }
- else
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text="查無ID";
- }
-
- }
- else
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text="未輸入ID";
- }
- }
- public void ID登入N()
- {
- 登入1.SetActive(true);
- 登入2.SetActive(false);
- }
- public async void 註冊()
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text="";
- string randomPassword = GenerateRandomPassword();
- Debug.Log(randomPassword);
- string res = await CheckAndRegister(randomPassword);
- if (res[..1] =="0")
- {
- 查詢暱稱();
- }
- else if (res[..1] =="1" || res[..1] =="2")
- {
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text=res[2..];
- }
-
- }
-
- public string GenerateRandomPassword()
- {
- const string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
- var random = new System.Random();
- var password = new string(Enumerable.Repeat(chars, 10)
- .Select(s => s[random.Next(s.Length)]).ToArray());
- return password;
- }
- public async Task<string> CheckAndRegister(string password)
- {
- // 檢查密碼是否已存在
- SQL_game_sys.SQL_使用者_重複搜尋(password);
- if (SQL_Module.dr.Read())
- {
- // 如果密碼已存在,則生成新的密碼並進行檢查
- return await CheckAndRegister(GenerateRandomPassword());
- }
- else
- {
- string email = password + "@gcmsmart.com"; // 使用密碼作為電子郵件地址的一部分
- return await firebaseManager.Register(email, password);
- }
- }
- public async Task<string> CheckAndRegister_google(string password)
- {
- // 檢查密碼是否已存在
- SQL_game_sys.SQL_使用者_重複搜尋(password);
- if (SQL_Module.dr.Read())
- {
- // 如果密碼已存在,則生成新的密碼並進行檢查
- return await CheckAndRegister_google(GenerateRandomPassword());
- }
- else
- {
-
- return password;
- }
- }
- public void 登出使用者()
- {
- 編輯頁1.SetActive(false);
- 編輯頁2.SetActive(true);
- 編輯文字.text="是否要登出?";
- 編輯判斷 = "登出";
- }
- public async void 刪除使用者()
- {
- 編輯頁1.SetActive(false);
- 編輯頁2.SetActive(true);
- 編輯文字.text="是否要刪除?";
- 編輯判斷 = "刪除";
- }
- private void 查詢暱稱()
- {
- SQL_game_sys.SQL_使用者_查詢暱稱(firebaseManager.user.UserId);
- if (SQL_Module.dr.Read())
- {
- 姓名.text=SQL_Module.dr["暱稱"].ToString();
- 電話.text=SQL_Module.dr["電話"].ToString();
- 地址.text=SQL_Module.dr["地址"].ToString();
- UID.text=SQL_Module.dr["驗證碼"].ToString();
- if (SQL_Module.dr["暱稱"].ToString() == "" || SQL_Module.dr["電話"].ToString() == "" || SQL_Module.dr["地址"].ToString() == "")
- {
- 檢查 =false;
-
- }
- else
- {
- 檢查 =true;
- }
- Debug.Log(檢查);
- if (SQL_Module.dr["GOOGLE登入"].ToString() == "False")
- {
- 綁定紐.interactable=true;
- }
- else
- {
- 綁定紐.interactable=false;
- }
- Main.Global.使用者暱稱=SQL_Module.dr["暱稱"].ToString();
- Main.Global.使用者ID=SQL_Module.dr["驗證碼"].ToString();
- Main.Global.使用者UID=SQL_Module.dr["使用者UID"].ToString();
- if (SQL_Module.dr["重設密碼"].ToString() == "False")
- {
- 綁定紐.interactable=true;
- }
- else
- {
- 綁定紐.interactable=false;
- }
- }
- }
- public void 使用者_顯示資料(){
- Debug.Log(firebaseManager.user.UserId);
- Debug.Log(firebaseManager.user.Email);
- 信箱_lb.text = firebaseManager.user.Email;
- }
- public void 使用者_修改暱稱(){
- 編輯頁1.SetActive(false);
- 編輯頁2.SetActive(true);
- 編輯文字.text="是否要修改?";
- 編輯判斷 = "修改";
-
- }
- public void 修改暱稱返回()
- {
- 編輯頁1.SetActive(true);
- 編輯頁2.SetActive(false);
- 編輯頁3.SetActive(false);
- }
- public void 使用者_ID綁定(){
- 編輯頁1.SetActive(false);
- 編輯頁2.SetActive(true);
- 編輯文字.text="是否要綁定ID?";
- 編輯判斷 = "ID綁定";
- }
- public async void 編輯是(){
- if (編輯判斷 == "修改"){
- 讀取面板.SetActive(true);
- SQL_game_sys.SQL_使用者_修改暱稱(firebaseManager.user.UserId, 姓名.text, 電話.text, 地址.text);
- 查詢暱稱();
- 編輯頁1.SetActive(true);
- 編輯頁2.SetActive(false);
- 編輯文字.text="";
- 編輯判斷 = "";
- 讀取面板.SetActive(false);
- }else if (編輯判斷 == "登出"){
- firebaseManager.登出();
- #if UNITY_ANDROID && !UNITY_EDITOR
- GoogleSignIn.DefaultInstance?.SignOut();
- #endif
-
- }
- else if (編輯判斷 == "刪除"){
- 讀取面板.SetActive(true);
- SQL_game_sys.SQL_使用者_刪除(firebaseManager.user.UserId);
- DataSet ds = new();
- SQL_game_sys.SQL_使用者_查詢貼文(firebaseManager.user.UserId);
- SQL_Module.da.Fill(ds);
- DataTable 貼文 = ds.Tables[0];
- for (int i = 0; i<貼文.Rows.Count; i++){
- string str = 貼文.Rows[i][0].ToString();
- 圖片資料庫名稱=貼文.Rows[i][12].ToString();
- 錄音資料庫名稱=貼文.Rows[i][13].ToString();
- SQL_CommString.SQL_連線字串_錄音_SQL(Main.Global.伺服器, 錄音資料庫名稱);
- SQL_CommString.SQL_連線字串_圖片_SQL(Main.Global.伺服器, 圖片資料庫名稱);
- SQL_game_sys.SQL_使用者_刪除圖片(str);
- SQL_game_sys.SQL_使用者_刪除錄音(str);
- }
- SQL_game_sys.SQL_使用者_刪除所有貼文(firebaseManager.user.UserId);
- string res = await firebaseManager.刪除使用者();
- if (res[..1] =="0"){}else if (res[..1] =="1"){
- 錯誤訊息2_lb.SetActive(true);
- 錯誤訊息2_lb.GetComponent<TextMeshProUGUI>().text=res[2..];
- }
- 讀取面板.SetActive(false);
- 編輯頁.SetActive(false);
- }
- else if(編輯判斷=="ID綁定"){
- SQL_game_sys.SQL_使用者重設密碼(firebaseManager.user.UserId);
- if (SQL_Module.dr.Read())
- {
- if (SQL_Module.dr[0].ToString()=="False")
- {
- string res = await firebaseManager.重設EMAIL(Main.Global.使用者ID+"@gcmsmart.com");
- firebaseManager.重設密碼(Main.Global.使用者ID);
- SQL_game_sys.SQL_使用者重設密碼完畢(firebaseManager.user.UserId);
- }
- }
- 編輯頁1.SetActive(true);
- 編輯頁2.SetActive(false);
- 編輯文字.text="";
- 編輯判斷 = "";
- 查詢暱稱();
- }
- }
- public void 輸入確認()
- {
- if (初姓名.text != "" && 初電話.text != "" && 初地址.text != "" )
- {
- 登入頁.SetActive(false);
- 主畫面.SetActive(true);
- 下排紐.SetActive(true);
- 編輯_pl.SetActive(true);
- 新增_pl.SetActive(false);
- 首頁_pl.SetActive(true);
- 輸入面.SetActive(false);
- SQL_game_sys.SQL_使用者_修改暱稱(firebaseManager.user.UserId, 初姓名.text, 初電話.text, 初地址.text);
- 查詢暱稱();
- }
- else
- {
- 輸入1.SetActive(false);
- 輸入2.SetActive(true);
- 輸入問題.text ="輸入資訊皆不能為空白";
- }
- }
- public void 再次輸入()
- {
- 輸入1.SetActive(true);
- 輸入2.SetActive(false);
- }
- public void 刪除是(){
- 讀取面板.SetActive(true);
- 貼文面.SetActive(true);
- SQL_game_sys.SQL_使用者_刪除貼文(預刪除單號);
- SQL_game_sys.SQL_使用者_刪除圖片(預刪除單號);
- SQL_game_sys.SQL_使用者_刪除錄音(預刪除單號);
- 初始貼文讀取();
- 讀取面板.SetActive(false);
- 刪除面板.SetActive(false);
- }
- public void 刪除否(){
- 貼文面.SetActive(true);
- 刪除面板.SetActive(false);
- 預刪除單號="";
- }
- public void 編輯否(){
- 編輯頁1.SetActive(true);
- 編輯頁2.SetActive(false);
- 編輯文字.text="";
- 編輯判斷 = "";
- }
- public void 開啟編輯(){
- 編輯頁.SetActive(true);
- 查詢暱稱();
- 編輯頁1.SetActive(true);
- 編輯頁2.SetActive(false);
- 主畫面.SetActive(false);
- 編輯文字.text="";
- 編輯判斷 = "";
- 編輯_pl.SetActive(true);
- 新增_pl.SetActive(false);
- 首頁_pl.SetActive(true);
- }
- public void 回主畫面(){
- 編輯頁.SetActive(false);
- 編輯文字.text="";
- 編輯判斷 = "";
- 貼文面.SetActive(false);
- 主畫面.SetActive(true);
- 介紹面.SetActive(false);
- 編輯_pl.SetActive(true);
- 新增_pl.SetActive(false);
- 首頁_pl.SetActive(true);
- 介紹 = "";
- Main.Global.回貼 =false;
- if (webView1 != null)
- {
- Destroy(webView1.gameObject);
- }
- }
- public void 介紹1()
- {
- 主畫面.SetActive(false);
- 介紹面.SetActive(true);
- 介紹 = "協會";
- for (int i = 0; i < 網頁.Rows.Count; i++)
- {
- if (網頁.Rows[i][0].ToString()=="協會")
- {
- 家網頁(網頁.Rows[i][1].ToString());
- }
- }
- 編輯_pl.SetActive(false);
- 新增_pl.SetActive(false);
- 首頁_pl.SetActive(true);
- }
- public void 介紹2()
- {
- 主畫面.SetActive(false);
- 介紹面.SetActive(true);
- 介紹 = "行動";
- for (int i = 0; i < 網頁.Rows.Count; i++)
- {
- if (網頁.Rows[i][0].ToString()=="行動")
- {
- 家網頁(網頁.Rows[i][1].ToString());
- }
- }
- 編輯_pl.SetActive(false);
- 新增_pl.SetActive(false);
- 首頁_pl.SetActive(true);
- }
- public void 介紹3()
- {
- 主畫面.SetActive(false);
- 介紹面.SetActive(true);
- 介紹 = "分解菌";
- for (int i = 0; i < 網頁.Rows.Count; i++)
- {
- if (網頁.Rows[i][0].ToString()=="分解菌")
- {
- 家網頁(網頁.Rows[i][1].ToString());
- }
- }
- 編輯_pl.SetActive(false);
- 新增_pl.SetActive(false);
- 首頁_pl.SetActive(true);
- }
-
- public void 開啟貼文()
- {
- Main.Global.回貼 =true;
- 貼文面.SetActive(true);
- 主畫面.SetActive(false);
- 編輯_pl.SetActive(false);
- 新增_pl.SetActive(true);
- 首頁_pl.SetActive(true);
- 初始貼文讀取();
- }
- public void 新增貼文(){
- Main.change_Secen(1);
- }
- public void 快速前往()
- {
- string url = "https://play.google.com/store/apps/details?id=com.gcmsmart.sfj"; // 简单示例中使用相同的URL,你可以根据需要修改为不同的URL
- Application.OpenURL(url);
- }
- void AuthStateChanged(object sender, System.EventArgs eventArgs)
- {
- if (firebaseManager.user == null)
- {
- currentIndex = 1;
- if (posts != null)
- {
- DeletetextCopies(posts);
- }
- UID.text="";
- 姓名.text="";
- 電話.text="";
- 地址.text="";
- 檢查 = false;
- Main.Global.使用者暱稱="";
- Main.Global.使用者ID="";
- Main.Global.使用者UID="";
- 登入頁.SetActive(true);
- 主畫面.SetActive(false);
- 登入1.SetActive(true);
- 登入2.SetActive(false);
- 編輯頁.SetActive(false);
- 下排紐.SetActive(false);
- }
- else
- {
- UID.text="";
- 姓名.text="";
- 電話.text="";
- 地址.text="";
- 讀取面板.SetActive(true);
- 查詢暱稱();
-
- if (檢查)
- {
- 登入頁.SetActive(false);
- 主畫面.SetActive(true);
- 下排紐.SetActive(true);
- 編輯_pl.SetActive(true);
- 新增_pl.SetActive(false);
- 首頁_pl.SetActive(true);
- }
- else
- {
- 登入頁.SetActive(false);
- 主畫面.SetActive(false);
- 輸入面.SetActive(true);
- 輸入1.SetActive(true);
- 輸入2.SetActive(false);
- 初姓名.text = "";
- 初電話.text = "";
- 初地址.text = "";
- 下排紐.SetActive(false);
- }
- Main.Global.使用者UID=firebaseManager.user.UserId;
- 讀取日期();
- string newsURL = "https://www.moa.gov.tw/theme_list.php?theme=news&sub_theme=agri";
- string playlistId = "PL9GjONJu_nMKBwF1g5Uu67qqMiyvwJD94";
- string apiKey = "AIzaSyBx8We1GYl75q5d4yZIaeBA7NcZkNHiByA";
- StartCoroutine(GetPlaylistVideos(playlistId, apiKey));
- StartCoroutine(LoadNews(newsURL));
- 讀取面板.SetActive(false);
- if (Main.Global.回貼)
- {
- 開啟貼文();
- }
-
- }
- }
- IEnumerator GetPlaylistVideos(string playlistId, string apiKey)
- {
- string url = $"https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={playlistId}&key={apiKey}&maxResults=5";
-
- UnityWebRequest request = UnityWebRequest.Get(url);
- yield return request.SendWebRequest();
-
- if (request.result == UnityWebRequest.Result.Success)
- {
- string json = request.downloadHandler.text;
- JSONNode response = JSON.Parse(json);
-
- JSONArray items = response["items"].AsArray;
- int i = 0;
- foreach (JSONNode item in items)
- {
- string title = item["snippet"]["title"].Value;
- if (title == "Deleted video" || title == "Private video")
- {
- continue; // 跳过已删除的视频
- }
- string videoId = item["snippet"]["resourceId"]["videoId"].Value;
- //string thumbnailUrl = item["snippet"]["thumbnails"]["default"]["url"].Value;
- 氣象標題[i].text = title;
- 氣象按鈕[i].onClick.AddListener(() => OpenWebPage1(videoId));
- i++;
- if (i >= 5)
- {
- break; // 达到5个视频项时退出循环
- }
- }
- while (i < 5 && response["nextPageToken"] != null)
- {
- // 继续请求下一页数据
- string nextPageToken = response["nextPageToken"].Value;
- url = $"https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={playlistId}&key={apiKey}&maxResults=5&pageToken={nextPageToken}";
- UnityWebRequest nextRequest = UnityWebRequest.Get(url);
- yield return nextRequest.SendWebRequest();
-
- if (nextRequest.result == UnityWebRequest.Result.Success)
- {
- string nextPageJson = nextRequest.downloadHandler.text;
- JSONNode nextPageResponse = JSON.Parse(nextPageJson);
- JSONArray nextPageItems = nextPageResponse["items"].AsArray;
-
- // 继续读取视频信息
- foreach (JSONNode item in nextPageItems)
- {
- string title = item["snippet"]["title"].Value;
- if (title == "Deleted video" || title == "Private video")
- {
- continue; // 跳过已删除的视频
- }
- string videoId = item["snippet"]["resourceId"]["videoId"].Value;
- //string thumbnailUrl = item["snippet"]["thumbnails"]["default"]["url"].Value;
- 氣象標題[i].text = title;
- 氣象按鈕[i].onClick.AddListener(() => OpenWebPage1(videoId));
- i++;
- if (i >= 5)
- {
- break; // 达到5个视频项时退出循环
- }
- }
- }
- else
- {
- Debug.LogError("Failed to fetch next page of playlist videos. Error: " + nextRequest.error);
- break; // 如果请求失败,则退出循环
- }
- }
- }
- else
- {
- Debug.LogError("Failed to fetch playlist videos. Error: " + request.error);
- }
- }
- IEnumerator LoadNews(string url)
- {
- UnityWebRequest request = UnityWebRequest.Get(url);
- yield return request.SendWebRequest();
-
- if (request.result == UnityWebRequest.Result.Success)
- {
- string htmlContent = request.downloadHandler.text;
-
- // 加载 HTML 内容到 HtmlDocument
- HtmlDocument doc = new HtmlDocument();
- doc.LoadHtml(htmlContent);
- // 解析新闻信息
- ParseNews(doc);
- }
- else
- {
- Debug.LogError("Failed to load news. Error: " + request.error);
- }
- }
-
- void ParseNews(HtmlDocument doc)
- {
- var newsNodes = doc.DocumentNode.SelectNodes("//tbody/tr");
- if (newsNodes != null)
- {
- int i = 0;
- foreach (var node in newsNodes.Take(5)) // 只获取前5条新闻
- {
- var dateNode = node.SelectSingleNode(".//td[@data-title='發布日期']");
- var titleNode = node.SelectSingleNode(".//td[@data-title='標題']//a");
-
- if (dateNode != null && titleNode != null)
- {
- string date = dateNode.InnerText.Trim();
- string title = titleNode.InnerText.Trim();
- string href = titleNode.Attributes["href"].Value;
- // 从链接中提取出新闻 ID
- string id = ExtractIDFromURL(href);
- 新聞標題[i].text =title;
- 新聞日期[i].text =date;
- 新聞按鈕[i].onClick.AddListener(() => OpenWebPage(id));
- }
- i+=1;
- }
- }
- }
- void OpenWebPage1(string id)
- {
- // 根据索引打开对应的网页
- string url = "https://www.youtube.com/watch?v="+id; // 简单示例中使用相同的URL,你可以根据需要修改为不同的URL
- //Application.OpenURL(url);
- 家網頁(url);
- 主畫面.SetActive(false);
- 介紹面.SetActive(true);
- 編輯_pl.SetActive(false);
- 新增_pl.SetActive(false);
- 首頁_pl.SetActive(true);
- }
- void OpenWebPage(string id)
- {
- // 根据索引打开对应的网页
- string url = "https://www.moa.gov.tw/theme_data.php?theme=news&sub_theme=agri&id="+id; // 简单示例中使用相同的URL,你可以根据需要修改为不同的URL
- //Application.OpenURL(url);
- 家網頁(url);
- 主畫面.SetActive(false);
- 介紹面.SetActive(true);
- 編輯_pl.SetActive(false);
- 新增_pl.SetActive(false);
- 首頁_pl.SetActive(true);
- }
- private string ExtractIDFromURL(string url)
- {
- // 使用 '/' 符号分割 URL
- string[] parts = url.Split('/');
- // 使用 '=' 符号分割最后一部分,取得 ID 部分
- string[] idParts = parts.Last().Split('=');
- // 返回 ID
- return idParts.Last();
- }
- private void 讀取日期()
- {
- DateTime currentDate = DateTime.Now;
- 今日日期.text = string.Format("今天是 {0} 年 {1:00} 月 {2:00} 日,{3}", currentDate.Year, currentDate.Month, currentDate.Day, currentDate.ToString("dddd"));
-
- Lunar.Lunar lunar = Lunar.Lunar.FromDate(currentDate);
- string 物侯 = lunar.WuHou;
- string 幾侯 = lunar.Hou;
- // 組合農曆日期
- string lunarDate = $"{lunar.YearInGanZhi}年{lunar.MonthInChinese}月{lunar.DayInChinese}";
-
- // 獲取宜忌、冲煞、節氣
- string yi = GetListText(lunar.DayYi);
- string ji = GetListText(lunar.DayJi);
-
- string 冲干支 = lunar.DayChongGan +lunar.DayChong;
- string 冲生肖 = lunar.DayChongShengXiao;
- string age = Main.Global.CalculateAge(lunar.YearInGanZhi, 冲干支);
-
- string shac = lunar.DaySha;
- Lunar.JieQi asd = lunar.GetPrevJieQi(true);
- 農曆日期.text =$"農曆 {lunarDate}";
- 沖煞.text = $"冲 {冲生肖}({age}) 煞 {shac}方";
- 宜.text = $"{yi}";
- 忌.text = $"{ji}";
- 節氣.text = $"{asd}•{物侯}";
- 侯.text = $"{幾侯}";
-
- }
-
- string GetListText(List<string> list)
- {
- string result = "";
- foreach (string item in list)
- {
- result += item + " ";
- }
- return result;
- }
-
- public void 強制登出()
- {
- firebaseManager.登出();
- 讀取面板.SetActive(false);
- }
- private void 初始貼文讀取()
- {
- if (posts != null)
- {
- DeletetextCopies(posts);
- }
- DataSet ds = new();
- SQL_game_sys.SQL_使用者_查詢貼文(Main.Global.使用者UID);
- SQL_Module.da.Fill(ds);
- 貼文 = ds.Tables[0];
- currentIndex = 1;
- if (GetTotalPostsCount() < 3)
- {
- 讀取貼文();
- }
- else
- {
- 總高=0;
- for (int i = 0; i < 3 && i < GetTotalPostsCount(); i++)
- {
- CreatePost(i, false);
- }
- post計算();
- buttonscroll1.onValueChanged.AddListener(OnScrollValueChanged);
- }
- Vector2 newPosition = buttonscroll1.content.anchoredPosition;
- newPosition.y = 0f;
- buttonscroll1.content.anchoredPosition = newPosition;
- }
- private void 讀取貼文()
- {
- float sum = 0;
- for (int i = 0; i<貼文.Rows.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, -sum);
- buttonObj.transform.SetParent(buttonParent1, false);
- ScrollRect scroll = buttonObj.transform.Find("相片")?.GetComponent<ScrollRect>();
- RectTransform content = scroll.content;
- Image copy = content.Find("圖")?.GetComponent<Image>();
- 圖片資料庫名稱=貼文.Rows[i][12].ToString();
- 錄音資料庫名稱=貼文.Rows[i][13].ToString();
- Debug.Log(圖片資料庫名稱);
- Debug.Log(錄音資料庫名稱);
- 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<TextMeshProUGUI>();
- PhotoScrollView scrollView = scroll.AddComponent<PhotoScrollView>();
- 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>();
- TextMeshProUGUI place = buttonObj.transform.Find("地點")?.GetComponent<TextMeshProUGUI>();
- TextMeshProUGUI time = buttonObj.transform.Find("時間")?.GetComponent<TextMeshProUGUI>();
- TextMeshProUGUI detail = buttonObj.transform.Find("內容")?.GetComponent<TextMeshProUGUI>();
- Image radio = buttonObj.transform.Find("顯示錄音")?.GetComponent<Image>();
- TextMeshProUGUI rtime = radio.transform.Find("時間")?.GetComponent<TextMeshProUGUI>();
- Button bt = radio.transform.Find("按鈕")?.GetComponent<Button>();
- Slider timeSlider = radio.transform.Find("時間軸")?.GetComponent<Slider>();
- Button bt1 = buttonObj.transform.Find("刪除")?.GetComponent<Button>();
- int iii = i;
- bt1.onClick.AddListener(() =>
- {
- 預刪除單號=貼文.Rows[iii][0].ToString();
- 貼文面.SetActive(false);
- 刪除面板.SetActive(true);
- });
- name.text =Main.Global.使用者暱稱;
- place.text=貼文.Rows[i][9].ToString()+貼文.Rows[i][10].ToString();
- time.text=ConvertToCustomFormat(貼文.Rows[i][1].ToString());
- float contentHeight = 0f;
- if (貼文.Rows[i][8].ToString() != "")
- {
- radio.gameObject.SetActive(true);
- AudioPlayer audio = buttonObj.AddComponent<AudioPlayer>();
- audio.timeText = rtime;
- audio.progressBar = timeSlider;
- audio.playPauseButton = bt;
- audio.playSprite = playSprite;
- audio.pauseSprite = pauseSprite;
- SQL_game_sys.SQL_讀取錄音(貼文.Rows[i][0].ToString());
- if (SQL_Module.dr.Read())
- {
- byte[] imageData = (byte[])SQL_Module.dr["錄音檔"];
- Debug.Log(SQL_Module.dr["錄音流水號"].ToString());
- audio.LoadAudioClip(imageData);
- }
-
- if (貼文.Rows[i][2].ToString() != "")
- {
- RectTransform contentRectTransform = detail.rectTransform;
- contentRectTransform.anchoredPosition += new Vector2(0, -100);
- }
- contentHeight += 100f;
- }
- else
- {
- radio.gameObject.SetActive(false);
- }
- if (貼文.Rows[i][2].ToString() != "")
- {
- detail.gameObject.SetActive(true);
- detail.text =貼文.Rows[i][2].ToString();
- contentHeight += detail.preferredHeight;
- }
- else
- {
- detail.gameObject.SetActive(false);
- }
- RectTransform panelRectTransform = buttonObj.GetComponent<RectTransform>();
- RectTransform parentRectTransform = 貼文面.GetComponent<RectTransform>();
-
- // 获取当前预制体的大小
- Vector2 panelSizeDelta = panelRectTransform.sizeDelta;
-
- // 将预制体的大小设置为与父对象一样宽,高度增加 contentHeight
- panelRectTransform.sizeDelta = new Vector2(parentRectTransform.rect.width, panelSizeDelta.y + contentHeight);
- Debug.Log(parentRectTransform.rect.width);
- // 设置 anchoring 和 pivot,使得预制体顶部对齐父对象的顶部
- panelRectTransform.anchorMin = new Vector2(0, 1);
- panelRectTransform.anchorMax = new Vector2(1, 1);
- panelRectTransform.pivot = new Vector2(0.5f, 1);
-
- sum+=panelSizeDelta.y + contentHeight;
- posts.Add(buttonObj);
- }
- buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
- }
- void OnDestroy()
- {
- firebaseManager.auth.StateChanged -= AuthStateChanged;
- }
- public void DeletetextCopies(List<GameObject> copy)
- {
- // 刪除複製出來的物件
- foreach (GameObject copys in copy)
- {
- Destroy(copys);
- }
- copy.Clear();
- }
- public void 截圖()
- {
- Main.截圖();
- }
- }
-
|