Table of Contents

Class PlayerPrefs

Namespace
MonoEight.Core
Assembly
MonoEight.Template.dll

Provides a static interface for storing and retrieving simple player data to a local JSON file.

public static class PlayerPrefs
Inheritance
PlayerPrefs
Inherited Members

Remarks

Supported Types: int, double, bool, string.

Methods

DeleteAll()

Removes all keys and values from the preferences, then saves to disk.

public static void DeleteAll()

DeleteKey(string)

Removes the given key and its value from the preferences, then saves to disk.

public static void DeleteKey(string key)

Parameters

key string

The key to remove.

Get<T>(string, T?)

Retrieves the value associated with the given key.

public static T? Get<T>(string key, T? defaultValue = default)

Parameters

key string

The unique key to identify the preference.

defaultValue T

The value to return if the key does not exist.

Returns

T

The stored value, or defaultValue if not found.

Type Parameters

T

The type of the value.

HasKey(string)

Checks if the given key exists in the preferences.

public static bool HasKey(string key)

Parameters

key string

The key to check.

Returns

bool

true if the key exists, otherwise, false.

Initialize()

Initializes the storage directory and loads existing preferences from disk.

public static void Initialize()

Remarks

File Locations:

  • Windows: %AppData%\MonoEight-Game\playerprefs.json
  • Unix/Mac: ~/.local/share/MonoEight-Game/playerprefs.json

Set<T>(string, T)

Sets the value for the given key and writes the changes to disk immediately.

public static void Set<T>(string key, T value)

Parameters

key string

The unique key.

value T

The value to store.

Type Parameters

T

The type of the value.