-
Notifications
You must be signed in to change notification settings - Fork 1
/
GlobalState.cs
52 lines (51 loc) · 1.25 KB
/
GlobalState.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
using UnityEngine;
using UnityEngine.Events;
class GlobalState
{
private const string SAVE_FILE_NAME = "save.json";
private static GlobalState _instance;
public static GlobalState instance {
get
{
if (_instance == null)
{
_instance = new GlobalState();
}
return _instance;
}
}
public GlobalState()
{
if (_instance != null)
{
Debug.LogError("GlobalState is a singleton!");
}
_instance = this;
}
public UnityEvent globalStateChangedEvent = new();
public UnityEvent<int> scoreChangedEvent = new();
private int _score = 0;
public int score
{
get { return _score; }
set
{
_score = value;
scoreChangedEvent.Invoke(_score);
globalStateChangedEvent.Invoke();
}
}
public UnityEvent<bool> gameOverChangedEvent = new();
private bool _gameOver = false;
public bool gameOver
{
get { return _gameOver; }
set
{
_gameOver = value;
globalStateChangedEvent.Invoke();
gameOverChangedEvent.Invoke(_gameOver);
globalStateChangedEvent.Invoke();
}
}
}