Skip to content

Instantly share code, notes, and snippets.

Sascha Graeff FlaShG

  • Hamburg
View GitHub Profile
@FlaShG
FlaShG / FavoritesWindow.cs
Created Aug 5, 2020
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
{
@FlaShG
FlaShG / CanvasPositioningExtensions.cs
Last active Jul 30, 2020
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.
/// Usage:
/// objectOnCanvasRectTransform.anchoredPosition = specificCanvas.WorldToCanvasPoint(worldspaceTransform.position);
/// </summary>
public static class CanvasPositioningExtensions
{
@FlaShG
FlaShG / FixedUpdateInterpolation.cs
Last active Jul 20, 2020
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 / FloatRange.cs
Last active Jun 24, 2020
A small struct representing a range from min to max.
View FloatRange.cs
using UnityEngine;
[System.Serializable]
public struct FloatRange
{
public float min;
public float max;
public float range { get { return Mathf.Abs(max - min); } }
public FloatRange(float min, float max)
@FlaShG
FlaShG / Invoker.cs
Last active Mar 2, 2020
A replacement for Unity's MonoBehaviour.Invoke and MonoBehaviour.InvokeRepeating, with extra features.
View Invoker.cs
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 / UsePropertyNameAttribute.cs
Last active Jan 8, 2020
Fix the display name when serializing property backing fields in Unity.
View UsePropertyNameAttribute.cs
using UnityEngine;
/// <summary>
/// Use this attribute in combination with a [SerializeField] attribute on top of a property to display the property name. Example:
/// [field: SerializeField, UsePropertyName]
/// public int number { get; private set; }
/// </summary>
public class UsePropertyNameAttribute : PropertyAttribute
{
@FlaShG
FlaShG / MyStaticCode.cs
Last active Jan 5, 2020
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 / Placr.cs
Last active Oct 27, 2019
Placr increases your level design speed by letting you place objects quickly. https://youtu.be/nm57A2ySfIY
View Placr.cs
using UnityEngine;
using UnityEditor;
/// <summary>
/// Placr increases your level design speed by letting you place objects quickly.
/// Enable Placr in the scene view and select a Prefab or 3D model in your project view.
/// * Left click to place the object.
/// * Right click to de-select the object.
/// * Hold Ctrl to rotate the object with your mouse.
/// * Hold Shift to change the vertical offset. Re-select your asset to reset it.
@FlaShG
FlaShG / GizmosColor.cs
Last active Oct 9, 2019
Temprarily set a color to be used for Gizmos and Handles.
View GizmosColor.cs
using UnityEngine;
using System;
/// <summary>
/// Temprarily set a color to be used for Gizmos.
/// <example>
/// <code>
/// using (new GizmosColor(Color.red))
/// {
@FlaShG
FlaShG / Benchmark.cs
Last active Sep 16, 2019
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.
You can’t perform that action at this time.