using System; using System.Collections; using System.Collections.Generic; using System.Threading; using BITKit; using BITKit.Tween; using Cysharp.Threading.Tasks; using NodeCanvas.Framework; using UnityEngine; using UnityEngine.UI; using Object = UnityEngine.Object; namespace Net.Project.B.NodeCanvas { public class BlackScreenTask : ActionTask { [RuntimeInitializeOnLoadMethod] private static void Reload() { var newGo = new GameObject("black screen"); var canvas = newGo.AddComponent(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvas.vertexColorAlwaysGammaSpace = true; Object.DontDestroyOnLoad(newGo); var newImageGo = new GameObject("image"); newImageGo.transform.SetParent(newGo.transform); var image = newImageGo.AddComponent(); image.color = Color.clear; image.raycastTarget = false; image.rectTransform.anchorMin = Vector2.zero; image.rectTransform.anchorMax = Vector2.one; image.rectTransform.sizeDelta = Vector2.zero; image.rectTransform.anchoredPosition = Vector2.zero; _image = image; } private static Image _image; private static CancellationTokenSource _cancellationTokenSource; protected override async void OnExecute() { _cancellationTokenSource?.Cancel(); _cancellationTokenSource = new CancellationTokenSource(); try { await BITween.Lerp(x => _image.color = x, Color.clear, Color.black, 1f, Color.Lerp, _cancellationTokenSource.Token); } catch (OperationCanceledException) { return; } finally { EndAction(); } try { await UniTask.NextFrame(); await UniTask.NextFrame(); await BITween.Lerp(x => _image.color = x, Color.black, Color.clear, 1f, Color.Lerp, _cancellationTokenSource.Token); } catch (OperationCanceledException) { } } protected override void OnStop(bool interrupted) { if (interrupted) { _cancellationTokenSource?.Cancel(); } } } }