Skip to content

Instantly share code, notes, and snippets.

@adammyhre
adammyhre / HeatmapCompute.compute
Last active April 13, 2025 18:14
Compute Shader + Render Feature Heatmap
#pragma kernel CSMain
RWTexture2D<float> heatmapTexture;
float2 texSize;
StructuredBuffer<float2> enemyPositions;
int enemyCount;
[numthreads(8, 8, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
@adammyhre
adammyhre / gist:67d4b32876d753e5e27e88d65cb63f4e
Created March 30, 2025 06:55
ZLinq VisualElement Traverser
using UnityEngine.UIElements;
using ZLinq; // https://github.com/Cysharp/ZLinq
public struct VisualElementTraverser : ITraverser<VisualElementTraverser, VisualElement> {
readonly VisualElement current;
int nextChildIndex;
readonly int totalChildren;
public VisualElementTraverser(VisualElement origin) {
current = origin;
@adammyhre
adammyhre / SineWaveInstanced.cs
Created March 23, 2025 08:45
GPU Instancing Example Unity 6
using System.Collections.Generic;
using UnityEngine;
public class SineWaveInstanced : MonoBehaviour {
#region Fields
public GameObject sample;
public Mesh mesh;
public Material material;
@adammyhre
adammyhre / ExampleGenerators.csproj
Created March 9, 2025 13:11
Roslyn Fundamentals
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
@adammyhre
adammyhre / DamageNumberSpawner.cs
Last active April 12, 2025 03:50
World Space UI Toolkit
using PrimeTween;
using UnityEngine;
using UnityEngine.Pool;
using UnityUtils;
public class DamageNumberSpawner : MonoBehaviour {
[SerializeField] WorldSpaceUIDocument uiDocumentPrefab;
[SerializeField] float positionRandomness = 0.2f;
IObjectPool<WorldSpaceUIDocument> uiDocumentPool;
@adammyhre
adammyhre / GridManager.cs
Created February 9, 2025 12:23
Tactical Pathfinding for A*
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using TMPro;
public struct Node {
public Vector3 position;
public bool isWalkable;
public Node(Vector3 position, bool isWalkable = false) {
@adammyhre
adammyhre / SessionManager.cs
Last active March 22, 2025 09:14
QuickStart SessionManager for 2025 Multiplayer Services
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using Unity.Services.Authentication;
using Unity.Services.Core;
using Unity.Services.Multiplayer;
using UnityEngine;
using UnityUtils;
public class SessionManager : Singleton<SessionManager> {
@adammyhre
adammyhre / AnyValue.cs
Created January 19, 2025 08:11
Serialized Callback System
using System;
using UnityEngine;
public enum ValueType { Int, Float, Bool, String, Vector3 }
[Serializable]
public struct AnyValue {
public ValueType type;
// Storage for different types of values
@adammyhre
adammyhre / PackageManagerHelper.cs
Last active April 12, 2025 03:52
Faster Unity Asset Importer (for use with Setup Script)
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
public static class PackageManagerHelper {
const string ServicesNamespace = "UnityEditor.PackageManager.UI.Internal";
/// <summary>
/// Resolves a PackageManager service by its interface name.
@adammyhre
adammyhre / Closure.cs
Created December 22, 2024 08:44
Simple Closure Implementation for Unity C#
using System;
public struct Closure<TContext> {
Delegate del;
TContext context;
public Closure(Delegate del, TContext context = default) {
this.del = del;
this.context = context;
}