Skip to content

Instantly share code, notes, and snippets.

@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`;
@adammyhre
adammyhre / CrowdInstance.shader
Created December 21, 2025 12:25
Compute Shader Example
Shader "Crowd/InstancedAgent" {
SubShader {
Tags { "RenderPipeline"="UniversalRenderPipeline" "RenderType"="Opaque" }
Pass {
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
# Unity text-based assets that are safe for Smart Merge / YAMLMerge
*.unity merge=unityyamlmerge
*.prefab merge=unityyamlmerge
*.mat merge=unityyamlmerge
*.physicMaterial merge=unityyamlmerge
*.physicsMaterial2D merge=unityyamlmerge
*.controller merge=unityyamlmerge
*.anim merge=unityyamlmerge
*.overrideController merge=unityyamlmerge
*.mask merge=unityyamlmerge
@adammyhre
adammyhre / Processor.cs
Created November 23, 2025 10:36
Generic Processing Chains
using System;
using UnityEngine;
public interface IProcessor<in TIn, out TOut> {
TOut Process(TIn input);
}
public delegate TOut ProcessorDelegate<in TIn, out TOut>(TIn input);
public class ThresholdFilter : IProcessor<float, bool> {
@adammyhre
adammyhre / CharacterStateMachine.cs
Last active November 17, 2025 06:34
Curiously Recurring Template Pattern (CRTP) in C#
using System.Collections.Generic;
using UnityEngine;
public class MoveState : CharacterState<MoveState> {
protected override void OnEnter() {
Debug.Log("#State# Entered Move");
}
protected override void OnExit() {
Debug.Log("#State# Exited Move");
@adammyhre
adammyhre / AllocCounter.cs
Created October 19, 2025 12:34
Allocation Analyzer
using System;
using UnityEngine.Profiling;
// See UnityEngine.TestTools.Constraints.AllocatingGCMemoryConstraint
// and https://maingauche.games/devlog/20230504-counting-allocations-in-unity/
public class AllocCounter {
UnityEngine.Profiling.Recorder rec;
public AllocCounter() {
rec = Recorder.Get("GC.Alloc");
@adammyhre
adammyhre / BulletHoleSpawner.cs
Created October 5, 2025 12:54
Decal Pooling in Unity
using System.Collections;
using UnityEngine;
using UnityEngine.Pool;
using UnityEngine.Rendering.Universal;
public class BulletHoleSpawner : MonoBehaviour {
#region Fields
IObjectPool<DecalProjector> decalPool;
@adammyhre
adammyhre / AOETargeting.cs
Last active October 8, 2025 08:24
Ability Targeting System
using System;
using System.Linq;
using Unity.Cinemachine;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityUtils;
[Serializable]
public class AOETargeting : TargetingStrategy {
public GameObject aoePrefab;
@adammyhre
adammyhre / DamageOverTimeEffect.cs
Created September 21, 2025 11:43
Effects Over Time Example
using System;
using System.Collections.Generic;
using ImprovedTimers; // https://github.com/adammyhre/Unity-Improved-Timers
using UnityEngine;
[Serializable]
public class Ability {
public AudioClip castSfx;
public GameObject castVfx;
public GameObject runningVfx;