Skip to content

Instantly share code, notes, and snippets.

@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;
@adammyhre
adammyhre / RadialMenuRoot.uxml
Created April 12, 2026 11:06
UI Toolkit radial menu that uses the Painter API and Unity 6.3 gradients, layout, rendering, and input selection.
<ui:UXML xmlns:ui="UnityEngine.UIElements" editor-extension-mode="False">
<Style src="RadialMenuStyles.uss" />
<ui:VisualElement name="radial-root" class="radial-root" picking-mode="Ignore">
<ui:VisualElement name="dimmer" class="radial-dimmer" picking-mode="Position" />
<ui:VisualElement name="wheel" class="radial-wheel" picking-mode="Ignore">
<ui:VisualElement name="items-host" class="radial-items-host" picking-mode="Position" />
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>
@adammyhre
adammyhre / SimpleBuildPart.cs
Created April 5, 2026 10:38
A simple Unity survival building system using modular pieces and socket-based snapping for clean placement.
using UnityEngine;
public enum SimpleBuildPieceType { Floor, Wall, Door }
public class SimpleBuildPart : MonoBehaviour {
[SerializeField] SimpleBuildPieceType pieceType = SimpleBuildPieceType.Floor; // identity for occupancy and placer logic
public SimpleBuildPieceType Type => pieceType;
public void SetPieceType(SimpleBuildPieceType value) => pieceType = value;
@adammyhre
adammyhre / SceneDirtyDiagnostics.cs
Created March 21, 2026 07:30
Unity Editor Tool: Finding What Marks Scenes Dirty
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
using Debug = UnityEngine.Debug;