Skip to content

Instantly share code, notes, and snippets.

@adammyhre
adammyhre / NavWorldBenchmark.cs
Created October 4, 2026 08:45
Unity's new NavMesh API, NavWorld - Unity 6.5
using Unity.AI.Navigation.LowLevel;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
public class NavWorldBenchmark : MonoBehaviour {
@adammyhre
adammyhre / CurveWeights.cs
Created August 30, 2026 12:04
Weighted Loot Tables in Unity
using UnityEngine;
public static class CurveWeights {
public static WeightedEntry[] FromCurve(string[] ids, AnimationCurve curve) {
var entries = new WeightedEntry[ids.Length];
var last = Mathf.Max(1, ids.Length - 1);
for (var i = 0; i < ids.Length; i++) {
var t = ids.Length == 1 ? 0f : (float) i / last;
entries[i] = new WeightedEntry { id = ids[i], weight = Mathf.Max(0f, curve.Evaluate(t)) };
@adammyhre
adammyhre / DoorInteractable.cs
Created August 16, 2026 08:19
Flexible Interaction System for Unity
using System.Collections.Generic;
using UnityEngine;
public class DoorInteractable : MonoBehaviour, IInteractable {
[SerializeField] InteractionUI ui;
bool isOpen;
List<InteractionAction> actions;
public InteractionUI UI => ui;
public List<InteractionAction> GetAvailableActions(Interactor interactor) => actions;
@adammyhre
adammyhre / CrunchBenchmark.cs
Created August 9, 2026 04:58
Zig + Unity: Native Speed for Hot Loops
using System;
using System.Diagnostics;
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;
using Debug = UnityEngine.Debug;
/// <summary>
/// Compares naive C#, Burst (1T + optional MT), and Zig (1T + optional MT) on the same sqdist kernel.
@adammyhre
adammyhre / BoidAgent.cs
Created August 2, 2026 13:43
Simple Boids in Unity
using System.Collections.Generic;
using UnityEngine;
using UnityUtils;
[DisallowMultipleComponent]
public class BoidAgent : MonoBehaviour {
#region Fields
[Header("Movement")]
[SerializeField, Min(0.1f)] float maxSpeed = 7f;
@adammyhre
adammyhre / FogObstacle.cs
Created July 26, 2026 05:12
Interactive Ground Fog for Unity URP
using UnityEngine;
public class FogObstacle : MonoBehaviour {
[SerializeField] float radius = 1.5f;
public float Radius => radius;
}
@adammyhre
adammyhre / ConvertBuiltinMaterialsTool.cs
Created June 28, 2026 06:29
Example Custom MCP Tool for Unity
using Unity.AI.MCP.Editor.Helpers;
using Unity.AI.MCP.Editor.ToolRegistry;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
public enum MaterialConversionScope { All, Selected }
public class ConvertBuiltinMaterialsParams {
[McpDescription(
@adammyhre
adammyhre / Colorize.hlsl
Last active June 21, 2026 17:34
Shader Function Reflection API Examples
// Example 2 — Customizing the node with XML hints (Unity 6.5+)
//
// The same three ingredients as Example 1, plus reflection hints that change
// how the node looks and behaves in Shader Graph:
//
// funchints -> customize the node as a whole (name, search category...)
// paramhints -> customize an individual port (display name, color picker,
// slider range, default value...)
//
// Hint validation is strict and type-aware:
@adammyhre
adammyhre / PerceptionAgent.cs
Last active June 28, 2026 05:33
Target Tracks Perception System
// Adapted from Game AI Pro - Crytek’s Target Tracks Perception System
using System.Collections.Generic;
using UnityEngine;
namespace Perception {
public class PerceptionAgent : MonoBehaviour {
#region Fields
[Header("Sight")]
[SerializeField] float viewRange = 15f;
@adammyhre
adammyhre / ParticleController.cs
Created May 3, 2026 10:40
GPU Particles in Unity 6 using Compute Shaders and Render Graph
using UnityEngine;
public class ParticleController : MonoBehaviour {
[SerializeField] ComputeShader compute;
[SerializeField] Mesh mesh;
[SerializeField] Material material;
[SerializeField] int particleCount = 10000;
[SerializeField] float areaSize = 10f;
[SerializeField] float spawnDistanceFromCamera = 8f;