49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using DG.Tweening;
|
||
|
||
public class ScreenFlashEffect : MonoBehaviour
|
||
{
|
||
public Image screenEdgeImage; // 用于显示闪烁的UI元素(整个屏幕的边缘效果)
|
||
public float flashDuration = 1f; // 每次闪烁的持续时间
|
||
public Color flashColor = new Color(1f, 0f, 0f, 0.5f); // 红色透明的渐变颜色
|
||
public float flashInterval = 1f; // 闪烁间隔(比如每隔0.5秒闪烁一次)
|
||
|
||
void Update()
|
||
{
|
||
|
||
|
||
}
|
||
private void Start()
|
||
{
|
||
// 初始化透明状态
|
||
screenEdgeImage.color = new Color(0, 0, 0, 0); // 初始透明
|
||
|
||
}
|
||
|
||
|
||
|
||
public void StartFlashing()
|
||
{
|
||
// 使用DOTween做循环闪烁动画
|
||
Sequence sequence = DOTween.Sequence();
|
||
|
||
// 1. 渐变到红色
|
||
sequence.Append(screenEdgeImage.DOColor(flashColor, flashDuration).SetEase(Ease.InOutQuad));
|
||
|
||
// 2. 再渐变回透明
|
||
sequence.Append(screenEdgeImage.DOColor(new Color(0, 0, 0, 0), flashDuration).SetEase(Ease.InOutQuad));
|
||
|
||
// 3. 循环闪烁
|
||
//sequence.SetLoops(-1, LoopType.Yoyo); // 无限次循环,往返动画(Yoyo)
|
||
|
||
}
|
||
|
||
public void StopFlashing()
|
||
{
|
||
// 取消闪烁效果
|
||
screenEdgeImage.color = new Color(0, 0, 0, 0); // 恢复透明
|
||
DOTween.Kill(screenEdgeImage); // 停止所有DOTween动画
|
||
}
|
||
}
|