using System.Collections.Generic; using Gameplay.Area.BoardView; using Gameplay.Level; using Gameplay.Unit; using UnityEngine; namespace Gameplay.Area { public class AttackAreaView { public GameUnit owner; public bool isAreaShowed; private int _lastCellIndex; private int _lastAttackDistance; private Color _hintColor; private Color _hintColor2; private bool _forceHide; private List _cacheBoardViewList = new List(); public void Init() { _hintColor = ColorUtility.TryParseHtmlString("#FFCB54", out Color color) ? color : Color.red; _hintColor2 = ColorUtility.TryParseHtmlString("#c26b36", out Color color2) ? color2 : Color.red; _hintColor2.a = 0; } public void SetOwner(GameUnit u) { owner = u; _lastCellIndex = -1; _lastAttackDistance = -1; } public void HideArea() { owner = null; _HideArea(); } public void ForceHide() { _forceHide = true; _HideArea(); } public void CancelForce() { _forceHide = false; if (owner != null) { SetOwner(owner); } } private void _HideArea() { if (!isAreaShowed) return; isAreaShowed = false; for (int i = 0; i < _cacheBoardViewList.Count; i++) { var boardViewData = _cacheBoardViewList[i]; boardViewData.Destroy(LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem); } _cacheBoardViewList.Clear(); DebugUtil.LogG("隐藏攻击区域"); } public void LogicUpdate(float dt) { var needShow = owner != null && !owner.statusData.isDead && !_forceHide; if (needShow) { var currentCellIndex = owner.transData.cellIndex; var currentAttackDistance = owner.fightData.attackDistance; if (currentCellIndex != _lastCellIndex || _lastAttackDistance != currentAttackDistance) { _lastCellIndex = currentCellIndex; _lastAttackDistance = currentAttackDistance; if (isAreaShowed) { // 隐藏区域信息 _HideArea(); } // 创建新的 var attackArea = AreaManager.instance.attackAreaManager.GetAttackArea(owner.transData.cellIndex, owner.fightData.attackDistance); var areaCellList = owner.fightData.isAttackIgnoreBlock ? attackArea.totalCells : attackArea.canAttackCells; BoardViewHelper.GenerateBoard(areaCellList, _cacheBoardViewList, LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem); for (int i = 0; i < _cacheBoardViewList.Count; i++) { var boardViewData = _cacheBoardViewList[i]; boardViewData.CreateBoardViewObj(LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem, _hintColor, _hintColor2); } isAreaShowed = true; DebugUtil.LogG("显示攻击区域"); } } else { if (isAreaShowed) { _HideArea(); } } } } }