Skip to content

Instantly share code, notes, and snippets.

@joshcamas
Last active January 22, 2019 07:08
Show Gist options
  • Save joshcamas/77da838fcda2538dbe3c9d130ba9e97f to your computer and use it in GitHub Desktop.
Save joshcamas/77da838fcda2538dbe3c9d130ba9e97f to your computer and use it in GitHub Desktop.
unity3d base class with a few helpers.
//Note that Awake, Update, and Start functions could be implemented the same way Destroy is... however,
//This of course would probably result in a lot of unneeded mono events. So... yeah.
public class BaseBehavior : MonoBehaviour
{
//Transform cacheing
private Transform _transform;
public Transform Transform
{
get
{
if( _transform == null)
{
_transform = transform;
}
return _transform;
}
}
//Overridable Functions
protected virtual void OnBehaviorDestroy(bool isQuitting)
{
}
//End of overridable functions, DO NOT OVERRIDE THESE
private bool isQuitting = false;
private void OnApplicationQuit()
{
isQuitting = true;
}
private void OnDestroy()
{
OnBehaviorDestroy(isQuitting);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment