Skip to content

Instantly share code, notes, and snippets.

View JanikHelbig's full-sized avatar

Janik Helbig JanikHelbig

  • Germany
View GitHub Profile
@JanikHelbig
JanikHelbig / ActionAsync.cs
Last active September 27, 2022 04:42
Asynchronous equivalent of .NET's System.Action and System.Action<T> using UniTask for Unity
public delegate UniTask ActionAsync(CancellationToken cancellationToken);
public delegate UniTask ActionAsync<in T>(T value, CancellationToken cancellationToken);
public static class ActionAsyncExtensions
{
public static UniTask InvokeAsync(this ActionAsync handler, CancellationToken cancellationToken)
{
Delegate[] delegates = handler?.GetInvocationList();
@JanikHelbig
JanikHelbig / PlayModeSceneMenu.cs
Last active April 9, 2021 14:30
Simple utility script that allows to quickly switch to Unity build behaviour in the editor.
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
public static class PlayModeSceneMenu
{
private const string PrefKey = "PLAY_MODE_SCENE_SELECTION";
private const string Path = "Play Mode Scene/";
private const string MenuDefault = "Default (Open Scene)";
private const string MenuEmulate = "Emulate Build Behaviour";
@JanikHelbig
JanikHelbig / EventHandlerAsync.cs
Last active June 24, 2022 06:54
Simple async EventHandler in Unity using Cysharp/UniTask
using System;
using UniRx.Async;
public delegate UniTask EventHandlerAsync(object sender, EventArgs e);
public static class EventHandlerAsyncExtensions
{
public static UniTask InvokeAsync(this EventHandlerAsync handler, object sender, EventArgs e)
{
Delegate[] delegates = handler?.GetInvocationList();