Files
Continentis/Assets/Scripts/MainGame/Character/CharacterData/CharacterData.cs

128 lines
5.5 KiB
C#
Raw Normal View History

2025-10-03 00:02:43 -04:00
using System;
using System.Collections.Generic;
2025-10-23 00:49:44 -04:00
using System.Linq;
2025-10-03 00:02:43 -04:00
using Continentis.MainGame.Card;
using Continentis.MainGame.UI;
2025-10-23 00:49:44 -04:00
using NaughtyAttributes;
using SLSFramework.General;
using SLSFramework.UModAssistance;
2025-10-03 00:02:43 -04:00
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")]
2025-10-23 00:49:44 -04:00
public partial class CharacterData : ScriptableObject
2025-10-03 00:02:43 -04:00
{
2025-10-23 00:49:44 -04:00
[Header("Fundamental")]
public bool haveCustomClass;
public string classFullName;
public string modName;
public string className;
public string displayName;
public List<string> tags;
2025-10-03 00:02:43 -04:00
2025-10-23 00:49:44 -04:00
public Sprite avatar;
public Sprite portrait;
2025-10-03 00:02:43 -04:00
2025-10-23 00:49:44 -04:00
public string characterDescription;
public string characterStory;
2025-10-03 00:02:43 -04:00
2025-10-23 00:49:44 -04:00
[Header("Attributes")]
[Tooltip("角色的核心属性:第一栏是属性名,第二栏是属性值")]
public SerializableDictionary<string, float> coreAttributes;
2025-10-03 00:02:43 -04:00
2025-10-23 00:49:44 -04:00
[Tooltip("角色的通常属性:第一栏是属性名,第二栏是属性值")]
public SerializableDictionary<string, float> generalAttributes;
2025-10-03 00:02:43 -04:00
[Tooltip("初始化时赋予给CurrentGeneralAttributes的属性第一栏是属性名第二栏是初始化时使用对应名称的GeneralAttributes的数据留空则默认为0,如果是float数字则直接使用该数字")]
2025-10-23 00:49:44 -04:00
public SerializableDictionary<string, string> runtimeGeneralAttributes;
2025-10-03 00:02:43 -04:00
2025-10-23 00:49:44 -04:00
[Header("View")]
public int combatPositionOrder;
public GameObject combatCharacterView;
2025-10-03 00:02:43 -04:00
2025-10-23 00:49:44 -04:00
[Header("References")]
public List<string> prefabRefs = new List<string>();
public List<string> derivativeCardDataRefs = new List<string>();
public List<string> derivativeCharacterDataRefs = new List<string>();
[Tooltip("初始卡组引用列表")]
public List<string> initialDeckRef;
[Tooltip("HUD信息引用列表")]
public List<string> hudDataRefs;
}
public partial class CharacterData
{
public static CharacterData Get(string dataID)
{
return ModManager.GetData<CharacterData>(dataID);
}
2025-10-03 00:02:43 -04:00
}
#if UNITY_EDITOR
public partial class CharacterData
{
public void PasteDefaultAttributes()
{
List<CharacterAttributesDefaultCollection> targetCollections = new List<CharacterAttributesDefaultCollection>();
string[] guids = AssetDatabase.FindAssets("t:CharacterAttributesDefaultCollection");
2025-10-23 00:49:44 -04:00
if (guids.Length > 1)
{
Debug.Log("找到了多个CharacterAttributesDefaultCollection它们将被合并后导入CharacterData");
}
2025-10-03 00:02:43 -04:00
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<ScriptableObject>(path);
Type assetType = collection.GetType();
string assetNamespace = assetType.Namespace;
2025-10-23 00:49:44 -04:00
// 检查目录是否有效,是否在"Assets/Mods/"下,并且是否以"/Characters/DefaultCollections"结尾
2025-10-03 00:02:43 -04:00
if (!string.IsNullOrEmpty(directory) &&
assetNamespace == typeof(CharacterAttributesDefaultCollection).Namespace &&
2025-10-23 00:49:44 -04:00
directory.StartsWith("Assets/Mods/") &&
2025-10-03 00:02:43 -04:00
directory.EndsWith("/Characters/DefaultCollections"))
{
// 3. 如果路径和命名空间都符合要求,则将该资产添加到目标列表中
CharacterAttributesDefaultCollection defaultList = collection as CharacterAttributesDefaultCollection;
targetCollections.Add(defaultList);
Debug.Log($"Loaded DefaultStringList from: {path}");
}
}
Dictionary<string, float> coreAttributes = new Dictionary<string, float>();
Dictionary<string, float> generalAttributes = new Dictionary<string, float>();
2025-10-23 00:49:44 -04:00
Dictionary<string, string> runtimeGeneralAttributes = new Dictionary<string, string>();
2025-10-03 00:02:43 -04:00
foreach (CharacterAttributesDefaultCollection collection in targetCollections)
{
collection.coreAttributes.PasteDictionary(coreAttributes);
collection.generalAttributes.PasteDictionary(generalAttributes);
2025-10-23 00:49:44 -04:00
collection.runtimeGeneralAttributes.PasteDictionary(runtimeGeneralAttributes);
2025-10-03 00:02:43 -04:00
}
coreAttributes.PasteDictionary(this.coreAttributes);
generalAttributes.PasteDictionary(this.generalAttributes);
2025-10-23 00:49:44 -04:00
runtimeGeneralAttributes.PasteDictionary(this.runtimeGeneralAttributes);
2025-10-03 00:02:43 -04:00
Debug.Log($"Pasted default attributes to file {this.name}");
}
}
#endif
}