Last active
January 22, 2019 07:08
-
-
Save joshcamas/77da838fcda2538dbe3c9d130ba9e97f to your computer and use it in GitHub Desktop.
unity3d base class with a few helpers.
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
//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