Skip to content

Instantly share code, notes, and snippets.

View FlaShG's full-sized avatar

Sascha Graeff FlaShG

View GitHub Profile
@FlaShG
FlaShG / CoroutineEvent.cs
Last active August 17, 2023 19:41
An event class for Unity that can run coroutines.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// An event that can run coroutines.
/// Invoking it returns an IEnumerator that can be waited for in another coroutine.
/// The Invocation waits until all registered coroutines are finished.
/// </summary>
@FlaShG
FlaShG / Invoker.cs
Last active September 4, 2023 09:47
A replacement for Unity's MonoBehaviour.Invoke and MonoBehaviour.InvokeRepeating, with extra features.
using System;
using System.Collections;
using UnityEngine;
/// <summary>
/// Replaces MonoBehaviour.Invoke and MonoBehaviour.InvokeRepeating
/// with a more sophisticated attempt. Namely: No strings involved.
/// Use like this:
/// StartCoroutine(Invoker.Invoke(MyMethod, 2));
/// </summary>
@FlaShG
FlaShG / Benchmark.cs
Last active January 3, 2024 15:40
A C# Benchmark class.
using System;
using System.Diagnostics;
/// <summary>
/// Simple benchmark class to measure average time consumption of code.
/// </summary>
public static class Benchmark
{
/// <summary>
/// A benchmark's time result.
@FlaShG
FlaShG / FavoritesWindow.cs
Last active March 14, 2024 04:53
A Unity EditorWindow to pin objects to for quick selection.
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Collections.Generic;
/// <summary>
/// An editor window that lets you store assets and GameObjects in it for quickly finding them again.
/// </summary>
public class FavoritesWindow : EditorWindow, IHasCustomMenu
{
@FlaShG
FlaShG / CanvasPositioningExtensions.cs
Last active April 26, 2024 12:46
A small Unity helper class to convert viewport, screen or world positions to canvas space.
using UnityEngine;
/// <summary>
/// Small helper class to convert viewport, screen or world positions to canvas space.
/// Only works with screen space canvases.
/// </summary>
/// <example>
/// <code>
/// objectOnCanvasRectTransform.anchoredPosition = specificCanvas.WorldToCanvasPoint(worldspaceTransform.position);
/// </code>