PersistenHandler.cs 867 B

12345678910111213141516171819202122232425262728293031
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. //持久化的处理脚本,在app启动时就应开始常驻
  5. public class PersistenHandler : MonoBehaviour
  6. {
  7. public static PersistenHandler ins;
  8. public static void Init() {
  9. if (ins) return;
  10. GameObject obj = new GameObject("PersistenHandler");
  11. ins = obj.AddComponent<PersistenHandler>();
  12. DontDestroyOnLoad(obj);
  13. }
  14. long lastPressExitTime = 0;
  15. void Update()
  16. {
  17. if (Input.GetKeyDown(KeyCode.Escape)) {
  18. long lastLast = lastPressExitTime;
  19. lastPressExitTime = JC.CS.Utility.GetTimestamp();
  20. if (lastPressExitTime - lastLast < 10 * 1000) {
  21. Application.Quit();
  22. } else {
  23. PopupMgr.ins.ShowTip("再按一次退出APP");
  24. }
  25. }
  26. }
  27. }