chip-gameV3/Assets/Scripts/Settings/ScreenTestPanel.cs

58 lines
1.7 KiB
C#

using System;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
public sealed class ScreenTestPanel : MonoBehaviour, IControlable
{
public event Action OnClosed;
[SerializeField] private CanvasGroup _canvasGroup;
[SerializeField] private Image _background;
[SerializeField] private float _fadeDuration = 0.35f;
[SerializeField] private float _rgbAnimationDuration = 5f;
private Sequence _animation;
public bool ControlsEnabled { get; set; }
private void OnDisable()
{
_animation?.Kill();
_animation = null;
ControlsEnabled = false;
}
public void Open()
{
_animation?.Kill();
transform.SetAsLastSibling();
_canvasGroup.alpha = 0f;
_canvasGroup.blocksRaycasts = true;
_background.color = Color.red;
ControlsEnabled = true;
float colorStepDuration = _rgbAnimationDuration / 3f;
_animation = DOTween.Sequence();
_animation.Append(_canvasGroup.DOFade(1f, _fadeDuration).SetEase(Ease.OutCubic));
_animation.Append(_background.DOColor(Color.green, colorStepDuration).SetEase(Ease.Linear));
_animation.Append(_background.DOColor(Color.blue, colorStepDuration).SetEase(Ease.Linear));
_animation.Append(_background.DOColor(Color.red, colorStepDuration).SetEase(Ease.Linear));
_animation.Append(_canvasGroup.DOFade(0f, _fadeDuration).SetEase(Ease.InCubic));
_animation.SetUpdate(true);
_animation.OnComplete(Close);
_animation.PlayForward();
}
public void UpdateControls()
{
}
private void Close()
{
ControlsEnabled = false;
_canvasGroup.blocksRaycasts = false;
OnClosed?.Invoke();
}
}