Skip to content

Instantly share code, notes, and snippets.

@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;
@adammyhre
adammyhre / DataBindingHelper.cs
Created January 18, 2026 13:52
Helper to Abstract Runtime Data Binding Methods
using UnityEngine;
using UnityEngine.UIElements;
using Unity.Properties;
public static class DataBindingHelper {
static string GetDefaultTargetProperty<T>() where T : VisualElement {
return typeof(T) == typeof(Label) ? "text" : "value";
}
/// <summary>
@adammyhre
adammyhre / MainToolbarButtons.cs
Created December 28, 2025 13:08
Unity 6.3 Custom Main Toolbar
using UnityEditor;
using UnityEditor.Toolbars;
using UnityEngine;
using UnityEngine.UIElements;
public class MainToolbarButtons {
[MainToolbarElement("Project/Open Project Settings", defaultDockPosition = MainToolbarDockPosition.Middle)]
public static MainToolbarElement ProjectSettingsButton() {
var icon = EditorGUIUtility.IconContent("SettingsIcon").image as Texture2D;
var content = new MainToolbarContent(icon);
@adammyhre
adammyhre / content.js
Created December 24, 2025 11:45
Udemy Progress Tooltip 2026 (Chrome Extension)
(async function () {
// ================= utilities =================
function secondsToHMS(seconds) {
seconds = Math.floor(seconds);
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = seconds % 60;
return `${h}h ${m}m ${s}s`;