StartDestroyEventObject.cs 586 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. public class StartDestroyEventObject : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. if (this.m_EventOnStart != null)
  9. {
  10. this.m_EventOnStart.Invoke();
  11. }
  12. }
  13. private void OnDestroy()
  14. {
  15. if (this.m_IsQuittingApplication)
  16. {
  17. return;
  18. }
  19. if (this.m_EventOnDestroy != null)
  20. {
  21. this.m_EventOnDestroy.Invoke();
  22. }
  23. }
  24. private void OnApplicationQuit()
  25. {
  26. this.m_IsQuittingApplication = true;
  27. }
  28. public UnityEvent m_EventOnStart;
  29. public UnityEvent m_EventOnDestroy;
  30. private bool m_IsQuittingApplication;
  31. }