Skip to content

Instantly share code, notes, and snippets.

View FlaShG's full-sized avatar

Sascha Graeff FlaShG

View GitHub Profile
@FlaShG
FlaShG / CoroutineWorker.cs
Last active September 7, 2021 07:44
Based on MyStaticCode.cs, a class that allows anything to run coroutines from anywhere.
using UnityEngine;
using System.Collections;
public static class CoroutineWorker
{
private class Worker : MonoBehaviour { }
private static Worker worker;
[RuntimeInitializeOnLoadMethod]
@FlaShG
FlaShG / CanvasPositioningExtensions.cs
Last active February 6, 2024 16:17
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>
@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 / StateMachine.cs
Last active August 21, 2022 15:15
A simple state machine class for Unity. Use it to run regular methods or coroutines as states.
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 / 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 / CorouTweenTest.cs
Last active August 26, 2022 00:56
Very simple Tweens for Unity using Coroutines.
using UnityEngine;
public class CorouTweenTest : MonoBehaviour
{
[SerializeField]
private Vector3 targetPosition;
[SerializeField]
private float duration = 1;
private void Start()
@FlaShG
FlaShG / ConsoleAccessAttribute.cs
Created April 1, 2019 01:19
A simple, easy-to-use console for Unity.
using System;
[AttributeUsage(AttributeTargets.Method)]
public class ConsoleAccessAttribute : Attribute
{
}
@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 / HideFlagsUtility.cs
Last active June 13, 2023 06:12
Shows all GameObjects in the scene with hideFlags, so you can debug them.
using UnityEngine;
using UnityEditor;
public static class HideFlagsUtility
{
[MenuItem("Help/Hide Flags/Show All Objects")]
private static void ShowAll()
{
var allGameObjects = Object.FindObjectsOfType<GameObject>(true);
foreach (var go in allGameObjects)
@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.