Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.ServiceProcess;
  5.  
  6. public delegate void OnSleepEnterCallback();
  7.  
  8. public class SuspendEvent1 : MonoBehaviour {
  9.  
  10. public UnityEngine.UI.Text textField;
  11. public bool runInBackActivated = true;
  12.  
  13. private void Start()
  14. {
  15. ServiceSleep service = new ServiceSleep(OnSleepEnter);
  16. SwitchRIB(runInBackActivated);
  17. }
  18.  
  19. void OnApplicationPause(bool pauseStatus)
  20. {
  21. textField.text = "Application pause!";
  22. Debug.LogError("Application pause");
  23. }
  24.  
  25. void OnApplicationFocus(bool focus)
  26. {
  27. Debug.LogError("Application" + (focus ? "focus" : "unfocus"));
  28. }
  29.  
  30. public void OnSleepEnter()
  31. {
  32. Debug.LogError("SLEEEEEEP!");
  33. }
  34.  
  35. void Update () {
  36. if(Input.touchCount == 2 &&Input.touches[1].phase == TouchPhase.Began)
  37. {
  38. runInBackActivated = !runInBackActivated;
  39. SwitchRIB(runInBackActivated);
  40.  
  41. textField.text = "Run in background value : " + runInBackActivated;
  42. }
  43. }
  44. void SwitchRIB(bool state)
  45. {
  46. Application.runInBackground = state;
  47. }
  48. }
  49. public class ServiceSleep : ServiceBase
  50. {
  51.  
  52. public OnSleepEnterCallback enterCallback;
  53.  
  54. public ServiceSleep(OnSleepEnterCallback paramCallback)
  55. {
  56. enterCallback = paramCallback;
  57. }
  58.  
  59. protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
  60. {
  61. Debug.LogError(powerStatus.ToString());
  62. switch (powerStatus)
  63. {
  64. case PowerBroadcastStatus.QuerySuspend:
  65. case PowerBroadcastStatus.Suspend:
  66. enterCallback.Invoke();
  67. break;
  68. case PowerBroadcastStatus.ResumeSuspend:
  69. case PowerBroadcastStatus.QuerySuspendFailed:
  70. case PowerBroadcastStatus.ResumeAutomatic:
  71. case PowerBroadcastStatus.ResumeCritical:
  72.  
  73. break;
  74. default:
  75. break;
  76. }
  77. return base.OnPowerEvent(powerStatus);
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement