Created
September 1, 2021 09:38
-
-
Save rubit0/44a34becbfed8209817d34482485afee to your computer and use it in GitHub Desktop.
Useful component to perform basic actions on Unity lifecycle events directly from the inspector ✨
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 UnityEngine.Events; | |
public class LifecycleEventsTrigger : MonoBehaviour | |
{ | |
[SerializeField] | |
private UnityEvent onAwake; | |
[SerializeField] | |
private UnityEvent onStart; | |
[SerializeField] | |
private UnityEvent onEnable; | |
[SerializeField] | |
private UnityEvent onDisable; | |
[SerializeField] | |
private UnityEvent onDestroy; | |
[SerializeField] | |
private UnityEvent onBecameInvisible; | |
[SerializeField] | |
private UnityEvent onBecameVisible; | |
private void Awake() | |
{ | |
onAwake?.Invoke(); | |
} | |
private void Start() | |
{ | |
onStart?.Invoke(); | |
} | |
private void OnEnable() | |
{ | |
onEnable?.Invoke(); | |
} | |
private void OnDisable() | |
{ | |
onDisable?.Invoke(); | |
} | |
private void OnDestroy() | |
{ | |
onDestroy?.Invoke(); | |
} | |
private void OnBecameInvisible() | |
{ | |
onBecameInvisible?.Invoke(); | |
} | |
private void OnBecameVisible() | |
{ | |
onBecameVisible?.Invoke(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment