Skip to content

Instantly share code, notes, and snippets.

Avatar

Sascha Graeff FlaShG

View GitHub Profile
@FlaShG
FlaShG / HideFlagsUtility.cs
Created Jul 8, 2019
Shows all GameObjects in the scene with hideFlags, so you can debug them.
View HideFlagsUtility.cs
using UnityEngine;
using UnityEditor;
public static class HideFlagsUtility
{
[MenuItem("Help/Hide Flags/Show All Objects")]
private static void ShowAll()
{
var allGameObjects = Object.FindObjectsOfType<GameObject>();
foreach (var go in allGameObjects)
@FlaShG
FlaShG / CanvasPositioningExtensions.cs
Last active Nov 1, 2022
A small Unity helper class to convert viewport, screen or world positions to canvas space.
View CanvasPositioningExtensions.cs
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>
@FlaShG
FlaShG / CorouTweenTest.cs
Last active Aug 26, 2022
Very simple Tweens for Unity using Coroutines.
View CorouTweenTest.cs
using UnityEngine;
public class CorouTweenTest : MonoBehaviour
{
[SerializeField]
private Vector3 targetPosition;
[SerializeField]
private float duration = 1;
private void Start()
@FlaShG
FlaShG / StateMachine.cs
Last active Aug 21, 2022
A simple state machine class for Unity. Use it to run regular methods or coroutines as states.
View StateMachine.cs
using UnityEngine;
using System;
using System.Collections;
/// <summary>
/// A simple state machine class. Use it to run regular methods or coroutines as states.
/// Steps to use:
/// 1. Define a private field for the StateMachine object.
/// private StateMachine stateMachine;
/// 2. Initialize the object in Awake. Pass the MonoBehaviour object to the constructor.
@FlaShG
FlaShG / ConsoleAccessAttribute.cs
Created Apr 1, 2019
A simple, easy-to-use console for Unity.
View ConsoleAccessAttribute.cs
using System;
[AttributeUsage(AttributeTargets.Method)]
public class ConsoleAccessAttribute : Attribute
{
}
@FlaShG
FlaShG / FavoritesWindow.cs
Last active Jul 6, 2022
A Unity EditorWindow to pin objects to for quick selection.
View FavoritesWindow.cs
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 / MyStaticCode.cs
Last active Jan 25, 2022
Execute any code based on Unity events without having to drag a component into a scene.
View MyStaticCode.cs
using UnityEngine;
/// <summary>
/// This template allows to define code that runs independently of any GameObjects or Components created in the editor, even though using Unity events.
/// It can be used for any Scene-independent code, including coroutines, without having to manually add a component to a scene.
/// </summary>
public static class MyStaticCode
{
[RuntimeInitializeOnLoadMethod]
private static void Initialize()
@FlaShG
FlaShG / FixedUpdateInterpolation.cs
Last active Nov 27, 2021
Interpolates a GameObject's position and rotation while being updated in FixedUpdate.
View FixedUpdateInterpolation.cs
using UnityEngine;
using System.Collections;
/// <summary>
/// Interpolates a GameObject's position and rotation while being updated in FixedUpdate.
/// </summary>
[DefaultExecutionOrder(-100)]
public class FixedUpdateInterpolation : MonoBehaviour
{
private Vector3 pos0;
@FlaShG
FlaShG / Benchmark.cs
Last active Sep 7, 2021
A C# Benchmark class.
View Benchmark.cs
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 / CoroutineWorker.cs
Last active Sep 7, 2021
Based on MyStaticCode.cs, a class that allows anything to run coroutines from anywhere.
View CoroutineWorker.cs
using UnityEngine;
using System.Collections;
public static class CoroutineWorker
{
private class Worker : MonoBehaviour { }
private static Worker worker;
[RuntimeInitializeOnLoadMethod]