Skip to content

Instantly share code, notes, and snippets.

Avatar

Sascha Graeff FlaShG

  • Hamburg
View GitHub Profile
@FlaShG
FlaShG / FavoritesWindow.cs
Last active Oct 18, 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 / 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 / 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 / WeakReferenceExtensions.cs
Created Jul 25, 2019
Extension methods to create simple code around working with WeakReferences referencing UnityEngine.Objects.
View WeakReferenceExtensions.cs
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
Created Jul 8, 2019
Shows all GameObjects in the scene with hideFlags, so you can debug them.
View HideFlagsUtility.cs
using UnityEngine;
using UnityEditor;
public static class HideFlagsUtility
{
[MenuItem("Help/Hide Flags/Show All Objects")]
private static void ShowAll()
{
var allGameObjects = Object.FindObjectsOfType<GameObject>();
foreach (var go in allGameObjects)
@FlaShG
FlaShG / EventOrderTest.cs
Last active Apr 28, 2019
Learn about Unity's event order when initializing an object.
View EventOrderTest.cs
using UnityEngine;
public class EventOrderTest : MonoBehaviour
{
private bool firstUpdate = true;
private void Awake()
{
Log("Awake");
}
@FlaShG
FlaShG / ConsoleAccessAttribute.cs
Created Apr 1, 2019
A simple, easy-to-use console for Unity.
View ConsoleAccessAttribute.cs
using System;
[AttributeUsage(AttributeTargets.Method)]
public class ConsoleAccessAttribute : Attribute
{
}
@FlaShG
FlaShG / CorouTweenTest.cs
Last active Sep 18, 2018
Very simple Tweens for Unity using Coroutines.
View CorouTweenTest.cs
using UnityEngine;
public class CorouTweenTest : MonoBehaviour
{
[SerializeField]
private Vector3 targetPosition;
[SerializeField]
private float duration = 1;
private void Start()
@FlaShG
FlaShG / ClassicEditorArrowMovement.cs
Last active Jul 18, 2018
A Unity editor script for enabling pre-2018.x scene view camera behaviour for arrow keys.
View ClassicEditorArrowMovement.cs
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 / StateMachine.cs
Last active Jul 17, 2018
A simple state machine class for Unity. Use it to run regular methods or coroutines as states.
View StateMachine.cs
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.
You can’t perform that action at this time.