110 lines
4.8 KiB
C#
110 lines
4.8 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using Continentis.MainGame.Card;
|
||
using Continentis.MainGame.UI;
|
||
using Sirenix.OdinInspector;
|
||
using SoulliesFramework.General;
|
||
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 : SerializedScriptableObject
|
||
{
|
||
[Title("Fundamental")]
|
||
public string characterName;
|
||
|
||
[TextArea(1,10)]
|
||
public string characterDescription;
|
||
|
||
[Searchable]
|
||
public List<string> tags;
|
||
|
||
[Title("Attributes")]
|
||
[Searchable]
|
||
[DictionaryDrawerSettings(KeyColumnWidth = 400)]
|
||
public Dictionary<string, float> coreAttributes;
|
||
|
||
[Searchable]
|
||
[DictionaryDrawerSettings(KeyColumnWidth = 400)]
|
||
public Dictionary<string, float> generalAttributes;
|
||
|
||
[Searchable]
|
||
[DictionaryDrawerSettings(KeyColumnWidth = 400)]
|
||
[Tooltip("初始化时赋予给CurrentGeneralAttributes的属性:第一栏是属性名,第二栏是初始化时使用对应名称的GeneralAttributes的数据,留空则默认为0,如果是float数字则直接使用该数字")]
|
||
public Dictionary<string, string> endowingGeneralAttributes;
|
||
|
||
[Title("Deck")]
|
||
[Searchable]
|
||
[Tooltip("初始卡组:第一栏是卡牌数据,第二栏是数量")]
|
||
public Dictionary<CardData, int> initialDeck;
|
||
|
||
[Title("HUD")]
|
||
public HUDData hudData;
|
||
}
|
||
|
||
#if UNITY_EDITOR
|
||
public partial class CharacterData
|
||
{
|
||
private const string ModsRootPath = "Assets/CoreMods";
|
||
|
||
[Button("从所有的DefaultCollection中粘贴默认属性")]
|
||
public void PasteDefaultAttributes()
|
||
{
|
||
List<CharacterAttributesDefaultCollection> targetCollections = new List<CharacterAttributesDefaultCollection>();
|
||
string[] guids = AssetDatabase.FindAssets("t:CharacterAttributesDefaultCollection");
|
||
|
||
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;
|
||
|
||
// 检查目录是否有效,是否在"Assets/CoreMods/"下,并且是否以"/Characters/DefaultCollections"结尾
|
||
if (!string.IsNullOrEmpty(directory) &&
|
||
assetNamespace == typeof(CharacterAttributesDefaultCollection).Namespace &&
|
||
directory.StartsWith("Assets/CoreMods/") &&
|
||
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>();
|
||
Dictionary<string, string> endowingGeneralAttributes = new Dictionary<string, string>();
|
||
|
||
foreach (CharacterAttributesDefaultCollection collection in targetCollections)
|
||
{
|
||
collection.coreAttributes.PasteDictionary(coreAttributes);
|
||
collection.generalAttributes.PasteDictionary(generalAttributes);
|
||
collection.endowingGeneralAttributes.PasteDictionary(endowingGeneralAttributes);
|
||
}
|
||
|
||
coreAttributes.PasteDictionary(this.coreAttributes);
|
||
generalAttributes.PasteDictionary(this.generalAttributes);
|
||
endowingGeneralAttributes.PasteDictionary(this.endowingGeneralAttributes);
|
||
Debug.Log($"Pasted default attributes to file {this.name}");
|
||
}
|
||
}
|
||
#endif
|
||
} |