Giter Club home page Giter Club logo

unity-powerprefs's Introduction

PowerPrefs

Latest release Twitter: @lordcodes Twitter: @lordcodes

A powerful and extensible preferences package for Unity, built on top of PlayerPrefs. PowerPrefs provides access to many more types than before, whilst also providing type-safe accessors to your key-value store.

 

FeaturesInstallUsage


Features

▶︎ Many extra types

Read and write values to PlayerPrefs with support for many extra types, such as bool, char, DateTime and long. There is also the possibility for adding many more in the future.

▶︎ Easy-to-use

You can be up and running without any configuration, simply start getting and setting values.

▶︎ Type-safe accessors

Values are retrieved and written through an accessor class which is typed. This means there are no types in the method names and you can even store the accessor class to read and write a key safely, without mentioning the type again. You can also store an accessor for a particular key to be used across your codebase without re-specifying the key.

▶︎ Migration

A method is provided to migrate a value from one key to another, which is useful if you wish to rename one of your keys safely.

▶︎ Open for extension

The classes which read and write values contain instance methods, allowing you to add extra features through extension methods if you wish. Even better, contribute them back to the library for others to use too!

▶︎ Fully documented

The public API is fully documented, including code documentation.

Install

PowerPrefs can be installed using the Unity Package Manager.

  1. Open the Package Manager within Unity.
  2. Select to add via Git URL.
  3. Enter the Git URL.
  4. The package can now be used within the Unity project.

The Git URL for the release branch: https://github.com/lordcodes/unity-powerprefs.git#upm

The Git URL for a specific version: https://github.com/lordcodes/unity-powerprefs.git#v{VERSION}

If a previous version of PowerPrefs had been imported using a unitypackage, make sure to remove it from the project before importing via Unity Package Manager.

Usage

First retrieve a typed accessor and then get or set a value:

PowerPrefs.ForBool().Get("aBoolean");
PowerPrefs.ForInt().Get("anInteger", -1);

PowerPrefs.ForLong().Set("aLong", 123456);
PowerPrefs.ForString().Set("aString", "Hello");

For the Get call you can provide a default value to return if the key doesn't exist. If this isn't provided then the default for that type will be used instead. E.g. for int it would be 0.

Advanced Usage

Re-use Accessor

You have the option of storing and re-using the accessor class.

var accessor = PowerPrefs.ForInt();
...
var myValue = accessor.Get("myKey");
accessor.Set("meyKey", 5);

An accessor for a particular key is also available: PowerPrefsKeyAccessor<T>.

var keyAccessor = PowerPrefs.ForString().KeyAccessor("someKey");
...
var myValue = keyAccessor.Get();
keyAccessor.Set("newValue");

Contributing or Help

If you notice any bugs or have a new feature to suggest, please check out the contributing guide. If you want to make changes, please make sure to discuss anything big before putting in the effort of creating the PR.

To reach out, please contact @lordcodes on Twitter.

unity-powerprefs's People

Contributors

lordcodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

trentsterling

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.