101 lines
3.0 KiB
C#
101 lines
3.0 KiB
C#
using Gameplay.Skill;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.PostProcess.BlackArea
|
|
{
|
|
public class LightPoint
|
|
{
|
|
public bool isLight;
|
|
public int cellIndex;
|
|
public float remainTime;
|
|
|
|
private MeshRenderer _meshRenderer;
|
|
private readonly GameObject _lightObj;
|
|
|
|
private static MaterialPropertyBlock _cacheMatBlock;
|
|
private static readonly int Alpha = Shader.PropertyToID("_Alpha");
|
|
|
|
private float _currentAlpha;
|
|
private const float LIGHT_UP_SPEED = 5F;
|
|
private const float LIGHT_OFF_SPEED = 5F;
|
|
|
|
public LightPoint(int cellIndex, GameObject lightObj)
|
|
{
|
|
if (_cacheMatBlock == null)
|
|
{
|
|
_cacheMatBlock = new MaterialPropertyBlock();
|
|
}
|
|
this.cellIndex = cellIndex;
|
|
_lightObj = lightObj;
|
|
isLight = false;
|
|
remainTime = 0f;
|
|
|
|
var meshTrans = _lightObj.transform.GetChild(0);
|
|
_meshRenderer = meshTrans.GetComponent<MeshRenderer>();
|
|
_currentAlpha = 0;
|
|
_cacheMatBlock.SetFloat(Alpha, _currentAlpha);
|
|
_meshRenderer.SetPropertyBlock(_cacheMatBlock);
|
|
}
|
|
|
|
public void LightUp()
|
|
{
|
|
isLight = true;
|
|
_lightObj.SetActive(true);
|
|
}
|
|
|
|
public void LightOff()
|
|
{
|
|
isLight = false;
|
|
_lightObj.SetActive(false);
|
|
}
|
|
|
|
public void MarkLight(float duringTime)
|
|
{
|
|
remainTime = Mathf.Max(duringTime, remainTime);
|
|
if (!isLight)
|
|
{
|
|
LightUp();
|
|
}
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
if (isLight)
|
|
{
|
|
if (_currentAlpha < 1)
|
|
{
|
|
var wrapDt = Mathf.Max(dt, 0.016f);
|
|
_currentAlpha += wrapDt * LIGHT_UP_SPEED;
|
|
_currentAlpha = Mathf.Min(1, _currentAlpha);
|
|
_cacheMatBlock.SetFloat(Alpha, _currentAlpha);
|
|
_meshRenderer.SetPropertyBlock(_cacheMatBlock);
|
|
}
|
|
if (SkillManager.instance.needSkillPaused)
|
|
{
|
|
return;
|
|
}
|
|
remainTime -= dt;
|
|
if (remainTime < 0)
|
|
{
|
|
LightOff();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_currentAlpha > 0)
|
|
{
|
|
var wrapDt = Mathf.Max(dt, 0.016f);
|
|
if (SkillManager.instance.needSkillPaused)
|
|
{
|
|
wrapDt = 0;
|
|
}
|
|
_currentAlpha -= wrapDt * LIGHT_OFF_SPEED;
|
|
_currentAlpha = Mathf.Max(0, _currentAlpha);
|
|
_cacheMatBlock.SetFloat(Alpha, _currentAlpha);
|
|
_meshRenderer.SetPropertyBlock(_cacheMatBlock);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|