重做粗略选曲界面 浮动小游戏可开关
修复一些小bug和加入部分新功能
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class loadDlcListPrefab : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Column
|
||||
{
|
||||
public string columnName;
|
||||
public List<dlcData> dlcList = new List<dlcData>();
|
||||
}
|
||||
|
||||
[Header("À¸Ä¿Áбí")]
|
||||
public List<Column> columns = new List<Column>();
|
||||
|
||||
[Header("UI Ô¤ÖÆÌå")]
|
||||
public GameObject dlc_scContent;
|
||||
public GameObject columnPrefab;
|
||||
public GameObject dlcButtonPrefab;
|
||||
|
||||
void Start()
|
||||
{
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
public void RefreshUI()
|
||||
{
|
||||
if (dlc_scContent == null) return;
|
||||
|
||||
for (int i = dlc_scContent.transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
var c = dlc_scContent.transform.GetChild(i).gameObject;
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying) DestroyImmediate(c);
|
||||
else Destroy(c);
|
||||
#else
|
||||
Destroy(c);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (columns == null) return;
|
||||
|
||||
for (int colIndex = 0; colIndex < columns.Count; colIndex++)
|
||||
{
|
||||
var col = columns[colIndex];
|
||||
|
||||
if (columnPrefab != null)
|
||||
{
|
||||
var headerGO = Instantiate(columnPrefab, dlc_scContent.transform);
|
||||
headerGO.name = "Column_" + colIndex;
|
||||
|
||||
var card = headerGO.GetComponent<columnCardPrefab>();
|
||||
if (card != null && card.columnNameText != null)
|
||||
{
|
||||
card.columnNameText.text = col.columnName ?? "(Unnamed)";
|
||||
}
|
||||
else
|
||||
{
|
||||
var txt = headerGO.transform.Find("ColumnNameText")?.GetComponent<Text>();
|
||||
if (txt != null) txt.text = col.columnName ?? "(Unnamed)";
|
||||
}
|
||||
}
|
||||
|
||||
if (col.dlcList == null) continue;
|
||||
|
||||
for (int entryIndex = 0; entryIndex < col.dlcList.Count; entryIndex++)
|
||||
{
|
||||
var dlc = col.dlcList[entryIndex];
|
||||
if (dlcButtonPrefab == null)
|
||||
{
|
||||
Debug.LogWarning("dlcButtonPrefab is not assigned");
|
||||
break;
|
||||
}
|
||||
|
||||
var itemGO = Instantiate(dlcButtonPrefab, dlc_scContent.transform);
|
||||
itemGO.name = $"DLC_Col{colIndex}_Item{entryIndex}";
|
||||
|
||||
var btn = itemGO.GetComponent<dlcButton>();
|
||||
if (btn != null)
|
||||
{
|
||||
if (dlc != null)
|
||||
{
|
||||
if (btn.dlc_profileImgae != null)
|
||||
{
|
||||
btn.dlc_profileImgae.sprite = dlc.dlc_image;
|
||||
btn.dlc_profileImgae.enabled = dlc.dlc_image != null;
|
||||
}
|
||||
if (btn.dlcName != null) btn.dlcName.text = dlc.dlcName ?? "(Unnamed)";
|
||||
if (btn.dlcID != null) btn.dlcID.text = dlc.dlcID.ToString();
|
||||
if (btn.dlcProducer != null) btn.dlcProducer.text = dlc.dlcProducer ?? "";
|
||||
if (btn.dlcPubliushDate != null) btn.dlcPubliushDate.text = dlc.dlcPublishDate ?? "";
|
||||
if (btn.dlcDescription != null) btn.dlcDescription.text = dlc.dlcDescription ?? "";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (btn.dlcName != null) btn.dlcName.text = "(None)";
|
||||
if (btn.dlcID != null) btn.dlcID.text = "";
|
||||
if (btn.dlc_profileImgae != null) btn.dlc_profileImgae.enabled = false;
|
||||
if (btn.dlcDescription != null) btn.dlcDescription.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var rt = dlc_scContent.GetComponent<RectTransform>();
|
||||
if (rt != null) UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(rt);
|
||||
|
||||
// After all buttons are instantiated, have each dlcButton resolve its dlcData (deferred lookup)
|
||||
var allButtons = dlc_scContent.GetComponentsInChildren<dlcButton>(true);
|
||||
foreach (var b in allButtons)
|
||||
{
|
||||
if (b != null)
|
||||
b.ResolveDlcData();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user