GlobalEventCenter.cs 897 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /* 全局事件中心-订阅发布 */
  5. public class GlobalEventCenter : MonoBehaviour
  6. {
  7. public System.Action onGameSceneLoad;
  8. public System.Action onGameSceneDestroy;
  9. public System.Action<bool> onSimulateMouseAwakeChanged; //Param0:激活/熄灭
  10. public System.Action<bool> onDeviceCalibrateViewAwakeChanged;
  11. private static GlobalEventCenter _ins;
  12. public static GlobalEventCenter ins {
  13. get {
  14. if (!_ins) {
  15. _ins = new GameObject("GlobalEventCenter").AddComponent<GlobalEventCenter>();
  16. DontDestroyOnLoad(_ins);
  17. }
  18. return _ins;
  19. }
  20. }
  21. void OnDestroy()
  22. {
  23. // 清除静态实例,确保不再持有对该实例的引用
  24. if (_ins == this)
  25. {
  26. _ins = null;
  27. }
  28. }
  29. }