/
ApplicationStateHandler.cs
114 lines (98 loc) · 3.02 KB
/
ApplicationStateHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//public class ApplicationStateHandler : MonoBehaviour
//{
// /*
// private List<Action> _onPauseHandlers;
// private List<Action> _onResumeHandlers;
// private List<Action> _onQuitHandlers;
// private bool isResumeCalled = false;
// private bool isPauseCalled = false;
// public ApplicationStateHandler()
// {
// _onPauseHandlers = new List<Action>();
// _onQuitHandlers = new List<Action>();
// _onResumeHandlers = new List<Action>();
// }
// private void Awake()
// {
// GlobalRefs.StateHandler = this;
// }
// public void RegisterPauseHandler(Action handler)
// {
// RegisterHandler(ApplicationHandlerType.Pause, handler);
// }
// public void RegisterResumeHandler(Action handler)
// {
// RegisterHandler(ApplicationHandlerType.Resume, handler);
// }
// public void RegisterQuitHandler(Action handler)
// {
// RegisterHandler(ApplicationHandlerType.Quit, handler);
// }
// public void RegisterHandler(ApplicationHandlerType type, Action handler)
// {
// switch (type)
// {
// case ApplicationHandlerType.Pause:
// _onPauseHandlers.Add(handler); return;
// case ApplicationHandlerType.Resume:
// _onResumeHandlers.Add(handler); return;
// case ApplicationHandlerType.Quit:
// _onQuitHandlers.Add(handler); return;
// default:
// break;
// }
// }
// private void OnApplicationPause(bool pause)
// {
// if (pause)
// {
// if (!isPauseCalled) {
// _onPauseHandlers.ForEach(handler => handler());
// isPauseCalled = true;
// isResumeCalled = false;
// PlayerPrefs.Save();
// }
// }
// else
// {
// if (!isResumeCalled) {
// _onResumeHandlers.ForEach(handler => handler());
// isResumeCalled = true;
// isPauseCalled = false;
// }
// }
// //StreamingSerialization.Save("pdata.json", GlobalRefs.PlayerData);
// }
// private void OnApplicationFocus(bool focus ) {
// if(focus) {
// if(!isResumeCalled) {
// _onResumeHandlers.ForEach(handler => handler());
// isResumeCalled = true;
// isPauseCalled = false;
// PlayerPrefs.Save();
// }
// } else {
// if(!isPauseCalled) {
// _onPauseHandlers.ForEach(handler => handler());
// isPauseCalled = true;
// isResumeCalled = false;
// }
// }
// }
// private void OnApplicationQuit()
// {
// _onQuitHandlers.ForEach(handler => handler());
// PlayerPrefs.Save();
// }*/
//}
//public enum ApplicationHandlerType
//{
// Pause,
// Resume,
// Quit
//}