This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ShrinkTutorial
|
||||
{
|
||||
public sealed class PlayerPrefsShrinkTutorialStorage : IShrinkTutorialStorage
|
||||
{
|
||||
private readonly string _storageKey;
|
||||
|
||||
public PlayerPrefsShrinkTutorialStorage(string storageKey)
|
||||
{
|
||||
_storageKey = string.IsNullOrWhiteSpace(storageKey)
|
||||
? "ShrinkTutorial.Progress"
|
||||
: storageKey;
|
||||
}
|
||||
|
||||
public ShrinkTutorialProgress Load()
|
||||
{
|
||||
if (!PlayerPrefs.HasKey(_storageKey))
|
||||
return new ShrinkTutorialProgress();
|
||||
|
||||
var json = PlayerPrefs.GetString(_storageKey, string.Empty);
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
return new ShrinkTutorialProgress();
|
||||
|
||||
return JsonUtility.FromJson<ShrinkTutorialProgress>(json) ?? new ShrinkTutorialProgress();
|
||||
}
|
||||
|
||||
public void Save(ShrinkTutorialProgress progress)
|
||||
{
|
||||
var json = JsonUtility.ToJson(progress ?? new ShrinkTutorialProgress());
|
||||
PlayerPrefs.SetString(_storageKey, json);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
PlayerPrefs.DeleteKey(_storageKey);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user