115 lines
3.4 KiB
C#
115 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Gameplay.Common;
|
|
|
|
namespace Gameplay.Area
|
|
{
|
|
|
|
using UnityEngine;
|
|
using Character;
|
|
using Gameplay.Level;
|
|
|
|
public class AttackAreaView
|
|
{
|
|
|
|
public GameUnit owner;
|
|
|
|
public bool isAreaShowed;
|
|
|
|
private Map _map;
|
|
private int _lastCellIndex;
|
|
private List<int> _areaInfo;
|
|
private Color _hintColor;
|
|
private Color _hintColor2;
|
|
private bool _forceHide;
|
|
private TGS.Territory _cacheTerritory;
|
|
private GameObject _cacheObjBorader;
|
|
private static readonly int Color1 = Shader.PropertyToID("_Color");
|
|
private static readonly int SecondColor = Shader.PropertyToID("_SecondColor");
|
|
|
|
public void Init()
|
|
{
|
|
_map = LevelManager.Instance.CurrentLevel.Map;
|
|
_areaInfo = new List<int>();
|
|
_hintColor = ColorUtility.TryParseHtmlString("#C1C336", 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;
|
|
}
|
|
|
|
public void HideArea()
|
|
{
|
|
owner = null;
|
|
_HideArea();
|
|
}
|
|
|
|
public void ForceHide()
|
|
{
|
|
_forceHide = true;
|
|
_HideArea();
|
|
}
|
|
|
|
public void CancelForce()
|
|
{
|
|
_forceHide = false;
|
|
}
|
|
|
|
private void _HideArea()
|
|
{
|
|
if (!isAreaShowed) return;
|
|
isAreaShowed = false;
|
|
var tIndex = _map.TerrainGridSystem.TerritoryGetIndex(_cacheTerritory);
|
|
_map.TerrainGridSystem.TerritoryDestroy(tIndex);
|
|
_cacheTerritory = null;
|
|
_areaInfo = null;
|
|
_cacheObjBorader.Destroy();
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
var needShow = owner != null
|
|
&& !owner.statusData.isDead
|
|
&& !_forceHide;
|
|
if (needShow)
|
|
{
|
|
var currentCellIndex = owner.transData.cellIndex;
|
|
if (currentCellIndex != _lastCellIndex)
|
|
{
|
|
_lastCellIndex = currentCellIndex;
|
|
|
|
if (isAreaShowed)
|
|
{
|
|
// 隐藏区域信息
|
|
_HideArea();
|
|
|
|
}
|
|
// 创建新的
|
|
_areaInfo = AreaManager.instance.GetCellIndexsAround(currentCellIndex, owner.fightData.attackDistance);
|
|
_cacheTerritory = _map.TerrainGridSystem.TerritoryCreate(_areaInfo);
|
|
var obj = _map.TerrainGridSystem.ForceDrawTerritoryDrawInteriorBorder(_cacheTerritory, 0, 1, _hintColor, _hintColor2);
|
|
var getMat = obj.transform.GetChild(0).GetComponent<MeshRenderer>().material;
|
|
getMat.SetColor(Color1, _hintColor);
|
|
getMat.SetColor(SecondColor, _hintColor2);
|
|
_cacheObjBorader = obj;
|
|
isAreaShowed = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (isAreaShowed)
|
|
{
|
|
_HideArea();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|