upm add package dev.upm-packages.cafu.keyvaluestore
Note: upm
command is provided by this repository.
KeyValueStoreInstaller.Install(Container, DataStoreType.PlayerPrefs);
Type | Description |
---|---|
PlayerPrefs | Using UnityEngine.PlayerPrefs |
Memory | Using IDictionary<> |
using CAFU.KeyValueStore.Application.Interface;
using System.Threading.Tasks;
public class Foo
{
[Inject] private IKeyValueStore KeyValueStore { get; }
public async Task Bar()
{
var value = "";
if (await KeyValueStore.Has("key"))
{
value = await KeyValueStore.Get<string>("key", "default value");
}
await KeyValueStore.Set<string>("key", "value is " + value);
}
}
It is strongly recommended that you use UniTask instead of Task
if you can.