2021-03-08 16:13:19 +01:00
|
|
|
using System.CodeDom;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
2021-03-08 17:26:33 +01:00
|
|
|
[CreateAssetMenu(fileName = "PPValue.asset", menuName = "KernelPanic/PlayerPrefValue")]
|
2021-03-08 16:13:19 +01:00
|
|
|
public class PlayerPrefValue : ScriptableObject
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private string KeyName;
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
{
|
|
|
|
OnStringSet = new UnityEvent<string>();
|
|
|
|
OnIntSet = new UnityEvent<int>();
|
|
|
|
OnFloatSet = new UnityEvent<float>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public UnityEvent<string> OnStringSet { get; private set; }
|
|
|
|
public UnityEvent<int> OnIntSet { get; private set; }
|
|
|
|
public UnityEvent<float> OnFloatSet { get; private set; }
|
|
|
|
|
|
|
|
public bool HasValue
|
|
|
|
=> PlayerPrefs.HasKey( KeyName );
|
|
|
|
|
|
|
|
public int GetInt( int defaultValue = int.MaxValue )
|
|
|
|
=> PlayerPrefs.GetInt( KeyName, defaultValue );
|
|
|
|
|
|
|
|
public string GetString( string defaultValue = null )
|
|
|
|
=> PlayerPrefs.GetString( KeyName, defaultValue );
|
|
|
|
|
|
|
|
public float GetFloat( float defaultValue = float.NaN )
|
|
|
|
=> PlayerPrefs.GetFloat( KeyName, defaultValue );
|
|
|
|
|
|
|
|
public void SetInt( int value )
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetInt( KeyName, value );
|
|
|
|
OnIntSet.Invoke( value );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFloat( float value )
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetFloat( KeyName, value );
|
|
|
|
OnFloatSet.Invoke( value );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetString( string value )
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetString( KeyName, value );
|
|
|
|
OnStringSet.Invoke( value );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Save()
|
|
|
|
=> PlayerPrefs.Save();
|
|
|
|
}
|