Created
April 20, 2022 11:20
-
-
Save inoook/6de3d834d1a2b13006e69b1d0d1c075a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using System.Runtime.CompilerServices; | |
using UnityEngine; | |
public class FadeTransition | |
{ | |
[SerializeField] CanvasGroup canvasGroup = null; | |
public FadeTransition(CanvasGroup canvasGroup) { | |
this.canvasGroup = canvasGroup; | |
this.canvasGroup.alpha = 0; | |
} | |
public async Task StartFade(float time, float to, System.Action onComplete = null) { | |
var tween = LeanTween.value(canvasGroup.gameObject, canvasGroup.alpha, to, time).setOnUpdate((v) => { | |
canvasGroup.alpha = v; | |
}); | |
await tween; | |
onComplete?.Invoke(); | |
} | |
} | |
public static class LeanTweenExtension | |
{ | |
public static TaskAwaiter<bool> GetAwaiter(this LTDescr leanTween) | |
{ | |
var tcs = new TaskCompletionSource<bool>(); | |
leanTween.setOnComplete(() => { | |
tcs.SetResult(true); | |
}); | |
return tcs.Task.GetAwaiter(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment