UseUpdateAPKDemo.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. namespace SC.Tools.UpdateAPKSystem {
  7. public class UseUpdateAPKDemo : MonoBehaviour
  8. {
  9. /// <summary>
  10. /// 开启app后等待多少时间开始检测
  11. /// </summary>
  12. [Header("开启检测的延迟")]
  13. [SerializeField]
  14. private float waittingTime = 0;
  15. Coroutine WaitCoroutine;
  16. /// <summary>
  17. /// 绑定的3D按键 可空
  18. /// </summary>
  19. [Header("绑定的3D按键 可空")]
  20. public SCButton Button3D;
  21. /// <summary>
  22. /// 绑定的2D UI按键 可空
  23. /// </summary>
  24. [Header("绑定的2D UI按键 可空")]
  25. public Button ButtonUI;
  26. static UseUpdateAPKDemo instant;
  27. void Awake() {
  28. if (instant) {
  29. DestroyImmediate(gameObject);
  30. return;
  31. }
  32. instant = this;
  33. DontDestroyOnLoad(gameObject);
  34. }
  35. void Start() {
  36. WaitCoroutine = StartCoroutine(Waitting(waittingTime));
  37. if (Button3D) {
  38. Button3D.onClick.AddListener(OnPointerClick);
  39. }
  40. if (ButtonUI) {
  41. ButtonUI.onClick.AddListener(OnPointerClick);
  42. }
  43. }
  44. void Disable() {
  45. if (Button3D) {
  46. Button3D.onClick.RemoveListener(OnPointerClick);
  47. }
  48. if (ButtonUI) {
  49. ButtonUI.onClick.RemoveListener(OnPointerClick);
  50. }
  51. if (WaitCoroutine != null) {
  52. StopCoroutine(Waitting(waittingTime));
  53. }
  54. }
  55. IEnumerator Waitting(float time = 0) {
  56. while (true) {
  57. if (time != 0) {
  58. yield return new WaitForSeconds(time);
  59. }
  60. yield return null;
  61. if (SvrManager.Instance && SvrManager.Instance.IsRunning) {
  62. UpdateAPKSystem.getInstant.RunSilent();
  63. yield break;
  64. }
  65. }
  66. }
  67. public void OnPointerClick() {
  68. UpdateAPKSystem.getInstant.Run();
  69. }
  70. }
  71. }