Coder Social home page Coder Social logo

sakuwz / unity-powerprefs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cosmicengineer/unity-powerprefs

0.0 1.0 0.0 181 KB

Read and write values of various types to Unity PlayerPrefs with way more options than before!

License: Apache License 2.0

C# 100.00%

unity-powerprefs's Introduction

PowerPrefs

Version Build Status License

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.

 

FeaturesInstallationUsage


Key Benefits

▶︎ 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.

Unity Support

It is developed and tested on Unity 2018.1.

Installation

You can download the latest version of PowerPrefs by using this link.

Once you have the unitypackage file, you can import it into your Unity project. If your project is already open then you can simply double-click the downloaded package. Alternatively, go to Assets -> Import Package -> Custom Package within the Unity editor.

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

If you find something that you don't think is working correctly, you have a feature you would like to see in PowerPrefs or just because you want to ask for some help, please open an issue.

If you would like to contribute some changes to PowerPrefs, I would greatly appreciate a PR. If you would like to make a major change, please create an issue first to discuss it.

Author

Andrew Lord @andrewlord1990

unity-powerprefs's People

Contributors

lordcodes avatar

Watchers

James Cloos avatar

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.