迁移数据表到 Luban,移除 JsonNet、EnumUtility
This commit is contained in:
@@ -10,7 +10,7 @@ namespace SepCore.UI
|
||||
|
||||
[SerializeField] private Image _icon;
|
||||
|
||||
public void OnInit(Sprite sprite, ItemRarity rarity)
|
||||
public void OnInit(Sprite sprite, Rarity rarity)
|
||||
{
|
||||
SetIcon(sprite);
|
||||
SetRarity(rarity);
|
||||
@@ -21,15 +21,15 @@ namespace SepCore.UI
|
||||
_icon.sprite = sprite;
|
||||
}
|
||||
|
||||
public void SetRarity(ItemRarity rarity)
|
||||
public void SetRarity(Rarity rarity)
|
||||
{
|
||||
_board.color = rarity switch
|
||||
{
|
||||
ItemRarity.White => Color.white,
|
||||
ItemRarity.Green => Color.green,
|
||||
ItemRarity.Blue => Color.blue,
|
||||
ItemRarity.Purple => Color.magenta,
|
||||
ItemRarity.Red => Color.red,
|
||||
Rarity.White => Color.white,
|
||||
Rarity.Green => Color.green,
|
||||
Rarity.Blue => Color.blue,
|
||||
Rarity.Purple => Color.magenta,
|
||||
Rarity.Red => Color.red,
|
||||
_ => Color.clear,
|
||||
};
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace SepCore.UI
|
||||
public void OnReset()
|
||||
{
|
||||
SetIcon(null);
|
||||
SetRarity(ItemRarity.None);
|
||||
SetRarity(Rarity.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace SepCore.UI
|
||||
public string IconAssetName;
|
||||
public string Title;
|
||||
public ItemType ItemType;
|
||||
public ItemRarity Rarity;
|
||||
public Rarity Rarity;
|
||||
public string Description;
|
||||
public int Price;
|
||||
public Vector3 TargetPos;
|
||||
@@ -22,7 +22,7 @@ namespace SepCore.UI
|
||||
IconAssetName = string.Empty;
|
||||
Title = string.Empty;
|
||||
ItemType = ItemType.None;
|
||||
Rarity = ItemRarity.White;
|
||||
Rarity = Rarity.White;
|
||||
Description = string.Empty;
|
||||
Price = 0;
|
||||
TargetPos = Vector3.zero;
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace SepCore.UI
|
||||
{
|
||||
Title = reward.Title,
|
||||
Icon = null,
|
||||
ItemRarity = reward.Rarity,
|
||||
Rarity = reward.Rarity,
|
||||
Description = ItemDescUtility.CreatePropDescription(reward.Modifiers),
|
||||
IconAssetName = reward.IconAssetName
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace SepCore.UI
|
||||
|
||||
if (_titleText != null) _titleText.text = context.Title;
|
||||
if (_descriptionText != null) _descriptionText.text = context.Description;
|
||||
if (_iconArea != null) _iconArea.OnInit(context.Icon, context.ItemRarity);
|
||||
if (_iconArea != null) _iconArea.OnInit(context.Icon, context.Rarity);
|
||||
|
||||
LoadIcon(_context.IconAssetName).Forget();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace SepCore.UI
|
||||
{
|
||||
public string Title;
|
||||
public Sprite Icon;
|
||||
public ItemRarity ItemRarity;
|
||||
public Rarity Rarity;
|
||||
public string Description;
|
||||
public string IconAssetName;
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ namespace SepCore.UI
|
||||
public class DisplayItemContext : UIContext
|
||||
{
|
||||
public string IconAssetName;
|
||||
public ItemRarity Rarity;
|
||||
public Rarity Rarity;
|
||||
public bool IsWeapon;
|
||||
|
||||
public DisplayItemContext()
|
||||
{
|
||||
IconAssetName = string.Empty;
|
||||
Rarity = ItemRarity.None;
|
||||
Rarity = Rarity.None;
|
||||
IsWeapon = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.CustomUtility;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
@@ -9,7 +9,7 @@ namespace SepCore.UI
|
||||
public class GoodsItemContext : UIContext
|
||||
{
|
||||
public string Title;
|
||||
public ItemRarity Rarity;
|
||||
public Rarity Rarity;
|
||||
public Sprite Icon;
|
||||
public ItemType ItemType;
|
||||
public string Description;
|
||||
@@ -19,35 +19,50 @@ namespace SepCore.UI
|
||||
{
|
||||
Title = string.Empty;
|
||||
Description = string.Empty;
|
||||
Rarity = ItemRarity.White;
|
||||
Rarity = Rarity.White;
|
||||
Price = 0;
|
||||
Icon = null;
|
||||
ItemType = ItemType.None;
|
||||
ItemType = ItemType.Weapon;
|
||||
}
|
||||
|
||||
public GoodsItemContext(GoodsItemRawData rawData)
|
||||
public GoodsItemContext(GoodsItemRawData rawData)
|
||||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
Title = string.Empty;
|
||||
Description = string.Empty;
|
||||
Rarity = Rarity.White;
|
||||
Price = 0;
|
||||
Icon = null;
|
||||
ItemType = ItemType.Weapon;
|
||||
return;
|
||||
}
|
||||
|
||||
Price = rawData.Price;
|
||||
Rarity = rawData.Rarity;
|
||||
ItemType = rawData.ItemType;
|
||||
|
||||
|
||||
if (ItemType == ItemType.None)
|
||||
if (rawData.DataRow == null)
|
||||
{
|
||||
Description = string.Empty;
|
||||
Icon = null;
|
||||
Title = string.Empty;
|
||||
}
|
||||
else if (ItemType == ItemType.Weapon)
|
||||
{
|
||||
var weapon = (DRWeapon)rawData.DataRow;
|
||||
Title = weapon.Title;
|
||||
Description = ItemDescUtility.CreateWeaponDescription(weapon);
|
||||
if (rawData.DataRow is WeaponConfig weaponConfig)
|
||||
{
|
||||
Title = weaponConfig.Name;
|
||||
Description = ItemDescUtility.CreateWeaponDescription(weaponConfig);
|
||||
}
|
||||
else if (rawData.DataRow is WeaponData weaponData)
|
||||
{
|
||||
Title = weaponData.Title;
|
||||
Description = ItemDescUtility.CreateWeaponDescription(weaponData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var prop = (DRProp)rawData.DataRow;
|
||||
var prop = (PropConfig)rawData.DataRow;
|
||||
Title = prop.Title;
|
||||
Description = ItemDescUtility.CreatePropDescription(prop.Modifiers);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using SepCore.Entity.Weapon;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace SepCore.UI
|
||||
private static DisplayItemContext BuildPropItem(PropItem propItem)
|
||||
{
|
||||
string iconAssetName = null;
|
||||
ItemRarity rarity = ItemRarity.None;
|
||||
Rarity rarity = Rarity.None;
|
||||
|
||||
if (propItem != null)
|
||||
{
|
||||
@@ -128,7 +128,7 @@ namespace SepCore.UI
|
||||
private static DisplayItemContext BuildWeaponItem(WeaponBase weaponBase)
|
||||
{
|
||||
string iconAssetName = null;
|
||||
ItemRarity rarity = ItemRarity.None;
|
||||
Rarity rarity = Rarity.None;
|
||||
|
||||
if (weaponBase != null && weaponBase.WeaponData != null)
|
||||
{
|
||||
@@ -164,8 +164,13 @@ namespace SepCore.UI
|
||||
var context = new GoodsItemContext(rawData);
|
||||
context.Icon = context.ItemType switch
|
||||
{
|
||||
ItemType.Weapon => await GameEntry.SpriteCache.GetSprite(((DRWeapon)rawData.DataRow).IconAssetName),
|
||||
ItemType.Prop => await GameEntry.SpriteCache.GetSprite(((DRProp)rawData.DataRow).IconAssetName),
|
||||
ItemType.Weapon => await GameEntry.SpriteCache.GetSprite(rawData.DataRow switch
|
||||
{
|
||||
WeaponConfig weaponConfig => weaponConfig.IconAssetName,
|
||||
WeaponData weaponData => weaponData.IconAssetName,
|
||||
_ => string.Empty
|
||||
}),
|
||||
ItemType.Prop => await GameEntry.SpriteCache.GetSprite(((PropConfig)rawData.DataRow).IconAssetName),
|
||||
_ => null
|
||||
};
|
||||
return context;
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
"GUID:363c5eb08ff8e6a439b85e37b8c20d96",
|
||||
"GUID:47a82ffa13c291447ab895cd0bc251cd",
|
||||
"GUID:436e23dbdc31e7d4fb5c3f804548b2df",
|
||||
"GUID:d54b9488b03814a44ab937f0aeb738b1"
|
||||
"GUID:d54b9488b03814a44ab937f0aeb738b1",
|
||||
"GUID:3bb549212964b4192b427888ac9382e7"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using SepCore.Entity.Weapon;
|
||||
using System;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.CustomUtility
|
||||
{
|
||||
public static class ItemDescUtility
|
||||
{
|
||||
private static readonly Dictionary<string, string> _paramsDict = new(StringComparer.OrdinalIgnoreCase)
|
||||
private static readonly Dictionary<ParamType, string> _paramTypeNames = new()
|
||||
{
|
||||
{"hitHalfWidth", "横向半宽"},
|
||||
{"hitRadius", "攻击半宽"},
|
||||
{"hitHeight", "判定高度"},
|
||||
{"hitCenterYOffset", "判定高度偏移"},
|
||||
{"sectorAngle", "攻击角度"},
|
||||
{"pierceLength", "前戳距离"},
|
||||
{"thrustDistance", "前戳距离(旧)"},
|
||||
{"forwardOffset", "前置偏移"},
|
||||
{"rotateSpeed", "转向速度"},
|
||||
{"attackDuration", "突刺时长"},
|
||||
{"returnDuration", "收枪时长"}
|
||||
{ ParamType.HitRadius, "攻击半宽" },
|
||||
{ ParamType.SectorAngle, "攻击角度" },
|
||||
{ ParamType.HitHalfWidth, "横向半宽" },
|
||||
{ ParamType.PierceLength, "前戳距离" },
|
||||
{ ParamType.HitHeight, "判定高度" },
|
||||
};
|
||||
|
||||
private static readonly string[] _statTypeNames =
|
||||
@@ -39,30 +32,43 @@ namespace SepCore.CustomUtility
|
||||
"闪避",
|
||||
"金币/经验吸收范围"
|
||||
};
|
||||
|
||||
public static string Describe(StatModifier modifier)
|
||||
|
||||
public static string Describe(modifier modifier)
|
||||
{
|
||||
if (modifier == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string name = _statTypeNames[(int)modifier.StatType];
|
||||
string name = _statTypeNames[(int)modifier.Key];
|
||||
string colorTag = modifier.Value > 0 ? "green" : "red";
|
||||
string suffix = modifier.IsPercent ? "%" : string.Empty;
|
||||
float displayValue = modifier.IsPercent ? modifier.Value * 100 : modifier.Value;
|
||||
return $"{name}: <color={colorTag}>+{displayValue}{suffix}</color>";
|
||||
}
|
||||
float displayValue;
|
||||
if (modifier.IsPercent)
|
||||
{
|
||||
displayValue = modifier.Value / 10f;
|
||||
}
|
||||
else if (modifier.Key == StatType.MovementSpeed)
|
||||
{
|
||||
displayValue = modifier.Value / 1000f;
|
||||
}
|
||||
else
|
||||
{
|
||||
displayValue = modifier.Value;
|
||||
}
|
||||
|
||||
public static string CreatePropDescription(StatModifier[] modifiers)
|
||||
return $"{name}: <color={colorTag}>+{displayValue:0.##}{suffix}</color>";
|
||||
}
|
||||
|
||||
public static string CreatePropDescription(IEnumerable<modifier> modifiers)
|
||||
{
|
||||
if (modifiers == null || modifiers.Length == 0)
|
||||
if (modifiers == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (StatModifier modifier in modifiers)
|
||||
foreach (modifier modifier in modifiers)
|
||||
{
|
||||
sb.Append(Describe(modifier));
|
||||
sb.Append('\n');
|
||||
@@ -71,15 +77,15 @@ namespace SepCore.CustomUtility
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string CreateWeaponDescription(DRWeapon drWeapon)
|
||||
public static string CreateWeaponDescription(WeaponConfig weaponConfig)
|
||||
{
|
||||
if (drWeapon == null)
|
||||
if (weaponConfig == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return CreateWeaponDescription(drWeapon.Attack, drWeapon.Cooldown, drWeapon.AttackRange, drWeapon.Modifiers,
|
||||
drWeapon.Pramas);
|
||||
return CreateWeaponDescription(weaponConfig.Attack, weaponConfig.Cooldown / 1000f,
|
||||
weaponConfig.AttackRange / 1000f, weaponConfig.Modifiers, weaponConfig.Parameters);
|
||||
}
|
||||
|
||||
public static string CreateWeaponDescription(WeaponBase weapon)
|
||||
@@ -100,7 +106,7 @@ namespace SepCore.CustomUtility
|
||||
}
|
||||
|
||||
return CreateWeaponDescription(weaponData.Attack, weaponData.Cooldown,
|
||||
weaponData.AttackRange, weaponData.Modifiers, weaponData.Params);
|
||||
weaponData.AttackRange, weaponData.Modifiers, weaponData.Parameters);
|
||||
}
|
||||
|
||||
public static string CreatePropDescription(PropItem prop)
|
||||
@@ -114,7 +120,7 @@ namespace SepCore.CustomUtility
|
||||
}
|
||||
|
||||
private static string CreateWeaponDescription(int attack, float cooldown, float attackRange,
|
||||
StatModifier[] modifiers, Dictionary<string, string> @params)
|
||||
IEnumerable<modifier> modifiers, IReadOnlyDictionary<ParamType, int> parameters)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"攻击: {attack}");
|
||||
@@ -127,19 +133,23 @@ namespace SepCore.CustomUtility
|
||||
sb.Append(modifiersDesc);
|
||||
}
|
||||
|
||||
if (@params == null || @params.Count == 0)
|
||||
if (parameters == null || parameters.Count == 0)
|
||||
{
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
foreach (var kvp in @params)
|
||||
foreach (var kvp in parameters)
|
||||
{
|
||||
if (!_paramsDict.TryGetValue(kvp.Key, out string value))
|
||||
if (!_paramTypeNames.TryGetValue(kvp.Key, out string paramName))
|
||||
{
|
||||
value = kvp.Key;
|
||||
Log.Warning($"{kvp.Key} is not defined.");
|
||||
paramName = kvp.Key.ToString();
|
||||
}
|
||||
sb.AppendLine($"{value}: {kvp.Value}");
|
||||
|
||||
string valStr = kvp.Key == ParamType.SectorAngle
|
||||
? kvp.Value.ToString()
|
||||
: (kvp.Value / 1000f).ToString("0.##");
|
||||
|
||||
sb.AppendLine($"{paramName}: {valStr}");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
|
||||
Reference in New Issue
Block a user