Skip to content

Instantly share code, notes, and snippets.

View blackbret94's full-sized avatar

Bret Black blackbret94

View GitHub Profile
@blackbret94
blackbret94 / AudioDirectory.cs
Created June 8, 2019 16:54
A useful model for creating ScriptableObject directories in Unity. This makes it easy to create an asset that stores AudioClips, Sprites, and other sets of data you want to be able to reference in many places throughout your project. Can be accessed like a Dictionary[string]. I use many variations of this in all my Unity projects.
using System.Collections.Generic;
using UnityEngine;
namespace Util.Directories
{
[CreateAssetMenu(fileName = "AudioDirectory", menuName = "Directory/Audio Directory", order = 1)]
public class AudioDirectory : ScriptableObject
{
public Wrapper[] Directory;
@blackbret94
blackbret94 / RefreshableStack.cs
Last active June 8, 2019 17:31
Simple data structure that makes it easy to track what members of the collection have been used most recently and which have not been used recently. This is useful for caching and inventory management in video game AI. This class is just a wrapper for a LinkedList with a few helper methods.
using System.Collections;
using System.Collections.Generic;
namespace Util.Collections
{
public class RefreshableStack<T> : IEnumerable<T>
{
private readonly LinkedList<T> _stack;
public IEnumerator<T> GetEnumerator() => _stack.GetEnumerator();
@blackbret94
blackbret94 / GamePanel.cs
Created September 25, 2019 14:47
This is a very simple extension of MonoBehaviour I use in every Unity project. Every panel class in my games extend this class, allowing for a common interface across all panels.
using UnityEngine;
namespace Bretblack.Games.GUI
{
public class GamePanel : MonoBehaviour
{
public virtual void SetActive(bool b)
{
gameObject.SetActive(b);
}