M1 回合制战斗架构收敛与 1v1 攻击闭环:BattleRuntime 内核、组件唯一入口、UI 数据驱动与 EditMode 测试
- 删除中间契约(BattleStartRequest/BattlePlayerInput/BattleReturnPlan/桥接与策略接口/FlowState),收敛为 BattleViewState/BattleStep/一层 BattleEvent - 新增内部 BattleRuntime/BattleUnit/BattleStatus 共享上下文;TurnBattleComponent 成为唯一外部入口,吸收启动/暂停/回写职责 - 内核支持 1v1 攻击闭环:效果公式、HP/MP 钳制、阵亡、Victory/TotalDefeat、敌人随机决策;敌人行动间歇 0.6s 由组件协程编排并经 StepListener 推送 - UI:玩家卡片/敌人槽/回合槽按战局重建,图标配置驱动(含新增 EnemyConfig.Icon),每轮刷新一次 TurnSlots 且轮内只移动高亮 - 新增 Tests 程序集 + InternalsVisibleTo,25 个 BattleRuntime 纯逻辑用例全部通过
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.AsyncTask;
|
||||
using SepCore.Battle;
|
||||
using SepCore.Definition;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -11,17 +15,62 @@ namespace SepCore.UI
|
||||
[SerializeField] private Image icon;
|
||||
[SerializeField] private TextMeshProUGUI label;
|
||||
|
||||
public GameObject ActiveMarker => activeMarker;
|
||||
public Image Icon => icon;
|
||||
public TextMeshProUGUI Label => label;
|
||||
private int _iconVersion;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void ConfigureEditor(GameObject marker, Image iconImage, TextMeshProUGUI slotLabel)
|
||||
/// <summary>
|
||||
/// 填充一个回合顺序槽:单位显示名、配置图标与当前行动者标记。
|
||||
/// </summary>
|
||||
public void SetTurnSlot(BattleUnitView unit, bool isCurrentActor)
|
||||
{
|
||||
activeMarker = marker;
|
||||
icon = iconImage;
|
||||
label = slotLabel;
|
||||
if (unit == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (label != null)
|
||||
{
|
||||
label.text = BattleUnitViewHelper.GetDisplayName(unit);
|
||||
}
|
||||
|
||||
SetCurrentActor(isCurrentActor);
|
||||
|
||||
_iconVersion++;
|
||||
LoadIconAsync(unit, _iconVersion).Forget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只更新当前行动者标记,不改变显示名。
|
||||
/// 同轮内单位行动后由 Logic 逐槽移动高亮。
|
||||
/// </summary>
|
||||
public void SetCurrentActor(bool isCurrentActor)
|
||||
{
|
||||
if (activeMarker != null)
|
||||
{
|
||||
activeMarker.SetActive(isCurrentActor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载单位图标(玩家/敌人分别走各自配置);iconVersion 防止旧加载覆盖新内容。
|
||||
/// </summary>
|
||||
private async UniTaskVoid LoadIconAsync(BattleUnitView unit, int iconVersion)
|
||||
{
|
||||
SpriteConfig iconConfig = unit.Faction == BattleFaction.Player
|
||||
? BattleUnitViewHelper.GetPlayerIconConfig(unit.ConfigId)
|
||||
: BattleUnitViewHelper.GetEnemyIconConfig(unit.ConfigId);
|
||||
if (iconConfig == null || icon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite sprite = await SpriteLoader.LoadSpriteAsync(iconConfig);
|
||||
if (sprite == null || _iconVersion != iconVersion)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
icon.sprite = sprite;
|
||||
icon.gameObject.SetActive(true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user