Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// A generic pool manager for managing instances of Unity components.
/// This class allows for efficient reuse of components by maintaining a pool
/// of inactive instances that can be activated and returned as needed.
/// </summary>
/// <typeparam name="T">The type of Unity Component to pool. Must be a class derived from Component.</typeparam>
using System;
using UnityEngine;
#if UNITY_EDITOR
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
#endif
using System;
using System.Collections.Generic;
using UnityEngine;
public class Example : MonoBehaviour
{
[SerializeReference] public List<IExampleInterface> List = new();
}
#if UNITY_EDITOR
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
/// <summary>
/// A component for adding annotations to GameObjects in a scene
/// </summary>
[AddComponentMenu("Annotation")]
@shane-harper
shane-harper / AppManager.cs
Created November 17, 2023 16:30
An editor window in Unity for installing and uninstalling apps via ADB. I had started to use SideQuest out of convenience over adb command line, but thought it'd be nice to not leave Unity and void the adverts. I had originally planned to do the file explorer too, hence the View abstract class, but felt it wasn't worth the time investment for ho…
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;
@shane-harper
shane-harper / ScreenNeverSleepScope.cs
Last active June 4, 2019 09:37
An object for Unity mobile to keep the screen awake while doing something
using System;
using System.Collections;
using UnityEngine;
public struct ScreenNeverSleepScope : IDisposable
{
public ScreenNeverSleepScope(bool neverSleep)
{
if (neverSleep)
Screen.sleepTimeout = SleepTimeout.NeverSleep;
@shane-harper
shane-harper / CoroutineRunner.cs
Last active June 3, 2019 12:49
A class for handling starting and stopping of coroutines. Haven't tried it out yet, seemed like a neat idea
using System;
using System.Collections;
using UnityEngine;
public interface ICoroutineRunner : IDisposable
{
/// <summary>
/// The MonoBehaviour running the coroutine
/// </summary>
MonoBehaviour Runner { get; }
@shane-harper
shane-harper / SerializableDictionary.cs
Last active May 30, 2019 21:33
A serializable dictionary class for Unity that includes all the interfaces you find on the Dictionary class.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
/// <summary>
/// Example implementation of the dictionary class
/// Unfortunately, Unity doesn't support serializing generic classes
/// </summary>
@shane-harper
shane-harper / Pool.cs
Last active January 2, 2021 03:05
A generic C# pool class and example PrefabPool class for use with Unity3D prefabs
using System;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;
/// <summary>
/// A strongly typed pool of objects. When the pool is empty, new instances will be created when requested
/// </summary>
/// <typeparam name="T">The type of elements in the pool</typeparam>
public abstract class Pool<T>
@shane-harper
shane-harper / AssetBundler.cs
Last active March 9, 2019 13:00
Asset Bundler - A simple tool for handling asset bundles and testing in editor without building.
/// NOTE
/// After creating this script, I discovered Addressables. Which does a similar thing, but has many more features!
/// Check them out here: https://forum.unity.com/threads/addressables-are-here.536304/
//#define USE_BUNDLES
using System.Collections;
using UnityEngine;
#if UNITY_EDITOR && !USE_BUNDLES
using UnityEditor;
using System.IO;