Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/doyasu24/prefswrapper
- Owner: doyasu24
- License: mit
- Created: 2018-03-30T10:06:13.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T14:53:29.000Z (about 2 months ago)
- Last Synced: 2024-10-29T17:36:28.020Z (about 2 months ago)
- Topics: playerprefs, unity, unity-editor
- Language: C#
- Size: 102 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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