- BattleRuntime 调度替换为完整规则:速度高优先、同速玩家优先、同阵营同速 PartyOrder 小优先;先制第一轮玩家全先行,第二轮恢复普通排序;RemainingTurnOrder 同步按调度序输出 - TurnBattleComponent 开局行动者为敌人时自动推进,协程等待 UI 监听注册避免先手事件丢失 - 调试入口支持 1v1 / 2v2 / 4v4 与先制开关;新增敌人队伍预设 4005(四普通敌人) - UI:修复 UIForm 复用导致第二次开战按钮监听丢失;EnemySlots/TurnSlots 改为按数量复用 item,图标同一单位不重复加载 - EditMode 新增 10 个调度用例(共 35 个):排序规则、先制两轮、重复敌人分别击杀、4v4 创建、死亡移出候选、固定随机序列复现
97 lines
2.9 KiB
C#
97 lines
2.9 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using SepCore.AsyncTask;
|
|
using SepCore.Battle;
|
|
using SepCore.Definition;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace SepCore.UI
|
|
{
|
|
[DisallowMultipleComponent]
|
|
public sealed class BattleEnemySlotItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button targetButton;
|
|
[SerializeField] private GameObject selectedMarker;
|
|
[SerializeField] private Image icon;
|
|
[SerializeField] private Image hpFill;
|
|
[SerializeField] private TextMeshProUGUI enemyName;
|
|
[SerializeField] private TextMeshProUGUI hpText;
|
|
|
|
private int _iconVersion;
|
|
private int _currentUnitId;
|
|
|
|
/// <summary>
|
|
/// 用战斗单位视图填充敌人槽:名称、HP 数值与血条、配置图标和当前行动者标记。
|
|
/// 阵亡或已逃跑目标不可选;同一单位复用时不重复加载图标。
|
|
/// </summary>
|
|
public void SetEnemy(BattleUnitView unit, bool isCurrentActor)
|
|
{
|
|
if (unit == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (enemyName != null)
|
|
{
|
|
enemyName.text = BattleUnitViewHelper.GetDisplayName(unit);
|
|
}
|
|
|
|
if (hpText != null)
|
|
{
|
|
hpText.text = unit.CurrentHp + " / " + unit.MaxHp;
|
|
}
|
|
|
|
SetBar(hpFill, unit.CurrentHp, unit.MaxHp);
|
|
|
|
if (selectedMarker != null)
|
|
{
|
|
selectedMarker.SetActive(isCurrentActor);
|
|
}
|
|
|
|
if (targetButton != null)
|
|
{
|
|
targetButton.interactable = !unit.IsDefeated && !unit.IsEscaped;
|
|
}
|
|
|
|
if (_currentUnitId != unit.BattleUnitId)
|
|
{
|
|
_currentUnitId = unit.BattleUnitId;
|
|
_iconVersion++;
|
|
ShowIconAsync(BattleUnitViewHelper.GetEnemyIconConfig(unit.ConfigId), _iconVersion).Forget();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步加载敌人图标;iconVersion 用于防止复用格子时旧加载结果覆盖新内容。
|
|
/// </summary>
|
|
private async UniTaskVoid ShowIconAsync(SpriteConfig iconConfig, int iconVersion)
|
|
{
|
|
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);
|
|
}
|
|
|
|
private static void SetBar(Image fill, int current, int max)
|
|
{
|
|
if (fill == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
float ratio = max > 0 ? Mathf.Clamp01((float)current / max) : 0f;
|
|
fill.rectTransform.anchorMax = new Vector2(ratio, 1f);
|
|
}
|
|
}
|
|
} |