using System; using System.Data; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class Module : MonoBehaviour { public static void 載入表格(string table_name,DataTable table,Transform tableParent,GameObject rowPrefab,GameObject ceneter,TMP_FontAsset myFont,Sprite UIsprite, GameObject LinePrefab,bool overflowMode){ 清除控件(ceneter); Image centerImage = ceneter.GetComponent(); if(centerImage == null){ centerImage = ceneter.AddComponent(); centerImage.type = Image.Type.Sliced; } centerImage.sprite = UIsprite; centerImage.fillCenter = false; centerImage.color = Main.Global.系統主題 == 1 ? new Color(0f, 0f, 0f, 1f) : new Color(1f, 1f, 1f, 1f); //==========動態生成表格================================== for (int i = 0; i < table.Rows.Count; i++){ // 建立資料列 GameObject row = Instantiate(rowPrefab, tableParent); // 設定資料列位置 row.GetComponent().anchoredPosition = new Vector2(0, -90 * i); // 建立資料列中的所有欄位 for (int j = 0; j < table.Columns.Count; j++){ // 取得欄位值 string value = table.Rows[i][j].ToString(); if(string.Equals(value, "true", StringComparison.OrdinalIgnoreCase) || string.Equals(value, "false", StringComparison.OrdinalIgnoreCase)){ Toggle cellText = new GameObject(table_name+"_Cells_"+i.ToString()+"_"+j.ToString()).AddComponent(); cellText.transform.SetParent(row.transform, false); cellText.tag = "Toggle"; Image Background_img = new GameObject("bg"+i.ToString()).AddComponent(); Background_img.transform.SetParent(cellText.transform, false); //Background_img.sprite = Main.Global.sprite_box; Background_img.rectTransform.sizeDelta = new Vector2(100f,70f); Image Check_img = new GameObject("Check"+i.ToString()).AddComponent(); Check_img.transform.SetParent(cellText.transform, false); Check_img.rectTransform.sizeDelta = new Vector2(100f,70f); //Check_img.sprite = Main.Global.sprite_check; cellText.graphic = Check_img; cellText.targetGraphic=Background_img; if(string.Equals(value, "true", StringComparison.OrdinalIgnoreCase)){ cellText.isOn=true; } }else{ GameObject cellText = new(table_name+"_Cells_"+i.ToString()+"_"+j.ToString()); cellText.transform.SetParent(row.transform, false); double number; if (double.TryParse(value, out number) && table_name=="區間"){ string formattedValue = String.Format("{0:###,##0.##}", number); cellText.AddComponent().text = formattedValue; }else{ cellText.AddComponent().text = value; } //cellText.AddComponent().text = value; cellText.GetComponent().tag="Cells"; if(overflowMode){cellText.GetComponent().overflowMode=TextOverflowModes.Ellipsis;} //cellText.AddComponent