技能主要更新,修复卡顿并加入动画,以及各种其他更新。
This commit is contained in:
@@ -1,31 +1,41 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
public class dlcButton : MonoBehaviour
|
||||
{
|
||||
[Header("基本套件")]
|
||||
[Header("������")]
|
||||
public Image dlc_profileImgae;
|
||||
public Text dlcName;
|
||||
public Text dlcID;
|
||||
public Text dlcProducer;
|
||||
public Text dlcPubliushDate;
|
||||
public Image dlc_nowSelectedImageBoarder;
|
||||
[Header("介绍")]
|
||||
[Header("����")]
|
||||
public Text dlcDescription;
|
||||
|
||||
[Header("DLC SO (可在 Inspector 指定)")]
|
||||
[Header("DLC SO (���� Inspector ָ��)")]
|
||||
public dlcData dlcDataSO;
|
||||
|
||||
[Header("DLC 内容 (运行时会由脚本填充)")]
|
||||
[Header("DLC ���� (����ʱ���ɽű����)")]
|
||||
public List<SongData> dlcContent = new List<SongData>();
|
||||
|
||||
[Header("搜索路径 (编辑器/运行时)")]
|
||||
[Header("����·�� (�༭��/����ʱ)")]
|
||||
public string editorSearchFolder = "Assets/Resources/dlc_dlcIndex";
|
||||
public string runtimeResourcesFolder = "Resources/dlc_dlcIndex";
|
||||
|
||||
private Button _btn;
|
||||
public bool Resolved { get; private set; }
|
||||
|
||||
// Shared cache to avoid repeated Resources.LoadAll scans
|
||||
private static Dictionary<int, dlcData> cachedById = new Dictionary<int, dlcData>();
|
||||
private static List<dlcData> cachedAll = new List<dlcData>();
|
||||
private static bool cacheBuilt = false;
|
||||
private static bool cacheBuilding = false;
|
||||
private static string cachedFolder = string.Empty;
|
||||
|
||||
|
||||
// Selection management (shared across all dlcButton instances)
|
||||
private static List<dlcButton> allButtons = new List<dlcButton>();
|
||||
@@ -206,7 +216,7 @@ public class dlcButton : MonoBehaviour
|
||||
// mark selection first
|
||||
Select();
|
||||
|
||||
var s = GameObject.FindObjectOfType<SongSelectUI>();
|
||||
var s = Object.FindAnyObjectByType<SongSelectUI>();
|
||||
if (s != null)
|
||||
{
|
||||
s.DisplaySongsFromList(dlcContent);
|
||||
@@ -388,41 +398,164 @@ public class dlcButton : MonoBehaviour
|
||||
// Resolve dlcData after all buttons have been instantiated
|
||||
public void ResolveDlcData()
|
||||
{
|
||||
if (Resolved)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StartCoroutine(ResolveDlcDataAsync());
|
||||
}
|
||||
|
||||
public IEnumerator ResolveDlcDataAsync()
|
||||
{
|
||||
if (Resolved)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
Debug.Log($"dlcButton.ResolveDlcData called on '{gameObject.name}'");
|
||||
|
||||
if (dlcDataSO != null)
|
||||
{
|
||||
Debug.Log($"dlcButton: dlcDataSO already assigned on '{gameObject.name}' -> {dlcDataSO.name}");
|
||||
ApplyDlcData(dlcDataSO);
|
||||
return;
|
||||
Resolved = true;
|
||||
yield break;
|
||||
}
|
||||
|
||||
int id = 0;
|
||||
int id;
|
||||
if (!TryGetResolveId(out id))
|
||||
{
|
||||
Debug.LogWarning($"dlcButton.ResolveDlcData: no dlcID text and no name to parse for '{gameObject.name}'");
|
||||
Resolved = true;
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return BuildCacheIfNeeded(runtimeResourcesFolder);
|
||||
|
||||
if (TryResolveFromCache(id))
|
||||
{
|
||||
Resolved = true;
|
||||
yield break;
|
||||
}
|
||||
|
||||
LoadContentBySongIdPrefix(id);
|
||||
Resolved = true;
|
||||
}
|
||||
|
||||
private bool TryGetResolveId(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dlcID != null && int.TryParse(dlcID.text, out id))
|
||||
{
|
||||
Debug.Log($"dlcButton: Resolving by dlcID text {id} for '{gameObject.name}'");
|
||||
LoadDlcDataById(id);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
string goName = gameObject.name;
|
||||
if (!string.IsNullOrEmpty(goName))
|
||||
{
|
||||
var parts = goName.Split('_');
|
||||
int parsed = 0;
|
||||
if (parts.Length > 0 && int.TryParse(parts[0], out parsed))
|
||||
if (parts.Length > 0 && int.TryParse(parts[0], out id))
|
||||
{
|
||||
Debug.Log($"dlcButton: Resolving by GameObject name prefix {parsed} for '{gameObject.name}'");
|
||||
LoadDlcDataById(parsed);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"dlcButton.ResolveDlcData: could not parse id from GameObject name '{goName}'");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryResolveFromCache(int id)
|
||||
{
|
||||
if (!cacheBuilt)
|
||||
{
|
||||
Debug.LogWarning($"dlcButton.ResolveDlcData: no dlcID text and no name to parse for '{gameObject.name}'");
|
||||
return false;
|
||||
}
|
||||
|
||||
dlcData so;
|
||||
if (cachedById.TryGetValue(id, out so) && so != null)
|
||||
{
|
||||
dlcDataSO = so;
|
||||
ApplyDlcData(so);
|
||||
return true;
|
||||
}
|
||||
|
||||
string prefix = id.ToString();
|
||||
for (int i = 0; i < cachedAll.Count; i++)
|
||||
{
|
||||
var item = cachedAll[i];
|
||||
if (item == null) continue;
|
||||
if (item.name.StartsWith(prefix))
|
||||
{
|
||||
dlcDataSO = item;
|
||||
ApplyDlcData(item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string NormalizeResourcesPath(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
string p = path.Replace("\\", "/");
|
||||
int idx = p.IndexOf("Resources/", System.StringComparison.OrdinalIgnoreCase);
|
||||
if (idx >= 0)
|
||||
{
|
||||
p = p.Substring(idx + "Resources/".Length);
|
||||
}
|
||||
return p.Trim('/');
|
||||
}
|
||||
|
||||
private static IEnumerator BuildCacheIfNeeded(string runtimeFolder)
|
||||
{
|
||||
if (cacheBuilt)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
if (cacheBuilding)
|
||||
{
|
||||
while (!cacheBuilt)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
cacheBuilding = true;
|
||||
cachedById.Clear();
|
||||
cachedAll.Clear();
|
||||
cachedFolder = NormalizeResourcesPath(runtimeFolder);
|
||||
|
||||
// allow one frame before heavy load
|
||||
yield return null;
|
||||
|
||||
dlcData[] arr = null;
|
||||
if (!string.IsNullOrEmpty(cachedFolder))
|
||||
{
|
||||
arr = Resources.LoadAll<dlcData>(cachedFolder);
|
||||
}
|
||||
if (arr == null || arr.Length == 0)
|
||||
{
|
||||
arr = Resources.LoadAll<dlcData>("");
|
||||
}
|
||||
|
||||
if (arr != null)
|
||||
{
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
var so = arr[i];
|
||||
if (so == null) continue;
|
||||
cachedAll.Add(so);
|
||||
if (!cachedById.ContainsKey(so.dlcID))
|
||||
{
|
||||
cachedById.Add(so.dlcID, so);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cacheBuilt = true;
|
||||
cacheBuilding = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,26 +10,26 @@ public class dlcData : ScriptableObject
|
||||
[Header("DLC֮ID")]
|
||||
public int dlcID;
|
||||
|
||||
[Header("DLC名称")]
|
||||
[Header("DLC����")]
|
||||
public string dlcName;
|
||||
|
||||
[Header("DLC出品人")]
|
||||
[Header("DLC��Ʒ��")]
|
||||
public string dlcProducer;
|
||||
|
||||
[Header("DLC是否已解锁")]
|
||||
[Header("DLC�Ƿ��ѽ���")]
|
||||
public bool dlcIsUnlocked;
|
||||
|
||||
[Header("DLC简介")]
|
||||
[Header("DLC���")]
|
||||
[TextArea(3,10)]
|
||||
public string dlcDescription;
|
||||
|
||||
[Header("DLC发行日期 yyyy-mm-dd")]
|
||||
[Header("DLC�������� yyyy-mm-dd")]
|
||||
public string dlcPublishDate;
|
||||
|
||||
[Header("DLC所含曲目(ScriptableObjects)")]
|
||||
[Header("DLC������Ŀ��ScriptableObjects��")]
|
||||
public List<SongData> songList = new List<SongData>();
|
||||
|
||||
[Header("本DLC结算音乐")]
|
||||
[Tooltip("在结算界面播放的背景音乐AudioClip")]
|
||||
[Header("��DLC��������")]
|
||||
[Tooltip("�ڽ�����沥�ŵı�������AudioClip")]
|
||||
public AudioClip settlementMusic;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user