113 lines
3.3 KiB
C#
113 lines
3.3 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using NUnit.Framework;
|
||
using Sirenix.OdinInspector;
|
||
using UnityEngine;
|
||
|
||
namespace Cielonos.MainGame.Characters.Inventory
|
||
{
|
||
public enum ItemType
|
||
{
|
||
MainWeapon,
|
||
Support,
|
||
Passive,
|
||
Consumable
|
||
}
|
||
|
||
public enum ItemRarity
|
||
{
|
||
None,
|
||
Tera,
|
||
Moser,
|
||
Graham,
|
||
Epsilon,
|
||
Aleph
|
||
}
|
||
|
||
[CreateAssetMenu(fileName = "ContentData", menuName = "Cielonos/Items/ContentData")]
|
||
public partial class ContentData : SerializedScriptableObject
|
||
{
|
||
[InlineButton("CreateID", "Create")]
|
||
[ValueDropdown("GetAllItemTypes", IsUniqueList = true, DropdownHeight = 400)]
|
||
public Type itemClass;
|
||
public ItemType itemType;
|
||
public ItemRarity itemRarity;
|
||
[ValueDropdown("GetAllTags", IsUniqueList = true, DropdownHeight = 400)]
|
||
public List<string> tags;
|
||
|
||
[ReadOnly]
|
||
public string displayNameKey;
|
||
[ReadOnly]
|
||
public string descriptionKey;
|
||
|
||
[ShowIf("isMainWeapon")]
|
||
public Sprite rectIcon;
|
||
[HideIf("isMainWeapon")]
|
||
public Sprite squareIcon;
|
||
|
||
[TitleGroup("Drop Settings")]
|
||
[Tooltip("掉落权重,越大越容易被随机选中。设为 0 则不会出现在随机池中。")]
|
||
public float dropWeight = 1f;
|
||
|
||
[Tooltip("额外的掉落设置,可以在 Roll 时传入 filter 进行更复杂的筛选逻辑。")]
|
||
public Dictionary<string, float> dropSettings = new Dictionary<string, float>();
|
||
}
|
||
|
||
public partial class ContentData
|
||
{
|
||
private bool isMainWeapon => itemType == ItemType.MainWeapon;
|
||
|
||
private void CreateID()
|
||
{
|
||
if(string.IsNullOrEmpty(itemClass?.Name))
|
||
{
|
||
Debug.LogWarning("Class Name is empty. Cannot create Item ID.");
|
||
return;
|
||
}
|
||
|
||
string itemType = this.itemType.ToString();
|
||
string className = this.itemClass.Name;
|
||
|
||
displayNameKey = $"{itemType}_{className}_Name";
|
||
descriptionKey = $"{itemType}_{className}_Desc";
|
||
}
|
||
}
|
||
|
||
public partial class ContentData
|
||
{
|
||
#if UNITY_EDITOR
|
||
private List<string> GetAllTags()
|
||
{
|
||
return new List<string>
|
||
{
|
||
"Melee",
|
||
"Ranged",
|
||
"Burn",
|
||
"Freeze",
|
||
"Electric"
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取项目中所有继承自ItemBase的类的名称列表,用于编辑器下拉选择。可以根据需要添加命名空间过滤等逻辑。
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private List<Type> GetAllItemTypes()
|
||
{
|
||
List<Type> itemTypes = new List<Type>();
|
||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||
{
|
||
foreach (var type in assembly.GetTypes())
|
||
{
|
||
if (type.IsClass && !type.IsAbstract && typeof(ItemBase).IsAssignableFrom(type))
|
||
{
|
||
itemTypes.Add(type);
|
||
}
|
||
}
|
||
}
|
||
return itemTypes;
|
||
}
|
||
|
||
#endif
|
||
}
|
||
} |