Skip to content

Instantly share code, notes, and snippets.

View nicolasmaclean's full-sized avatar

Nick Maclean nicolasmaclean

View GitHub Profile
@nicolasmaclean
nicolasmaclean / SystemBehaviour.cs
Last active August 4, 2023 00:39
System for dependency injection in Unity. Everything revolves arround the [Dependency] attribute. The SystemBehaviour class can be derived from or the CollectDependencies method can be called directly to perform injection.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
[AttributeUsage(validOn: AttributeTargets.Field)]
public class DependencyAttribute : Attribute
{
public enum ELocation
@nicolasmaclean
nicolasmaclean / Pool.cs
Created November 16, 2022 23:00
Prefab and Type based Object Pooling for Unity
// some back-end inspired by Microsoft's object pooling tutorial:
// https://learn.microsoft.com/en-us/dotnet/standard/collections/thread-safe/how-to-create-an-object-pool
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
[CreateAssetMenu(menuName="Object Pool")]
@nicolasmaclean
nicolasmaclean / EmptyFolderProtection.cs
Last active November 15, 2022 23:36
Automatically create/delete ".emptydir" files in empty folders to allow version control to include empty folders.
#if UNITY_EDITOR
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public static class EmptyFolderProtection
{
@nicolasmaclean
nicolasmaclean / DynamicSingletonSO.cs
Last active February 6, 2023 17:58
Singleton Scriptable Object with out-of-the-box loading/saving
// from https://gist.github.com/fguillen/a929a1d003a20bc727d8efe228b5dda4
// which is from https://www.youtube.com/watch?v=6kWUGEQiMUI&ab_channel=whateep
// ReSharper disable StaticMemberInGenericType
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;