Files
plugin-library/Assets/00.StaryEvo/~Samples/Runtime/CounterApp/Script/IStorage.cs
2025-03-31 11:19:27 +08:00

47 lines
1.0 KiB
C#

using UnityEditor;
using UnityEngine;
namespace Stary.Evo.Example.Counter
{
public interface IStorage:IUtility
{
void SaveInt(string key, int value);
int LoadInt(string key, int defaultValue = 0);
}
public class PlayerPrefsStorage : IStorage
{
public void SaveInt(string key, int value)
{
Debug.Log("PlayerPrefsStorage执行");
PlayerPrefs.SetInt(key, value);
}
public int LoadInt(string key, int defaultValue = 0)
{
return PlayerPrefs.GetInt(key, defaultValue);
}
}
public class EditorPrefsStorage : IStorage
{
public void SaveInt(string key, int value)
{
#if UNITY_EDITOR
Debug.Log("EditorPrefsStorage执行");
EditorPrefs.SetInt(key, value);
#endif
}
public int LoadInt(string key, int defaultValue = 0)
{
#if UNITY_EDITOR
return EditorPrefs.GetInt(key, defaultValue);
#else
return 0;
#endif
}
}
}