Git Product home page Git Product logo

playerprefspro's Introduction

Unity PlayerPrefsPro

Unity PlayerPrefsPro uses Unity's default PlayerPrefs to save complex data types and classes (E.g. Booleans, Colors, Vectors, Lists, ...).

Syntax

The syntax is actually the same as PlayerPrefs.

You may need to call namespace as follow to call PlayerPrefsPro.

using HarioGames.PlayerPrefsPro; 

Some Examples

An example script is provided in the package and here are some examples of saving and loading datas with PlayerPrefsPro.

✷ Booleans :

bool testBoolean = true;
bool resultBoolean;

//Save
PlayerPrefsPro.Save("Test_Bool", testBoolean); //"Test_Bool" is the key to store data because PlayerPrefs needs a key to store data.

//Load
resultBoolean = PlayerPrefsPro.Load("Test_Bool", false); //With default value
resultBoolean = PlayerPrefsPro.Load<bool>("Test_Bool"); //Without providing default value

✷ Colors :

Color testColor = Color.white;
Color resultColor;

//Color 32bit
Color32 testColor32 = Color.red;
Color32 resultColor32;

//Save
PlayerPrefsPro.Save("Test_Color", testColor); //"Test_Color" is the key to store data because PlayerPrefs needs a key to store data.
PlayerPrefsPro.Save("Test_Color32", testColor32); //"Test_Color32" is the key to store data because PlayerPrefs needs a key to store data.

//The keys to store data need to be different for each data.

//Load
resultColor = PlayerPrefsPro.Load("Test_Color", Color.black); //With default value
resultColor = PlayerPrefsPro.Load<Color>("Test_Color"); //Without providing default value
resultColor32 = PlayerPrefsPro.Load("Test_Color32", Color.black); //With default value
resultColor32 = PlayerPrefsPro.Load<Color32>("Test_Color32"); //Without providing default value

✷ Vector3 and Quaternion :

Vector3 testVector3 = Vector3.one;
Vector3 resultVector3;

Quaternion testQuaternion = Quaternion.identity;
Quaternion resultQuaternion;

//Save
PlayerPrefsPro.Save("Test_Vector3", testVector3); //"Test_Vector3" is the key to store data because PlayerPrefs needs a key to store data.
PlayerPrefsPro.Save("Test_Quaternion", testQuaternion); //"Test_Quaternion" is the key to store data because PlayerPrefs needs a key to store data.

//Load
resultVector3 = PlayerPrefsPro.Load("Test_Vector3", Vector3.zero); //With default value
resultVector3 = PlayerPrefsPro.Load<Vector3>("Test_Vector3"); //Without providing default value
resultQuaternion = PlayerPrefsPro.Load("Test_Quaternion", Quaternion.identity); //With default value
resultQuaternion = PlayerPrefsPro.Load<Quaternion>("Test_Quaternion"); //Without providing default value

✷ List :

List<int> testList = new List<int>() { 1, 2, 3};
List<int> resultList;

//Save
PlayerPrefsPro.Save("Test_List", testList); //"Test_List" is the key to store data because PlayerPrefs needs a key to store data.

//Load
resultList = PlayerPrefsPro.Load("Test_List", new List<int>()); //With default value
resultList = PlayerPrefsPro.Load<List<int>>("Test_List"); //Without providing default value

✷ Objects :

//Class
[System.Serializable]
public class MyClass
{
   public int testInt = 20;
   public string testString = "Hi";

   //Parameterless Constructor
   public MyClass()
   {

   }

   public MyClass(int testInt, string testString)
   {
       this.testInt = testInt;
       this.testString = testString;
   }
}

public MyClass testClass = new MyClass(123, "Leo");
public MyClass resultClass;

//Save
PlayerPrefsPro.Save("Test_Class", testClass); //"Test_Class" is the key to store data because PlayerPrefs need a key to store data.

//Load
resultClass = PlayerPrefsPro.Load("Test_Class", new MyClass()); //With default value
resultClass = PlayerPrefsPro.Load<MyClass>("Test_Class"); //Without providing default value

Contacts :

You can contact me via [email protected].

Social Medias :

Wai Yan Zaw Win | Facebook Wai Yan Zaw Win | Instagram Wai Yan Zaw Win | LinkedIn


playerprefspro's People

Contributors

wai-yan-zaw-win 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.