BackKeyCallBackSet.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using SC.InputSystem;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.SceneManagement;
  7. using System;
  8. public class BackKeyCallBackSet : PointerDelegate
  9. {
  10. static BackKeyCallBackSet instant;
  11. public EventTrigger eventTrigger;
  12. public bool IsBackQuit = true;
  13. public Action BackKeyCallBack;
  14. void Awake() {
  15. if(instant) {
  16. DestroyImmediate(gameObject);
  17. return;
  18. }
  19. instant = this;
  20. DontDestroyOnLoad(gameObject);
  21. }
  22. protected override void partAnyKeyDownDelegate(InputKeyCode keyCode, InputDevicePartBase part) {
  23. base.partAnyKeyDownDelegate(keyCode, part);
  24. if(keyCode != InputKeyCode.Back)
  25. return;
  26. if(BackKeyCallBack != null) {
  27. BackKeyCallBack();
  28. }
  29. }
  30. void Update() {
  31. if(BackKeyCallBack != null) {
  32. Input.backButtonLeavesApp = false;
  33. } else {
  34. Input.backButtonLeavesApp = true;
  35. }
  36. }
  37. }