-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseValueSaver.cs
More file actions
33 lines (29 loc) · 911 Bytes
/
BaseValueSaver.cs
File metadata and controls
33 lines (29 loc) · 911 Bytes
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
using Demos.SOArchApproach.CodeBase.ScriptableObjectsFramework.Values;
using UnityEngine;
namespace Demos.SOArchApproach.CodeBase.ScriptableObjectsFramework
{
public abstract class BaseValueSaver<TYPE, HOLDER> : MonoBehaviour where HOLDER : BaseValue<TYPE>
{
public HOLDER Value;
public StringValue Key;
public bool LoadOnAwake;
public TYPE DefaultValue;
private void Awake()
{
if(LoadOnAwake)
{
if(PlayerPrefs.HasKey(Key.Value))
Value.Value = LoadValue();
else
Value.Value = DefaultValue;
}
}
public abstract TYPE LoadValue();
public abstract void SaveValue();
public void OnUpdateValue()
{
SaveValue();
PlayerPrefs.Save();
}
}
}