Skip to content

Instantly share code, notes, and snippets.

View FlaShG's full-sized avatar

Sascha Graeff FlaShG

View GitHub Profile
@FlaShG
FlaShG / FBXAxesFixer.cs
Last active August 29, 2015 14:16
This AssetPostprocessor switches the Y and Z axes of imported FBX files (and everything converted to FBX from Unity).
using UnityEngine;
using UnityEditor;
public class FBXAxesFixer : AssetPostprocessor
{
void OnPostprocessModel(GameObject g)
{
if(assetImporter.ToString() == " (UnityEngine.FBXImporter)")
{
FixFBXImport(g.transform, 0);
@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 / FixedUpdateInterpolation.cs
Last active May 11, 2023 21:16
Interpolates a GameObject's position and rotation while being updated in FixedUpdate.
using UnityEngine;
using UnityEngine.LowLevel;
using System.Collections.Generic;
using UnityEngine.PlayerLoop;
/// <summary>
/// Interpolates a GameObject's position and rotation while being updated in FixedUpdate.
/// </summary>
public class FixedUpdateInterpolation : MonoBehaviour
@FlaShG
FlaShG / CoroutinePoolThread.cs
Last active October 28, 2018 20:09
Small classes that allow for comfortably executing a single thread or a threadpool task in a coroutine.
using UnityEngine;
using System;
using System.Threading;
/// <summary>
/// Orders the Threadpool to perform an action and waits until it's done.
/// Use for short actions that maybe are performed more often.
/// </summary>
public class CoroutinePoolThread : CustomYieldInstruction
{
@FlaShG
FlaShG / Placr.md
Last active July 20, 2021 12:36
Placr increases your level design speed by letting you place objects quickly. https://youtu.be/nm57A2ySfIY
@FlaShG
FlaShG / MyStaticCode.cs
Last active January 25, 2022 15:29
Execute any code based on Unity events without having to drag a component into a scene.
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 / SetScriptExecutionOrder.cs
Last active July 4, 2018 16:24
Add this to a MonoBehaviour to set its Script Execution Order without access to the editor.
#if UNITY_EDITOR
private const int executionOrder = -1000;
[UnityEditor.InitializeOnLoadMethod]
private static void SetScriptOrder()
{
var go = new GameObject("Temp");
var monoScript = UnityEditor.MonoScript.FromMonoBehaviour(go.AddComponent<NAME_OF_THIS_MONOBEHAVIOUR>());
if (UnityEditor.MonoImporter.GetExecutionOrder(monoScript) != executionOrder)
{
@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 / PathAttribute.cs
Last active July 4, 2018 16:20
Allows setting a string in the Unity Editor by dragging a file or folder from outside the editor.
using UnityEngine;
public class PathAttribute : PropertyAttribute
{
}
@FlaShG
FlaShG / FloatRange.cs
Last active May 30, 2023 10:28
A small struct representing a range from min to max.
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)