-
Notifications
You must be signed in to change notification settings - Fork 1
/
Progress.cs
67 lines (58 loc) · 1.41 KB
/
Progress.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
using System.Runtime.InteropServices;
using TMPro;
using UnityEngine;
[System.Serializable]
public class PlayerInfo
{
public int connectedAccount;
public int bearS;
public int bestScore;
public int spawnBackgroubd;
public int gunNumber;
public int gameOver;
}
public class Progress : MonoBehaviour
{
public PlayerInfo PlayerInfo;
[DllImport("__Internal")]
private static extern void SaveExtern(string date);
[DllImport("__Internal")]
private static extern void LoadExtern();
// [SerializeField] TextMeshProUGUI _playerInfoText;
public static Progress Instance;
private void Awake()
{
if (Instance == null)
{
transform.parent = null;
DontDestroyOnLoad(gameObject);
Instance = this;
#if UNITY_WEBGL
LoadExtern();
#endif
}
else
{
Destroy(gameObject);
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Backspace))
{
PlayerInfo = new PlayerInfo();
Save();
}
}
public void Save()
{
string jsonString = JsonUtility.ToJson(PlayerInfo);
#if UNITY_WEBGL
SaveExtern(jsonString);
#endif
}
public void SetPlayerInfo(string value)
{
PlayerInfo = JsonUtility.FromJson<PlayerInfo>(value);
}
}