1
This commit is contained in:
50
Unity/Scripts/UX/BlackScreen/BlackScreen.cs
Normal file
50
Unity/Scripts/UX/BlackScreen/BlackScreen.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.Events;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class BlackScreen : MonoBehaviour
|
||||
{
|
||||
[Header(Constant.Header.Components)]
|
||||
public UIDocument document;
|
||||
VisualElement root;
|
||||
void Start()
|
||||
{
|
||||
root = document.rootVisualElement;
|
||||
Data.AddListener<UnityAction>("BlackScreen", x =>
|
||||
{
|
||||
CrossFade(x, 0.32f);
|
||||
});
|
||||
root.SetOpacity(1);
|
||||
root.SetActive(false);
|
||||
}
|
||||
void CrossFade(UnityAction action, float duration = 1f)
|
||||
{
|
||||
Sequence sequence = DOTween.Sequence();
|
||||
var enterTween = DOTween.To(root.GetOpacity, root.SetOpacity, 1, duration);
|
||||
var exitTween = DOTween.To(root.GetOpacity, root.SetOpacity, 0, duration);
|
||||
|
||||
sequence.Append(enterTween);
|
||||
sequence.AppendInterval(0.1f);
|
||||
sequence.Append(exitTween);
|
||||
|
||||
enterTween.onComplete += () =>
|
||||
{
|
||||
action.Invoke();
|
||||
};
|
||||
sequence.onComplete += () =>
|
||||
{
|
||||
root.SetActive(false);
|
||||
};
|
||||
|
||||
root.SetActive(true);
|
||||
root.SetOpacity(0);
|
||||
|
||||
sequence.Play();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user