Giter VIP home page Giter VIP logo

unityplayerprefsextra's Introduction

Unity PlayerPrefsExtra

Video thumbnail

Unity PlayerPrefsExtra gives you the ability to save more complexe data types such as : Vectors, Bool, Colors, Lists, ... and it uses the Unity's PlayerPrefs behind the scene.

⁉ How to use :

Use the same syntaxe as PlayerPrefs.

■ Booleans :

//Load
bool b = PlayerPrefsExtra.GetBool("mybool", false);

//Update (flip value)
b = !b;

//Save
PlayerPrefsExtra.SetBool("mybool", b);

■ Vectors ( Vector2, Vector3, and Vector4 ):

//Load
Vector2 v = PlayerPrefsExtra.GetVector2("myV2", Vector2.zero);

//Update
v+=Vector2.one;

//Save
PlayerPrefsExtra.SetVector2("myV2", v);

■ Colors :

// Get color
Color c = PlayerPrefsExtra.GetColor("Col");

// Set color
PlayerPrefsExtra.SetColor("Col", Color.red);

■ Quaternions :

// Get Quaternion
Quaternion qua = PlayerPrefsExtra.GetQuaternion("q");

//Set Quaternion
PlayerPrefsExtra.SetQuaternion("q", qua);

■ Lists :

// Get List
List<float> list = PlayerPrefsExtra.GetList<float>("myList", new List<float>());

// Add data to List
list.Add(Random.Range(100,900);

// Save List
PlayerPrefsExtra.SetList("myList", list);

■ Objects :

//Class
[System.Serializable]
public class Shape{
	public int totalPoints = 3;
	public float strokeWidth = 0f;
	public List<Vector3> points = new List<Vector3>();
}
// Get object
Shape s = PlayerPrefsExtra.GetObject<Shape>("myShape", new Shape());

// Update object data
s.strokeWidth++;
s.points.Add(Vector3.one*Random.Range(0f,3f));

// Save object
PlayerPrefsExtra.SetObject("myShape", s);



❤️ Donate

Paypal

BuyMeACoffee

Patreon

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.