Files
Continentis/Assets/Scripts/MainGame/Equipment/EquipmentData.cs
SoulliesOfficial 9b1b5ca93f initial
2025-10-03 00:02:43 -04:00

98 lines
3.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using Continentis.MainGame.Card;
using Continentis.MainGame.Character;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Serialization;
namespace Continentis.MainGame.Equipment
{
[CreateAssetMenu(menuName = "Continentis/MainGame/Equipment/EquipmentData", fileName = "EquipmentData")]
public partial class EquipmentData : SerializedScriptableObject
{
[Title("Fundamental")]
[ValueDropdown("GetLogicTypes", IsUniqueList = true)]
public Type equipmentClass;
public List<string> tags;
public string equipmentName;
public int equipmentWeight;
[FormerlySerializedAs("equipmentImage")] public Sprite equipmentSprite;
[TextArea(1, 10)]
public string equipmentDescription;
[Title("Attributes")][Searchable]
public Dictionary<string, float> coreNumericChange = new Dictionary<string, float>();
[Searchable]
public Dictionary<string, float> corePercentageChangeOfAccumulation = new Dictionary<string, float>();
[Searchable]
public Dictionary<string, float> corePercentageChangeOfMultiplication = new Dictionary<string, float>();
[Searchable]
public Dictionary<string, float> generalNumericChange = new Dictionary<string, float>();
[Searchable]
public Dictionary<string, float> generalPercentageChangeOfAccumulation = new Dictionary<string, float>();
[Searchable]
public Dictionary<string, float> generalPercentageChangeOfMultiplication = new Dictionary<string, float>();
[Title("Cards")][Searchable]
public Dictionary<CardData, int> cards;
[Title("Upgrades")]
public List<EquipmentData> upgrades;
}
public partial class EquipmentData
{
public EquipmentBase GenerateEquipment(CharacterBase character)
{
if (Activator.CreateInstance(equipmentClass) is EquipmentBase equipment)
{
equipment.equipmentData = this;
equipment.SetUp(character);
return equipment;
}
Debug.LogError($"Failed to create equipment of type {equipmentClass}");
return null;
}
}
#if UNITY_EDITOR
public partial class EquipmentData
{
private IEnumerable<ValueDropdownItem<Type>> GetLogicTypes()
{
IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.Where(t => typeof(EquipmentBase).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface);
// 我们将从命名空间中移除这个公共前缀,让路径更简洁
string commonNamespacePrefix = "Continentis.Mods";
foreach (var type in types)
{
string path = "Uncategorized/" + type.Name; // 默认路径
if (type.Namespace != null && type.Namespace.StartsWith(commonNamespacePrefix))
{
// 1. 移除公共前缀
string formattedNamespace = type.Namespace.Substring(commonNamespacePrefix.Length);
// 2. 移除特定的子命名空间部分(例如 "Cards"
formattedNamespace = formattedNamespace.Replace(".Equipments", "");
// 3. 将点 '.' 替换为斜杠 '/' 来创建分组
formattedNamespace = formattedNamespace.Replace('.', '/');
// 4. 组合成最终的路径
path = formattedNamespace + "/" + type.Name;
}
yield return new ValueDropdownItem<Type>(path, type);
}
}
}
#endif
}