Skip to content

Instantly share code, notes, and snippets.

View FlaShG's full-sized avatar

Sascha Graeff FlaShG

View GitHub Profile
@FlaShG
FlaShG / CoroutineEvent.cs
Last active August 17, 2023 19:41
An event class for Unity that can run coroutines.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// An event that can run coroutines.
/// Invoking it returns an IEnumerator that can be waited for in another coroutine.
/// The Invocation waits until all registered coroutines are finished.
/// </summary>
@FlaShG
FlaShG / RuntimeSceneReference.cs
Created May 7, 2023 12:47
A serializable struct for referencing and, at runtime, handle scenes.
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.SceneManagement;
[System.Serializable]
public struct RuntimeSceneReference : ISerializationCallbackReceiver
{
@FlaShG
FlaShG / FavoritesWindow.cs
Last active March 14, 2024 04:53
A Unity EditorWindow to pin objects to for quick selection.
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 / 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))
/// {
@FlaShG
FlaShG / UsePropertyNameAttribute.cs
Last active January 20, 2023 07:18
Fix the display name when serializing property backing fields in Unity.
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 / 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 / HideFlagsUtility.cs
Last active September 30, 2024 13:30
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 / 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 / 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 / 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()