Skip to content

Instantly share code, notes, and snippets.

@adammyhre
adammyhre / DStarLite.cs
Last active May 12, 2025 04:33
Implementation of D* Lite Algorithm for Unity
// D* Lite is an incremental heuristic search algorithm that finds the shortest path in a graph
// from a goal node to a start node. It is designed to be efficient in terms of memory and computation
// while updating the graph in real-time.
// Koenig and Likhachev - http://idm-lab.org/bib/abstracts/papers/aaai02b.pdf
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
@adammyhre
adammyhre / ImprovedTimers.cs
Last active July 22, 2024 05:53
Improved Timers for Unity
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.LowLevel;
using UnityEngine.PlayerLoop;
namespace ImprovedTimers {
public static class TimerManager {
static readonly List<Timer> timers = new();
@adammyhre
adammyhre / Mediator.cs
Created March 31, 2024 02:50
Unity Mediator
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public abstract class Mediator<T> : MonoBehaviour where T : Component, IVisitable {
readonly List<T> entities = new List<T>();
public void Register(T entity) {
if (!entities.Contains(entity)) {
@adammyhre
adammyhre / .gitconfig
Created March 17, 2024 03:05
.gitconfig
[user]
email = [email protected]
name = Your Name
[alias]
co = checkout
ct = commit
ci = commit
st = status -sb
br = branch
@adammyhre
adammyhre / SerializableType.cs
Last active February 28, 2025 14:16
SerializableType and Supporting classes
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
[Serializable]
public class SerializableType : ISerializationCallbackReceiver {
[SerializeField] string assemblyQualifiedName = string.Empty;
public Type Type { get; private set; }
@adammyhre
adammyhre / AbilitySystem.cs
Last active May 28, 2025 23:41
MVC Ability System
[CreateAssetMenu(fileName = "AbilityData", menuName = "ScriptableObjects/AbilityData", order = 1)]
public class AbilityData : ScriptableObject {
public AnimationClip animationClip;
public int animationHash;
public float duration;
public Sprite icon;
public string fullName;
void OnValidate() {
using System;
using System.Collections.Generic;
using System.Collections;
/// <summary>
/// Initializes a new instance of the ObservableList class that is empty
/// or contains elements copied from the specified list.
/// </summary>
/// <param name="initialList"> The list to copy elements from. </param>
public interface IObservableList<T> {
@adammyhre
adammyhre / Observable.cs
Last active April 12, 2025 04:30
Generic Observable with ValueChanged Action
using System;
using System.Collections.Generic;
[Serializable]
public class Observable<T> {
private T value;
public event Action<T> ValueChanged;
public T Value {
get => value;
@adammyhre
adammyhre / Preconditions.cs
Last active April 25, 2025 10:26
Unity Preconditions Class
using System;
public class Preconditions {
Preconditions() { }
public static T CheckNotNull<T>(T reference) {
return CheckNotNull(reference, null);
}
public static T CheckNotNull<T>(T reference, string message) {
@adammyhre
adammyhre / LoadSceneAttribute.cs
Created January 21, 2024 07:18
Unity Testing LoadSceneAttribute
public class LoadSceneAttribute : NUnitAttribute, IOuterUnityTestAction {
readonly string scene;
public LoadSceneAttribute(string scene) => this.scene = scene;
public IEnumerator BeforeTest(ITest test) {
Debug.Assert(scene.EndsWith(".unity"), "Scene must end with .unity");
yield return EditorSceneManager.LoadSceneInPlayMode(scene, new LoadSceneParameters(LoadSceneMode.Single));
}