52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using UnityEngine;
|
|
using DG.Tweening;
|
|
|
|
public class HeatLineSegmentController : MonoBehaviour
|
|
{
|
|
private LineRenderer lineRenderer;
|
|
private Sequence sequence;
|
|
|
|
public float duration = 4f; // 整个冷却淡出时间
|
|
public Color hotColor = Color.red;
|
|
public Color coldColor = Color.black;
|
|
|
|
void Awake()
|
|
{
|
|
lineRenderer = GetComponent<LineRenderer>();
|
|
if (lineRenderer == null)
|
|
{
|
|
Debug.LogError("HeatLineSegmentController需要LineRenderer组件");
|
|
}
|
|
lineRenderer.startColor = lineRenderer.endColor = hotColor;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
// 创建颜色渐变序列
|
|
sequence = DOTween.Sequence();
|
|
|
|
// 颜色从热色到冷色
|
|
sequence.Append(DOTween.To(() => lineRenderer.startColor, x => {
|
|
lineRenderer.startColor = x;
|
|
lineRenderer.endColor = x;
|
|
}, coldColor, duration * 0.7f).SetEase(Ease.InOutQuad));
|
|
|
|
// 淡出效果
|
|
sequence.Append(DOTween.To(() => lineRenderer.startColor.a, x => {
|
|
Color c = lineRenderer.startColor;
|
|
c.a = x;
|
|
lineRenderer.startColor = c;
|
|
lineRenderer.endColor = c;
|
|
}, 0f, duration * 0.3f).SetEase(Ease.InQuad));
|
|
|
|
// 完成后销毁对象
|
|
sequence.OnComplete(() => Destroy(gameObject));
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
// 清理DOTween序列
|
|
sequence?.Kill();
|
|
}
|
|
}
|