PlayerData
This commit is contained in:
1 parent
ca3994de2e
commit
0d3fb5071a
5 files changed
+79
-28
No files matched your search
@@ -12,12 +12,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
using SpaceRace.Shared;
|
||||
|
||||
public class PlayerData {
|
||||
public Guid Id;
|
||||
}
|
||||
|
||||
public class LapService {
|
||||
static string playerDataPath = Path.Combine(Application.persistentDataPath, "playerData.json");
|
||||
string _mapName;
|
||||
PlayerData _player;
|
||||
PbDTO _pb;
|
||||
@@ -38,7 +33,7 @@ public class LapService {
|
||||
|
||||
public LapService(string mapName) {
|
||||
_mapName = mapName;
|
||||
LoadPlayerData();
|
||||
_player = PlayerDataService.Load();
|
||||
}
|
||||
|
||||
public IEnumerator GetLapTimes() {
|
||||
@@ -107,22 +102,4 @@ public class LapService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoadPlayerData() {
|
||||
try {
|
||||
string json = File.ReadAllText(playerDataPath);
|
||||
_player = JsonConvert.DeserializeObject<PlayerData>(json);
|
||||
Debug.Log($"Loaded player data {json}");
|
||||
} catch {
|
||||
Debug.Log("No existing playerData.json");
|
||||
CreatePlayerData();
|
||||
}
|
||||
}
|
||||
|
||||
PlayerData CreatePlayerData() {
|
||||
_player = new PlayerData { Id = Guid.NewGuid() };
|
||||
Debug.Log(JsonConvert.SerializeObject(_player));
|
||||
File.WriteAllText(playerDataPath, JsonConvert.SerializeObject(_player));
|
||||
return _player;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user