Skip to content

Instantly share code, notes, and snippets.

View thebeardphantom's full-sized avatar

Mika Notarnicola thebeardphantom

View GitHub Profile
using System;
using System.Linq;
using UnityEditor;
using UnityEditor.ShortcutManagement;
using UnityEngine;
[InitializeOnLoad]
public class PlayModeShortcutManagerProfileUtility
{
#region Types
@thebeardphantom
thebeardphantom / TaskData.cs
Last active February 16, 2022 10:32
Simple, efficient task scheduler for Unity using SortedSet<T>.
using UnityEngine;
public readonly struct TaskData
{
#region Fields
public readonly double ExecTime;
public readonly double DelayTime;
@thebeardphantom
thebeardphantom / ILiteEvent.cs
Last active February 12, 2022 23:06
A reimplementation of C# events for Unity 2020+ that's lighter on GC.
using System;
namespace BeardPhantom.LiteEvent
{
public interface ILiteEvent<in TDelegate> where TDelegate : Delegate
{
#region Properties
int ListenerCount { get; }
@thebeardphantom
thebeardphantom / AdvancedDropdownField.cs
Last active January 30, 2022 23:42
A very simple wrapper around IMGUI's AdvancedDropdown for UI Toolkit.
public class AdvancedDropdownField : DropdownField
{
#region Types
private class SimpleAdvancedDropdown : AdvancedDropdown
{
#region Fields
private readonly DropdownField _dropdownField;
using Cysharp.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using UnityEditor;
using UnityEditor.Recorder;
using UnityEditor.Recorder.Input;
using UnityEngine;
[DefaultExecutionOrder(-50)]
public class IconRecorder : MonoBehaviour
@thebeardphantom
thebeardphantom / UnityNullCheck.cs
Last active October 12, 2021 19:07
Useful if you don't know the type of an object and you want to ensure you don't bypass Unity's native-side null checks.
public static bool IsNull<T>(this T obj) where T : class
{
if(obj is UnityEngine.Object unityObj)
{
/* Invokes Unity's custom == check for nulls.
* This case technically only works because obj is
* a "fake null" on the C# side by this point.
* If its a true null it'd hit the else case instead,
* which fortunately still returns what we want.
*/
@thebeardphantom
thebeardphantom / FastNoiseRNG.cs
Created December 16, 2020 10:27
A mechanism to use FastNoiseLite as a proper RNG class.
using System.Collections.Generic;
using UnityEngine;
public class FastNoiseRNG : FastNoiseLite
{
#region Fields
private ulong _position;
#endregion
using UnityEngine;
public sealed class ReferenceDrawerAttribute : PropertyAttribute { }
@thebeardphantom
thebeardphantom / TilemapGraph.cs
Last active October 29, 2020 06:27
An example of a custom graph that extends A* Pathfinding Project to directly use a Unity Tilemap for building nodes and navigation. Also uses https://gist.github.com/thebeardphantom/6a05ef68ce6ce7c890c4a4d9afaccf74
using Pathfinding;
using Pathfinding.Serialization;
using Pathfinding.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Tilemaps;
[Preserve]
@thebeardphantom
thebeardphantom / SmoothDampState.cs
Last active September 24, 2020 07:05
A serializable struct wrapper for smooth damping. Debug inspector will show you Current Value and Velocity!
using System;
using UnityEngine;
[Serializable]
public struct SmoothDampState
{
#region Fields
public float Damping;