Skip to content

Instantly share code, notes, and snippets.

@adammyhre
adammyhre / Smooth Follow
Created August 31, 2024 16:14
Smooth Follow Spline Auto Dolly for Cinemachine 3.1.1 Example
using System;
using Unity.Cinemachine;
using UnityEngine;
using UnityEngine.Splines;
[Serializable]
public class SmoothFollow : SplineAutoDolly.ISplineAutoDolly {
[Tooltip("Maximum speed of the dolly along the spline.")]
public float MaxSpeed = 0.5f;
@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 September 1, 2024 13:05
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 August 20, 2024 01:45
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 July 19, 2024 12:20
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 June 29, 2024 06:53
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 July 28, 2024 15:28
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 July 28, 2024 15:28
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