添加 SepCore.Runtime 和 SepCore.Base 程序集

- 暂时将 Entity 全部归进 Runtime 程序集里
- 调整部分 UI 的 UseCase/RawData/Context 之间的关系,让 RawData 更接近业务原始数据,Context 更接近 UI 直接可读的数据
- 调整其他程序集的引用关系
This commit is contained in:
SepComet
2026-06-03 11:15:58 +08:00
parent d5893ac52b
commit 91f70dd783
176 changed files with 245 additions and 231 deletions
@@ -1,3 +1,5 @@
using CustomUtility;
using SepCore.DataTable;
using SepCore.Definition;
using UnityEngine;
@@ -7,19 +9,46 @@ namespace SepCore.UI
{
public string Title;
public ItemRarity Rarity;
public string Type;
public Sprite Icon;
public ItemType ItemType;
public string Description;
public int Price;
public GoodsItemContext()
{
Title = string.Empty;
Description = string.Empty;
Rarity = ItemRarity.White;
Price = 0;
Icon = null;
ItemType = ItemType.None;
}
public GoodsItemContext(GoodsItemRawData rawData)
{
Title = rawData.Title;
Description = rawData.Description;
Price = rawData.Price;
Rarity = rawData.Rarity;
Type = rawData.Type;
Icon = rawData.Icon;
ItemType = rawData.ItemType;
if (ItemType == ItemType.None)
{
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);
GameEntry.SpriteCache.GetSprite(weapon.IconAssetName, sprite => Icon = sprite);
}
else
{
var prop = (DRProp)rawData.DataRow;
Title = prop.Title;
Description = ItemDescUtility.CreatePropDescription(prop.Modifiers);
GameEntry.SpriteCache.GetSprite(prop.IconAssetName, sprite => Icon = sprite);
}
}
}
}
@@ -1,3 +1,8 @@
using System;
using System.Drawing;
using CustomUtility;
using Entity.EntityData;
using Entity.Weapon;
using SepCore.Definition;
using UnityEngine;
@@ -8,11 +13,50 @@ namespace SepCore.UI
public int Index;
public string IconAssetName;
public string Title;
public string TypeText;
public ItemType ItemType;
public ItemRarity Rarity;
public string Description;
public int Price;
public bool IsWeapon;
public Vector3 TargetPos;
public DisplayItemInfoContext()
{
Index = -1;
IconAssetName = string.Empty;
Title = string.Empty;
ItemType = ItemType.None;
Rarity = ItemRarity.White;
Description = string.Empty;
Price = 0;
TargetPos = Vector3.zero;
}
public DisplayItemInfoContext(DisplayItemInfoRawData rawData)
{
Index = rawData.Index;
ItemType = rawData.ItemType;
Rarity = rawData.Rarity;
Price = rawData.Price;
TargetPos = rawData.TargetPos;
if (ItemType == ItemType.None)
{
IconAssetName = string.Empty;
Title = string.Empty;
}
else if (ItemType == ItemType.Weapon)
{
var data = (WeaponData)rawData.Data;
IconAssetName = data.IconAssetName;
Title = data.Title;
Description = ItemDescUtility.CreateWeaponDescription(data);
}
else
{
var data = (PropItem)rawData.Data;
IconAssetName = data.IconAssetName;
Title = data.Title;
Description = ItemDescUtility.CreatePropDescription(data);
}
}
}
}
@@ -43,18 +43,7 @@ namespace SepCore.UI
return null;
}
return new DisplayItemInfoContext
{
Index = rawData.Index,
IconAssetName = rawData.IconAssetName,
Title = rawData.Title,
Rarity = rawData.Rarity,
TypeText = rawData.TypeText,
Description = rawData.Description,
Price = rawData.Price,
IsWeapon = rawData.IsWeapon,
TargetPos = rawData.TargetPos
};
return new DisplayItemInfoContext(rawData);
}
public override async UniTask<int?> OpenUIAsync(object userData = null, float timeout = 30f)
@@ -1,3 +1,4 @@
using System;
using SepCore.Event;
using TMPro;
using UnityEngine;
@@ -32,6 +33,7 @@ namespace SepCore.UI
[SerializeField] private float _screenEdgePadding = 0f;
private DisplayItemInfoContext _context;
private Vector3 _targetPos;
public void RefreshUI(DisplayItemInfoContext context)
@@ -53,13 +55,13 @@ namespace SepCore.UI
}
if (_itemTitle != null) _itemTitle.text = _context.Title ?? string.Empty;
if (_itemTypeText != null) _itemTypeText.text = _context.TypeText ?? string.Empty;
if (_itemTypeText != null) _itemTypeText.text = BuildTypeText(_context.ItemType) ?? string.Empty;
if (_itemDescription != null) _itemDescription.text = _context.Description ?? string.Empty;
if (_itemPrice != null) _itemPrice.text = $"{_context.Price} <sprite name=\"coin\" index=0>";
if (_recycleButton != null)
{
_recycleButton.gameObject.SetActive(_context.IsWeapon);
_recycleButton.gameObject.SetActive(_context.ItemType == ItemType.Weapon);
}
if (_iconArea != null)
@@ -193,7 +195,7 @@ namespace SepCore.UI
public void OnRecycleButtonClick()
{
if (_context == null || !_context.IsWeapon) return;
if (_context == null || _context.ItemType != ItemType.Weapon) return;
GameEntry.Event.Fire(this, ShopWeaponRecycleEventArgs.Create(_context.Index, _context.Price));
}
@@ -201,5 +203,16 @@ namespace SepCore.UI
{
GameEntry.Event.Fire(this, DisplayItemInfoHideEventArgs.Create(true));
}
private string BuildTypeText(ItemType type)
{
return type switch
{
ItemType.None => "error",
ItemType.Weapon => "武器",
ItemType.Prop => "道具",
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
}
}
}
@@ -374,18 +374,14 @@ namespace SepCore.UI
return false;
}
var weaponData = weapon.WeaponData;
rawData = new DisplayItemInfoRawData
{
TargetPos = targetPos,
Index = index,
IconAssetName = weaponData.IconAssetName,
Title = weaponData.Title,
Rarity = weaponData.Rarity,
TypeText = "武器",
Description = ItemDescUtility.CreateWeaponDescription(weaponData),
Price = Mathf.FloorToInt(weaponData.Price * Context.WeaponRecycleRate),
IsWeapon = true
Data = weapon.WeaponData,
Rarity = weapon.WeaponData.Rarity,
ItemType = ItemType.Weapon,
Price = Mathf.FloorToInt(weapon.WeaponData.Price * Context.WeaponRecycleRate),
};
return true;
}
@@ -417,13 +413,10 @@ namespace SepCore.UI
{
TargetPos = targetPos,
Index = index,
IconAssetName = propItem.IconAssetName,
Title = propItem.Title,
Data = propItem,
Rarity = propItem.Rarity,
TypeText = "道具",
Description = ItemDescUtility.CreatePropDescription(propItem),
Price = 0,
IsWeapon = false
ItemType = ItemType.Prop,
Price = 0
};
return true;
}
@@ -1,3 +1,4 @@
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -22,7 +23,13 @@ namespace SepCore.UI
{
_iconArea.OnInit(data.Icon, data.Rarity);
_titleText.text = data.Title;
_typeText.text = data.Type;
_typeText.text = data.ItemType switch
{
ItemType.None => "error",
ItemType.Weapon => "武器",
ItemType.Prop => "道具",
_ => throw new ArgumentOutOfRangeException()
};
_descriptionText.text = data.Description;
_costText.text = $"{data.Price} <sprite name=\"coin\" index=0>";
}
@@ -3,9 +3,10 @@
"rootNamespace": "SepCore.UI",
"references": [
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:47a82ffa13c291447ab895cd0bc251cd",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:363c5eb08ff8e6a439b85e37b8c20d96",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
"GUID:47a82ffa13c291447ab895cd0bc251cd",
"GUID:436e23dbdc31e7d4fb5c3f804548b2df"
],
"includePlatforms": [],
"excludePlatforms": [],
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 77816bb3deec31c4ba8881acdd951fea
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,120 @@
using System.Collections.Generic;
using System.Text;
using SepCore.DataTable;
using SepCore.Definition;
using Entity.EntityData;
using Entity.Weapon;
using System;
using UnityGameFramework.Runtime;
namespace CustomUtility
{
public static class ItemDescUtility
{
private static readonly Dictionary<string, string> _paramsDict = new(StringComparer.OrdinalIgnoreCase)
{
{"hitHalfWidth", "横向半宽"},
{"hitRadius", "攻击半宽"},
{"hitHeight", "判定高度"},
{"hitCenterYOffset", "判定高度偏移"},
{"sectorAngle", "攻击角度"},
{"pierceLength", "前戳距离"},
{"thrustDistance", "前戳距离(旧)"},
{"forwardOffset", "前置偏移"},
{"rotateSpeed", "转向速度"},
{"attackDuration", "突刺时长"},
{"returnDuration", "收枪时长"}
};
public static string CreatePropDescription(StatModifier[] modifiers)
{
if (modifiers == null || modifiers.Length == 0)
{
return null;
}
StringBuilder sb = new StringBuilder();
foreach (StatModifier modifier in modifiers)
{
sb.Append(modifier);
sb.Append('\n');
}
return sb.ToString();
}
public static string CreateWeaponDescription(DRWeapon drWeapon)
{
if (drWeapon == null)
{
return null;
}
return CreateWeaponDescription(drWeapon.Attack, drWeapon.Cooldown, drWeapon.AttackRange, drWeapon.Modifiers,
drWeapon.Pramas);
}
public static string CreateWeaponDescription(WeaponBase weapon)
{
if (weapon == null || weapon.WeaponData == null)
{
return null;
}
return CreateWeaponDescription(weapon.WeaponData);
}
public static string CreateWeaponDescription(WeaponData weaponData)
{
if (weaponData == null)
{
return null;
}
return CreateWeaponDescription(weaponData.Attack, weaponData.Cooldown,
weaponData.AttackRange, weaponData.Modifiers, weaponData.Params);
}
public static string CreatePropDescription(PropItem prop)
{
if (prop == null)
{
return null;
}
return CreatePropDescription(prop.Modifiers);
}
private static string CreateWeaponDescription(int attack, float cooldown, float attackRange,
StatModifier[] modifiers, Dictionary<string, string> @params)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"攻击: {attack}");
sb.AppendLine($"冷却: {cooldown}");
sb.AppendLine($"范围: {attackRange}");
string modifiersDesc = CreatePropDescription(modifiers);
if (!string.IsNullOrEmpty(modifiersDesc))
{
sb.Append(modifiersDesc);
}
if (@params == null || @params.Count == 0)
{
return sb.ToString();
}
foreach (var kvp in @params)
{
if (!_paramsDict.TryGetValue(kvp.Key, out string value))
{
value = kvp.Key;
Log.Warning($"{kvp.Key} is not defined.");
}
sb.AppendLine($"{value}: {kvp.Value}");
}
return sb.ToString();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dcfdad321f8ce314fa013b885c2a78f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: