Skip to content

Instantly share code, notes, and snippets.

@adammyhre
adammyhre / UniTaskHelpers.cs
Created August 25, 2024 18:29
A helper class for UniTask that implements a WhenAllSettled method, allowing all tasks to complete and capturing both successful results and exceptions.
using System;
using Cysharp.Threading.Tasks;
/// <summary>
/// Provides helper methods for working with UniTask, including methods to await multiple tasks
/// and capture their results or exceptions.
/// </summary>
public class UniTaskHelpers {
/// <summary>
/// Awaits two UniTasks and returns a tuple containing the results or exceptions for each task.
@adammyhre
adammyhre / FixUnityBrokenSelectionBase.cs
Created August 7, 2024 19:27
Custom Unity Editor Script to Fix [SelectionBase] for Consistent Parent Selection
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
// Put this in an Editor folder
[InitializeOnLoad]
public class FixUnityBrokenSelectionBase : Editor {
static List<Object> newSelection;
static Object[] lastSelection = { };
@adammyhre
adammyhre / ProjectSetup.cs
Last active April 7, 2026 09:08
Automated Unity Project Setup Script
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
using static System.Environment;
@adammyhre
adammyhre / GravityWell.cs
Last active February 26, 2026 20:31
Player Controller Sandbox Scripts
using UnityEngine;
using UnityUtils;
[RequireComponent(typeof(TriggerArea))]
public class GravityWell : MonoBehaviour {
TriggerArea triggerArea;
void Start() {
triggerArea = GetComponent<TriggerArea>();
}
@adammyhre
adammyhre / AnimationSystem.cs
Created July 14, 2024 02:01
AnimationSystem with Audio and Awaitables
using System;
using UnityEngine.Animations;
using UnityEngine.Playables;
using UnityEngine;
[Serializable]
public class AnimationConfig {
public Animator animator;
public AnimationClip idleClip;
public AnimationClip walkClip;
@adammyhre
adammyhre / AnimationSystem.cs
Last active May 12, 2025 04:31
Simple Wrapper for Unity Playables API
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;
using MEC; // Uses More Effective Coroutines from the Unity Asset Store
public class AnimationSystem {
PlayableGraph playableGraph;
readonly AnimationMixerPlayable topLevelMixer;
@adammyhre
adammyhre / AnimatorControllerCloneTool.cs
Last active September 23, 2024 03:15
Code to clone an existing Animator Controller Asset with or without Motions
using UnityEditor;
using UnityEditor.Animations;
public static class AnimatorControllerCloneTool {
[MenuItem("Assets/Clone Animator Controller", true)]
static bool CanCloneAnimatorController() {
return Selection.activeObject is AnimatorController;
}
[MenuItem("Assets/Clone Animator Controller")]
@adammyhre
adammyhre / MemorySnapshotter.cs
Last active May 11, 2025 16:38
Utility for taking Unity Memory Snapshots Programmatically
using System;
using System.IO;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Profiling;
using Unity.Profiling.Memory;
using UnityEngine;
public class MemorySnapshotter {
const string capturesFolder = "MemoryCaptures";
@adammyhre
adammyhre / ComponentCopier.cs
Last active March 11, 2026 17:01
Copy and Paste All Components Between GameObjects
#if UNITY_EDITOR
using UnityEditorInternal;
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
/// <summary>
/// A Unity editor extension for copying and pasting all components between GameObjects.
/// The tool supports handling multiple components of the same type and correctly restores
@adammyhre
adammyhre / PriorityQueue.cs
Last active February 17, 2025 14:43
Double Key Priority Queue for Unity C#
using System;
using System.Collections.Generic;
using UnityUtils;
public class PriorityQueue<T> {
class KeyNodeComparer : IComparer<(Key, T)> {
public int Compare((Key, T) x, (Key, T) y) {
return x.Item1 < y.Item1 ? -1 : x.Item1 > y.Item1 ? 1 : 0;
}
}