131 lines
3.2 KiB
C#
131 lines
3.2 KiB
C#
using UnityEngine;
|
|
using Core.SceneLoading;
|
|
using UnityEngine.InputSystem;
|
|
|
|
using DG.Tweening;
|
|
using Michsky.UI.Reach;
|
|
|
|
public class PressToContinue : MonoBehaviour
|
|
{
|
|
[SerializeField] FeedNotification notification;
|
|
[SerializeField] CanvasGroup notificationCanvasGroup;
|
|
[SerializeField, Range(0f, 1f)] float minAlpha = 0.25f;
|
|
[SerializeField, Range(0f, 1f)] float maxAlpha = 1f;
|
|
[SerializeField] float blinkDuration = 1.2f;
|
|
[SerializeField] float blinkStartDelay = 1f;
|
|
|
|
Tween blinkTween;
|
|
Tween blinkDelayTween;
|
|
bool isShown;
|
|
|
|
void Awake()
|
|
{
|
|
if (notification == null)
|
|
{
|
|
notification = FindObjectOfType<FeedNotification>(true);
|
|
}
|
|
|
|
if (notificationCanvasGroup == null && notification != null)
|
|
{
|
|
notificationCanvasGroup = notification.GetComponent<CanvasGroup>();
|
|
if (notificationCanvasGroup == null)
|
|
{
|
|
notificationCanvasGroup = notification.gameObject.AddComponent<CanvasGroup>();
|
|
}
|
|
}
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
isShown = false;
|
|
|
|
if (StartupSceneLoader.Instance != null)
|
|
{
|
|
StartupSceneLoader.Instance.BeginLoad();
|
|
}
|
|
}
|
|
|
|
void LateUpdate()
|
|
{
|
|
if (StartupSceneLoader.Instance == null) return;
|
|
|
|
if (!isShown && StartupSceneLoader.Instance.IsLoadComplete())
|
|
{
|
|
ShowNotification();
|
|
}
|
|
|
|
if (!isShown) return;
|
|
if (Keyboard.current == null) return;
|
|
if (!Keyboard.current.anyKey.wasPressedThisFrame) return;
|
|
|
|
StartupSceneLoader.Instance.ActivateLoadedScene();
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
StopBlink();
|
|
}
|
|
|
|
void ShowNotification()
|
|
{
|
|
if (notification == null) return;
|
|
|
|
notification.defaultState = FeedNotification.DefaultState.Expanded;
|
|
notification.minimizeAfter = 0f;
|
|
isShown = true;
|
|
|
|
if (notificationCanvasGroup != null)
|
|
{
|
|
notificationCanvasGroup.alpha = maxAlpha;
|
|
}
|
|
|
|
StopBlink();
|
|
notification.ExpandNotification();
|
|
StartBlinkAfterDelay();
|
|
}
|
|
|
|
void StartBlinkAfterDelay()
|
|
{
|
|
if (notificationCanvasGroup == null) return;
|
|
|
|
if (blinkDelayTween != null && blinkDelayTween.IsActive())
|
|
{
|
|
blinkDelayTween.Kill();
|
|
}
|
|
|
|
blinkDelayTween = DOVirtual.DelayedCall(blinkStartDelay, StartBlink).SetUpdate(true);
|
|
}
|
|
|
|
void StartBlink()
|
|
{
|
|
if (notificationCanvasGroup == null) return;
|
|
|
|
if (blinkTween != null && blinkTween.IsActive())
|
|
{
|
|
blinkTween.Kill();
|
|
}
|
|
|
|
notificationCanvasGroup.alpha = maxAlpha;
|
|
blinkTween = DOTween
|
|
.To(() => notificationCanvasGroup.alpha, a => notificationCanvasGroup.alpha = a, minAlpha, blinkDuration)
|
|
.SetEase(Ease.InOutSine)
|
|
.SetLoops(-1, LoopType.Yoyo)
|
|
.SetUpdate(true);
|
|
}
|
|
|
|
void StopBlink()
|
|
{
|
|
if (blinkDelayTween != null && blinkDelayTween.IsActive())
|
|
{
|
|
blinkDelayTween.Kill();
|
|
}
|
|
blinkDelayTween = null;
|
|
|
|
if (blinkTween != null && blinkTween.IsActive())
|
|
{
|
|
blinkTween.Kill();
|
|
}
|
|
blinkTween = null;
|
|
}
|
|
}
|