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 / 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 / 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 / ClassicEditorArrowMovement.cs
Last active July 18, 2018 14:24
A Unity editor script for enabling pre-2018.x scene view camera behaviour for arrow keys.
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
/// <summary>
/// Re-enables pre-2018.x scene view camera behaviour for arrow keys.
/// Allows the user to move the scene view camera on a horizontal plane.
/// </summary>
public static class ClassicEditorArrowMovement
{
@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 / EventOrderTest.cs
Last active April 28, 2019 11:22
Learn about Unity's event order when initializing an object.
using UnityEngine;
public class EventOrderTest : MonoBehaviour
{
private bool firstUpdate = true;
private void Awake()
{
Log("Awake");
}
@FlaShG
FlaShG / WeakReferenceExtensions.cs
Created July 25, 2019 18:00
Extension methods to create simple code around working with WeakReferences referencing UnityEngine.Objects.
using UnityEngine;
/// <summary>
/// Extension methods to create simple code around working with WeakReferences referencing UnityEngine.Objects.
/// </summary>
public static class WeakReferenceExtensions
{
/// <summary>
/// Destroys the referenced object if it still exists.
/// Does nothing if no object is referenced or the referenced object is already destroyed.
@FlaShG
FlaShG / ParticleManipulator.cs
Last active February 17, 2021 10:22
A superclass for classes that manipulate particles in Update.
using UnityEngine;
/// <summary>
/// Create a subclass of this class to manipulate particles in Update any way you see fit.
/// </summary>
[RequireComponent(typeof(ParticleSystem))]
[ExecuteInEditMode]
public abstract class ParticleManipulator : MonoBehaviour
{
new protected ParticleSystem particleSystem { get; private set; }
@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 / GizmosColor.cs
Last active August 19, 2021 18:52
Temprarily set a color to be used for Gizmos and Handles.
using UnityEngine;
using System;
/// <summary>
/// Temporarily set a color to be used for Gizmos.
/// <example>
/// <code>
/// using (new GizmosColor(Color.red))
/// {