Skip to content

Mapper for Unity game engine which helps to save and load entities to PlayerPrefs.

License

Notifications You must be signed in to change notification settings

nubick/entity-to-playerprefs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Entity to PlayerPrefs

Plugin for Unity game engine. It helps to store entities in PlayerPrefs.

Take the latest unitypackage from releases.

Usage

###[PlayerPrefsField] attribute

Instead of using 'Set' methods and string keys for saving

PlayerPrefs.SetFloat("SoundsVolumeKey", SoundsVolume);

and 'Get' methods and string keys for loading

SoundsVolume = PlayerPrefs.GetFloat("SoundsVolumeKey");

Mark field by [PlayerPrefsField] attribute:

[PlayerPrefsField] public float SoundsVolume;

When call 'PlayerPrefsMapper.Save' all fields which are marked by [PlayerPrefsField] attribute will be saved to PlayerPrefs.

PlayerPrefsMapper.Save(entity);

When call 'PlayerPrefsMapper.Load' all fields which are marked by [PlayerPrefsField] attribute will be loaded from PlayerPrefs.

PlayerPrefsMapper.Load(entity);

[Code Example]

###[PlayerPrefsEntityId] attribute Add [PlayerPrefsEntityId] attribute if you want to save several different instances of one class to PlayerPrefs. Field with [PlayerPrefsEntityId] attribute must have string type. Value of this field must be unique between all instances of this class.

Example: When we want to save state of several levels we can use following class:

public class Level : MonoBehaviour
{
	public int Number;
	[PlayerPrefsEntityId] public string Id { get { return Number.ToString(); } }
	[PlayerPrefsField] public bool IsCompleted;
	[PlayerPrefsField] public int Stars;
}

We can save level state when level is completed:

public void Complete(int stars)
{
	Stars = stars;
	IsCompleted = true;
	PlayerPrefsMapper.Save(this);
}

We can load all levels state on game start:

public Level[] Levels;
public void Awake()
{
	PlayerPrefsMapper.Load(Levels);
}

Editor

Plugin contains editor for game state management during development. It allows to edit any field or delete any field from PlayerPrefs. Editor groups records by tabs based on entity type. This allows quickly find required entity. You can use editor by open it from menu 'Your Game' -> 'Entity To PlayerPrefs' in the Unity.

My image

My image

Supported types.

Plugin extends PlayerPrefs types:

  • string
  • int
  • float

by following types:

  • bool
  • DateTime
  • Enumerators

About

Mapper for Unity game engine which helps to save and load entities to PlayerPrefs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages