Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.ServiceProcess;
- public delegate void OnSleepEnterCallback();
- public class SuspendEvent1 : MonoBehaviour {
- public UnityEngine.UI.Text textField;
- public bool runInBackActivated = true;
- private void Start()
- {
- ServiceSleep service = new ServiceSleep(OnSleepEnter);
- SwitchRIB(runInBackActivated);
- }
- void OnApplicationPause(bool pauseStatus)
- {
- textField.text = "Application pause!";
- Debug.LogError("Application pause");
- }
- void OnApplicationFocus(bool focus)
- {
- Debug.LogError("Application" + (focus ? "focus" : "unfocus"));
- }
- public void OnSleepEnter()
- {
- Debug.LogError("SLEEEEEEP!");
- }
- void Update () {
- if(Input.touchCount == 2 &&Input.touches[1].phase == TouchPhase.Began)
- {
- runInBackActivated = !runInBackActivated;
- SwitchRIB(runInBackActivated);
- textField.text = "Run in background value : " + runInBackActivated;
- }
- }
- void SwitchRIB(bool state)
- {
- Application.runInBackground = state;
- }
- }
- public class ServiceSleep : ServiceBase
- {
- public OnSleepEnterCallback enterCallback;
- public ServiceSleep(OnSleepEnterCallback paramCallback)
- {
- enterCallback = paramCallback;
- }
- protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
- {
- Debug.LogError(powerStatus.ToString());
- switch (powerStatus)
- {
- case PowerBroadcastStatus.QuerySuspend:
- case PowerBroadcastStatus.Suspend:
- enterCallback.Invoke();
- break;
- case PowerBroadcastStatus.ResumeSuspend:
- case PowerBroadcastStatus.QuerySuspendFailed:
- case PowerBroadcastStatus.ResumeAutomatic:
- case PowerBroadcastStatus.ResumeCritical:
- break;
- default:
- break;
- }
- return base.OnPowerEvent(powerStatus);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement