164 lines
4.8 KiB
C#
164 lines
4.8 KiB
C#
using System.Collections.Generic;
|
|
using AOT.PostProcess.BlackArea;
|
|
using Gameplay.Area;
|
|
using Gameplay.Character;
|
|
using Gameplay.Level;
|
|
using Gameplay.Unit;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.PostProcess.BlackArea
|
|
{
|
|
public class BlackAreaManagerImpl : IBlackAreaManager
|
|
{
|
|
|
|
private bool _enableBlackArea;
|
|
public bool enableBlackArea
|
|
{
|
|
get
|
|
{
|
|
return _enableBlackArea;
|
|
}
|
|
}
|
|
|
|
private Camera _targetCamera;
|
|
public Camera targetCamera
|
|
{
|
|
get
|
|
{
|
|
return _targetCamera;
|
|
}
|
|
}
|
|
|
|
private List<LightPoint> _pointList = new List<LightPoint>();
|
|
public List<LightPoint> pointList
|
|
{
|
|
get
|
|
{
|
|
return _pointList;
|
|
}
|
|
}
|
|
|
|
private Dictionary<int, LightPoint> _pointDic = new Dictionary<int, LightPoint>();
|
|
private GameObject _rootObj;
|
|
|
|
private Material _blitMat;
|
|
public Material blitMat
|
|
{
|
|
get
|
|
{
|
|
return _blitMat;
|
|
}
|
|
}
|
|
|
|
public const string BLIT_MAT_PATH = "Assets/Art/Other/mat/black_area_blit.mat";
|
|
|
|
public void Init(bool enable)
|
|
{
|
|
_enableBlackArea = enable;
|
|
if (!enableBlackArea) return;
|
|
_InitLightMap();
|
|
_blitMat = AssetManager.Instance.GetPreLoadResult<Material>(BLIT_MAT_PATH);
|
|
_targetCamera = CameraManager.Instance.MainCamera;
|
|
}
|
|
|
|
private void _InitLightMap()
|
|
{
|
|
_pointList.Clear();
|
|
_pointDic.Clear();
|
|
_rootObj = new GameObject("[BlackAreaRoot]");
|
|
var allCells = LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem.cells;
|
|
var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(Framework.Constants.FIGHT_LIGHT_AREA_PATH);
|
|
for (int i = 0; i < allCells.Count; i++)
|
|
{
|
|
var cell = allCells[i];
|
|
var cellIndex = cell.index;
|
|
var cellWorldPos = AreaManager.instance.GetCellPosByIndex(cellIndex);
|
|
var instObj = Object.Instantiate(sampleObj, cellWorldPos, Quaternion.identity, _rootObj.transform);
|
|
|
|
var lightPoint = new LightPoint(cellIndex, instObj);
|
|
lightPoint.LightOff();
|
|
_pointList.Add(lightPoint);
|
|
_pointDic.Add(cellIndex, lightPoint);
|
|
}
|
|
}
|
|
|
|
public void AutoLightUpReadyArea()
|
|
{
|
|
if (!enableBlackArea) return;
|
|
var readyArea = AreaManager.instance.readyAreaManager.mapSavedReadyCellIndexs;
|
|
for (int i = 0; i < readyArea.Count; i++)
|
|
{
|
|
LightUpCell(readyArea[i], 0.1f);
|
|
}
|
|
}
|
|
|
|
public void LightUpCell(int cellIndex, float during)
|
|
{
|
|
if (!enableBlackArea) return;
|
|
if (_pointDic.TryGetValue(cellIndex, out var lightPoint))
|
|
{
|
|
lightPoint.MarkLight(during);
|
|
}
|
|
else
|
|
{
|
|
DebugUtil.LogError("LightUpCell failed, cellIndex:{0} is invalid!", cellIndex);
|
|
}
|
|
}
|
|
|
|
private void _AutoLightCharacterArea()
|
|
{
|
|
var allUnits = GameUnitManager.instance.infightUnits.unitList;
|
|
for (int i = 0; i < allUnits.Count; i++)
|
|
{
|
|
var unit = allUnits[i];
|
|
if (unit.statusData.isDead) continue;
|
|
if (unit.commonData.troopId != ETroopsId.Self) continue;
|
|
var lightUpDistance = unit.fightData.lightUpArea;
|
|
var cellIndexs = AreaManager.instance.GetCellIndexsAround(unit.transData.cellIndex, lightUpDistance);
|
|
for (int j = 0; j < cellIndexs.Count; j++)
|
|
{
|
|
LightUpCell(cellIndexs[j], 0.1f);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool CheckIsInLightArea(int cellIndex)
|
|
{
|
|
if (!enableBlackArea)
|
|
{
|
|
return true;
|
|
}
|
|
if (_pointDic.TryGetValue(cellIndex, out var lightPoint))
|
|
{
|
|
return lightPoint.isLight;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
if (!enableBlackArea)
|
|
{
|
|
return;
|
|
}
|
|
_AutoLightCharacterArea();
|
|
for (int i = 0; i < _pointList.Count; i++)
|
|
{
|
|
_pointList[i].LogicUpdate(dt);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_enableBlackArea = false;
|
|
if (_rootObj != null)
|
|
{
|
|
Object.Destroy(_rootObj);
|
|
_rootObj = null;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|