Skip to content

Instantly share code, notes, and snippets.

@ShuraProgerMain
Last active October 9, 2023 20:54
Show Gist options
  • Save ShuraProgerMain/0e95cf1b4b9ec1f31d9142cf6eec3613 to your computer and use it in GitHub Desktop.
Save ShuraProgerMain/0e95cf1b4b9ec1f31d9142cf6eec3613 to your computer and use it in GitHub Desktop.
GraduateHelper
using System;
using System.Threading.Tasks;
using UnityEngine;
namespace Helpers
{
public static class GraduateHelper
{
public static async void Graduate(Action<float> action, float duration, bool reverse = false)
{
try
{
await GraduateAsync(action, duration, reverse);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
public static async Task GraduateAsync(Action<float> action, float duration, bool reverse = false)
{
for (var time = 0f; time < duration; time += Time.deltaTime)
{
var ratio = time / duration;
ratio = reverse ? 1f - ratio : ratio;
var progress = ratio;
action.Invoke(progress);
await Task.Yield();
}
action.Invoke(reverse ? 0f : 1f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment