91 lines
2.9 KiB
C#
91 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using RuntimeData;
|
|
using Logic.Multilingual;
|
|
|
|
[Serializable]
|
|
[CreateAssetMenu(fileName = "LibraryDataAssets", menuName = "TH1 Game Data/Library Data Asset")]
|
|
public class LibraryDataAssets : ScriptableObject
|
|
{
|
|
|
|
public List<LibraryGiantData> LibraryGiantList;
|
|
public List<LibraryWonderData> LibraryWonderList;
|
|
|
|
public bool GetLibraryInfoByGiant(GiantType giant, out LibraryGiantData libraryGiantData)
|
|
{
|
|
// 检查列表是否为空,避免空引用异常
|
|
if (LibraryGiantList == null || LibraryGiantList.Count == 0)
|
|
{
|
|
Debug.LogWarning($"LibraryGiantList is empty or null in {this.name}. Cannot find data for GiantType: {giant}");
|
|
libraryGiantData = null;
|
|
return false;
|
|
}
|
|
// 使用 LINQ 或 foreach 遍历列表查找匹配项
|
|
foreach (var data in LibraryGiantList)
|
|
{
|
|
if (data.GiantType == giant)
|
|
{
|
|
libraryGiantData = data;
|
|
return true; // 找到后立即返回
|
|
}
|
|
}
|
|
// 如果遍历完整个列表都没有找到,则返回 null
|
|
Debug.LogWarning($"No LibraryGiantData found for GiantType: {giant} in {this.name}.");
|
|
libraryGiantData = null;
|
|
return false;
|
|
}
|
|
|
|
public bool GetLibraryInfoByWonder(WonderLibrary wonderLibraryID, out LibraryWonderData data)
|
|
{
|
|
// 检查列表是否为空,避免空引用异常
|
|
if (LibraryWonderList == null || LibraryWonderList.Count == 0)
|
|
{
|
|
Debug.LogWarning($"LibraryWonderList is empty or null in {this.name}. Cannot find data for WonderLibraryID: {wonderLibraryID}");
|
|
data = null;
|
|
return false;
|
|
}
|
|
// 遍历列表查找匹配项
|
|
foreach (var wonderData in LibraryWonderList)
|
|
{
|
|
if (wonderData.WonderLibraryID == wonderLibraryID)
|
|
{
|
|
data = wonderData;
|
|
return true; // 找到后立即返回
|
|
}
|
|
}
|
|
// 如果遍历完整个列表都没有找到,则返回 null
|
|
Debug.LogWarning($"No LibraryWonderData found for WonderLibraryID: {wonderLibraryID} in {this.name}.");
|
|
data = null;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class LibraryGiantData
|
|
{
|
|
public GiantType GiantType;
|
|
[MultilingualField] public string Name;
|
|
[MultilingualField]
|
|
public string Desc;
|
|
[MultilingualField]
|
|
public string Diag;
|
|
public Color DiagColor;
|
|
public Sprite Illust;
|
|
public int AchivePreId;//成就的前缀id
|
|
}
|
|
|
|
[Serializable]
|
|
public class LibraryWonderData
|
|
{
|
|
public WonderLibrary WonderLibraryID;
|
|
[MultilingualField] public List<DiagList> Diags;
|
|
public int AchivePreId;//成就的前缀id
|
|
}
|
|
|
|
[Serializable]
|
|
public class DiagList
|
|
{
|
|
public List<string> Diag;
|
|
public List<GiantType> Giant;
|
|
} |