NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Area/AttackAreaView.cs

109 lines
3.1 KiB
C#
Raw Normal View History

2023-12-12 12:49:49 +08:00
using System.Collections.Generic;
using Gameplay.Area.BoardView;
2023-12-13 16:20:41 +08:00
using Gameplay.Unit;
using UnityEngine;
2023-08-22 19:08:45 +08:00
namespace Gameplay.Area
{
public class AttackAreaView
{
public GameUnit owner;
2023-10-19 15:00:19 +08:00
public bool isAreaShowed;
2023-08-22 19:08:45 +08:00
private int _lastCellIndex;
2024-05-17 14:20:53 +08:00
private int _lastAttackDistance;
2023-08-22 19:08:45 +08:00
private Color _hintColor;
private Color _hintColor2;
private bool _forceHide;
private List<BoardViewData> _cacheBoardViewList;
2023-08-22 19:08:45 +08:00
public void Init()
{
2024-06-13 14:42:12 +08:00
_hintColor = ColorUtility.TryParseHtmlString("#FFCB54", out Color color) ? color : Color.red;
2023-08-22 19:08:45 +08:00
_hintColor2 = ColorUtility.TryParseHtmlString("#c26b36", out Color color2) ? color2 : Color.red;
_hintColor2.a = 0;
}
public void SetOwner(GameUnit u)
{
owner = u;
_lastCellIndex = -1;
2024-05-17 14:20:53 +08:00
_lastAttackDistance = -1;
2023-08-22 19:08:45 +08:00
}
public void HideArea()
{
owner = null;
_HideArea();
}
public void ForceHide()
{
_forceHide = true;
_HideArea();
}
public void CancelForce()
{
_forceHide = false;
if (owner != null)
{
SetOwner(owner);
}
2023-08-22 19:08:45 +08:00
}
private void _HideArea()
{
if (!isAreaShowed) return;
isAreaShowed = false;
for (int i = 0; i < _cacheBoardViewList.Count; i++)
{
var boardViewData = _cacheBoardViewList[i];
boardViewData.Destroy();
}
_cacheBoardViewList.Clear();
2023-08-22 19:08:45 +08:00
}
public void LogicUpdate(float dt)
{
var needShow = owner != null
&& !owner.statusData.isDead
&& !_forceHide;
if (needShow)
{
var currentCellIndex = owner.transData.cellIndex;
2024-05-17 14:20:53 +08:00
var currentAttackDistance = owner.fightData.attackDistance;
if (currentCellIndex != _lastCellIndex || _lastAttackDistance != currentAttackDistance)
2023-08-22 19:08:45 +08:00
{
_lastCellIndex = currentCellIndex;
2024-05-17 14:20:53 +08:00
_lastAttackDistance = currentAttackDistance;
2023-08-22 19:08:45 +08:00
if (isAreaShowed)
{
// 隐藏区域信息
_HideArea();
}
// 创建新的
var attackArea = AreaManager.instance.attackAreaManager.GetAttackArea(owner.transData.cellIndex, owner.fightData.attackDistance);
var areaCellList = owner.fightData.isAttackIgnoreBlock ? attackArea.totalCells : attackArea.canAttackCells;
_cacheBoardViewList = BoardViewHelper.GenerateBoard(areaCellList, _hintColor, _hintColor2);
2023-08-22 19:08:45 +08:00
isAreaShowed = true;
}
}
else
{
if (isAreaShowed)
{
_HideArea();
}
}
}
}
}