Cute_demon_attacks/meng_yao/Assets/script/A_Fight/ScreenFlashEffect.cs

54 lines
1.4 KiB
C#
Raw Normal View History

using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class ScreenFlashEffect : MonoBehaviour
{
public Image screenEdgeImage; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>˸<EFBFBD><CBB8>UIԪ<49>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD>ı<EFBFBD>ԵЧ<D4B5><D0A7><EFBFBD><EFBFBD>
public float flashDuration = 1f; // ÿ<><C3BF><EFBFBD><EFBFBD>˸<EFBFBD>ij<EFBFBD><C4B3><EFBFBD>ʱ<EFBFBD><CAB1>
public Color flashColor = new Color(1f, 0f, 0f, 0.5f); // <20><>ɫ͸<C9AB><CDB8><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD>ɫ
public float flashInterval = 1f; // <20><>˸<EFBFBD><CBB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>0.5<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸һ<EFBFBD>Σ<EFBFBD>
void Update()
{
if (Input.GetKeyDown(KeyCode.P)) //
{
StartFlashing();
}
else if (Input.GetKeyDown(KeyCode.I)) //
{
StopFlashing();
}
}
private void Start()
{
// <20><>ʼ<EFBFBD><CABC>͸<EFBFBD><CDB8>״̬
screenEdgeImage.color = new Color(0, 0, 0, 0); // <20><>ʼ͸<CABC><CDB8>
}
public void StartFlashing()
{
// ʹ<><CAB9>DOTween<65><6E>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8><EFBFBD><EFBFBD>
Sequence sequence = DOTween.Sequence();
// 1. <20><><EFBFBD><EFBFBD><E4B5BD>ɫ
sequence.Append(screenEdgeImage.DOColor(flashColor, flashDuration).SetEase(Ease.InOutQuad));
// 2. <20>ٽ<EFBFBD><D9BD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD><CDB8>
sequence.Append(screenEdgeImage.DOColor(new Color(0, 0, 0, 0), flashDuration).SetEase(Ease.InOutQuad));
// 3. ѭ<><D1AD><EFBFBD><EFBFBD>˸
sequence.SetLoops(-1, LoopType.Yoyo); // <20><><EFBFBD>޴<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Yoyo<79><6F>
}
public void StopFlashing()
{
// ȡ<><C8A1><EFBFBD><EFBFBD>˸Ч<CBB8><D0A7>
screenEdgeImage.color = new Color(0, 0, 0, 0); // <20>ָ<EFBFBD>͸<EFBFBD><CDB8>
DOTween.Kill(screenEdgeImage); // ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>DOTween<65><6E><EFBFBD><EFBFBD>
}
}