Created
March 25, 2016 14:11
-
-
Save saint-angels/a8bd4e336cdff3a8604a to your computer and use it in GitHub Desktop.
You probably have a bunch of components that you want to keep a constantly updated list of too. Maybe all your enemies, or maybe all your bullets. (For Unity3D engine, from http://garry.tv/2015/06/14/unity-tips/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections.Generic; | |
public abstract class ListComponent<T> : MonoBehaviour where T : MonoBehaviour | |
{ | |
public static List<T> InstanceList = new List<T>(); | |
protected virtual void OnEnable() | |
{ | |
InstanceList.Add( this as T ); | |
} | |
protected virtual void OnDisable() | |
{ | |
InstanceList.Remove( this as T ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment