56 lines
770 B
C#
56 lines
770 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace BitStrap
|
|
{
|
|
[Serializable]
|
|
public abstract class PlayerPrefProperty<T>
|
|
{
|
|
[SerializeField]
|
|
protected string key;
|
|
|
|
private T value;
|
|
|
|
private bool initialized;
|
|
|
|
public T Value
|
|
{
|
|
get
|
|
{
|
|
RetrieveValue();
|
|
return value;
|
|
}
|
|
set
|
|
{
|
|
SaveValue(value);
|
|
}
|
|
}
|
|
|
|
protected PlayerPrefProperty(string prefKey)
|
|
{
|
|
key = prefKey;
|
|
value = default(T);
|
|
initialized = false;
|
|
}
|
|
|
|
protected void RetrieveValue()
|
|
{
|
|
if (!initialized)
|
|
{
|
|
value = OnRetrieveValue();
|
|
initialized = true;
|
|
}
|
|
}
|
|
|
|
protected void SaveValue(T newValue)
|
|
{
|
|
value = newValue;
|
|
OnSaveValue(value);
|
|
}
|
|
|
|
protected abstract T OnRetrieveValue();
|
|
|
|
protected abstract void OnSaveValue(T value);
|
|
}
|
|
}
|