-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGameValues.cs
More file actions
63 lines (55 loc) · 2.29 KB
/
GameValues.cs
File metadata and controls
63 lines (55 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PersistentData
{
public static class GameValues
{
/// <summary>
/// Save some data, identified with a key
/// </summary>
/// <typeparam name="T">The type of data to save</typeparam>
/// <param name="key">The key to identify the data with</param>
/// <param name="value">The data to save</param>
public static void Set<T>(string key, T value)
=> Backend.Set(key, value);
/// <summary>
/// Load some data, identified by key
/// </summary>
/// <typeparam name="T">The type to load the data as</typeparam>
/// <param name="key">The key the data is identified with</param>
/// <param name="defaultValue">If there was no data saved with the given key, save and return this</param>
/// <returns>The loaded value</returns>
public static T Get<T>(string key, T defaultValue = default)
=> Backend.Get(key, defaultValue);
/// <summary>
/// Check if saved data exists identified by this key
/// </summary>
public static bool KeyExists(string key)
=> Backend.KeyExists(key);
/// <summary>
/// Delete the data saved at this key, if there is any
/// </summary>
public static void DeleteKey(string key)
=> Backend.DeleteKey(key);
/// <summary>
/// Delete all the saved data in GameValues. Be very very careful with this!
/// </summary>
public static void DeleteAll()
=> Backend.DeleteAll();
/// <summary>
/// If <see langword="true"/>, data will be written do disk as soon as you change it. Otherwise, you must manually call <see cref="Save"/>.
/// This value is <see langword="true"/> unless you change it.
/// </summary>
public static bool AutoSave
{
get => Backend.AutoSave;
set => Backend.AutoSave = value;
}
/// <summary>
/// Writes all data changes to disk. You don't need to call this if <see cref="AutoSave"/> is <see langword="true"/> (which it is by default)
/// </summary>
public static void Save()
=> Backend.SaveAllDataToDisk();
}
}