Files
Main/Assets/Code/Logic/_Required/Entity/Character/Utils/HitBlinker.cs
2025-01-25 04:38:09 +08:00

75 lines
2.1 KiB
C#

using Thousandto.Core.Asset;
using UnityEngine;
namespace Thousandto.Code.Logic
{
//受击闪烁器
public class HitBlinker
{
#region//私有变量
private float _timer = 0f;
private float _lifeTime = 0f;
private float _power = 0f;
private Color _color = Color.white;
private AnimationCurve _curve = null;
private FSkinModel _handleSkin = null;
private bool _running = false;
#endregion
#region//属性
public bool IsRunning
{
get
{
return _running;
}
}
#endregion
#region//公有函数
public void Start(float time, float power, Color color, AnimationCurve curve, FSkinModel skin)
{
if (time <= 0f || curve == null || skin == null)
return;
if (skin.SkinStatus == FSkinStatusCode.Dead)
return;
_timer = 0f;
_lifeTime = time;
_power = power;
_color = color;
_curve = curve;
_handleSkin = skin;
_handleSkin.SetStatus(FSkinStatusCode.BeHit);
_handleSkin.SetColor(FSkinPartCode.Body, ShaderPropertyIDDefine.RimColor, _color);
_handleSkin.SetFloat(FSkinPartCode.Body, ShaderPropertyIDDefine.RimPower, (1f - _curve.Evaluate(0f)) * _power);
_running = true;
}
public void Update(float dt)
{
if (!_running)
return;
_timer += dt;
if (_timer >= _lifeTime)
{
_running = false;
}
_handleSkin.SetFloat(FSkinPartCode.Body, ShaderPropertyIDDefine.RimPower, (1f - _curve.Evaluate(_timer / _lifeTime)) * _power);
if (!_running)
{
if (_handleSkin.SkinStatus == FSkinStatusCode.BeHit)
{
_handleSkin.SetStatus(FSkinStatusCode.Normal);
}
_handleSkin = null;
}
}
#endregion
}
}