Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/doyasu24/prefswrapper

Extensible PlayerPrefs wrapper
https://github.com/doyasu24/prefswrapper

playerprefs unity unity-editor

Last synced: 16 days ago
JSON representation

Extensible PlayerPrefs wrapper

Awesome Lists containing this project

README

        

# PrefsWrapper

Extensible PlayerPrefs wrapper.

AES encryption support

## Support types
- int
- bool
- byte
- sbyte
- char
- short
- ushort
- float
- string
- byte[]
- DateTime
- TimeSpan
- Enum
- Json (UnityEngine.JsonUtility)
- Vector2, 3, 4
- Quaternion
- Color
- ...
- struct in UnityEngine

# Install

You can add https://github.com/doyasu24/PrefsWrapper.git?path=Assets/Plugins/PrefsWrapper#1.0.1 to Package Manager.

see `Assets/Examples/Sample.unity` scene.

# Sample

```Sample.cs
using UnityEngine;

namespace PrefsWrapper.Examples
{
public class Sample : MonoBehaviour
{
// memory cache preference
private readonly IPreference _stringTestPref = PreferenceFactory.CreateStringPref("string-test-key");

// non-memory cache preference
private readonly IPreference _intTestPref = PreferenceFactory.CreateIntPref("int-test-key", enableMemCachePref: false);

// AES encoding preference
private readonly IPreference _cryptoPref = PreferenceFactory.CreateJsonCryptoPref(
key: "vector3-crypto-test",
password: "password",
salt: "salt1234567890"
);

private void Start()
{
// call PlayerPrefs.HasKey internally
Debug.Log($"HasValue: {_stringTestPref.HasValue}");

// call PlayerPrefs.GetString internally
Debug.Log($"GetValueOrDefault: {_stringTestPref.GetValueOrDefault("default value")}");

// call PlayerPrefs.DeleteKey internally
_stringTestPref.DeleteValue();

// call PlayerPrefs.SetString internally and set value to memory cache
_stringTestPref.Value = "test";

// get value from memory cache
Debug.Log($"Value: {_stringTestPref.Value}");

_cryptoPref.Value = Vector3.up;
Debug.Log($"CryptoPref Decode: {_cryptoPref.Value}");

// key and value are encrypted
// return false
Debug.Log($"PlayerPrefs.HasKey(\"vector3-crypto-test\"): {PlayerPrefs.HasKey("vector3-crypto-test")}");
}
}
}
```

# How to customize

see `PrefsWrapper.PreferenceFactory`

implement `IPrefsSerializer` and `IEncoder`

# License

MIT License