using System; using System.Collections.Generic; using System.Linq; using Continentis.MainGame.Card; using Continentis.MainGame.UI; using NaughtyAttributes; using SLSFramework.General; using SLSFramework.UModAssistance; using UnityEngine; using UnityEngine.Serialization; #if UNITY_EDITOR using System.IO; using UnityEditor; #endif namespace Continentis.MainGame.Character { [CreateAssetMenu(menuName = "Continentis/MainGame/Character/CharacterData", fileName = "CharacterData")] public partial class CharacterData : ScriptableObject { [Header("Fundamental")] public bool haveCustomClass; public string classFullName; public string modName; public string className; public string displayName; public List tags; public Sprite avatar; public Sprite portrait; public string characterDescription; public string characterStory; [Header("Attributes")] [Tooltip("角色的核心属性:第一栏是属性名,第二栏是属性值")] public SerializableDictionary coreAttributes; [Tooltip("角色的通常属性:第一栏是属性名,第二栏是属性值")] public SerializableDictionary generalAttributes; [Tooltip("初始化时赋予给CurrentGeneralAttributes的属性:第一栏是属性名,第二栏是初始化时使用对应名称的GeneralAttributes的数据,留空则默认为0,如果是float数字则直接使用该数字")] public SerializableDictionary runtimeGeneralAttributes; [Header("View")] public int combatPositionOrder; public GameObject combatCharacterView; [Header("References")] public List prefabRefs = new List(); public List derivativeCardDataRefs = new List(); public List derivativeCharacterDataRefs = new List(); [Tooltip("初始卡组引用列表")] public List initialDeckRef; [Tooltip("HUD信息引用列表")] public List hudDataRefs; } public partial class CharacterData { public static CharacterData Get(string dataID) { return ModManager.GetData(dataID); } } #if UNITY_EDITOR public partial class CharacterData { public void PasteDefaultAttributes() { List targetCollections = new List(); string[] guids = AssetDatabase.FindAssets("t:CharacterAttributesDefaultCollection"); if (guids.Length > 1) { Debug.Log("找到了多个CharacterAttributesDefaultCollection,它们将被合并后导入CharacterData"); } foreach (string guid in guids) { // 将GUID转换为资产的路径 string path = AssetDatabase.GUIDToAssetPath(guid); // 2. 验证每个资产的路径是否完全符合您指定的结构 // 使用 Path.GetDirectoryName 获取文件所在的目录 // 并统一使用'/'作为路径分隔符,以兼容不同操作系统 string directory = Path.GetDirectoryName(path)?.Replace('\\', '/'); Debug.Log($"Checking asset at path: {path}, directory: {directory}"); // 加载资产以检查其命名空间 ScriptableObject collection = AssetDatabase.LoadAssetAtPath(path); Type assetType = collection.GetType(); string assetNamespace = assetType.Namespace; // 检查目录是否有效,是否在"Assets/Mods/"下,并且是否以"/Characters/DefaultCollections"结尾 if (!string.IsNullOrEmpty(directory) && assetNamespace == typeof(CharacterAttributesDefaultCollection).Namespace && directory.StartsWith("Assets/Mods/") && directory.EndsWith("/Characters/DefaultCollections")) { // 3. 如果路径和命名空间都符合要求,则将该资产添加到目标列表中 CharacterAttributesDefaultCollection defaultList = collection as CharacterAttributesDefaultCollection; targetCollections.Add(defaultList); Debug.Log($"Loaded DefaultStringList from: {path}"); } } Dictionary coreAttributes = new Dictionary(); Dictionary generalAttributes = new Dictionary(); Dictionary runtimeGeneralAttributes = new Dictionary(); foreach (CharacterAttributesDefaultCollection collection in targetCollections) { collection.coreAttributes.PasteDictionary(coreAttributes); collection.generalAttributes.PasteDictionary(generalAttributes); collection.runtimeGeneralAttributes.PasteDictionary(runtimeGeneralAttributes); } coreAttributes.PasteDictionary(this.coreAttributes); generalAttributes.PasteDictionary(this.generalAttributes); runtimeGeneralAttributes.PasteDictionary(this.runtimeGeneralAttributes); Debug.Log($"Pasted default attributes to file {this.name}"); } } #endif }