/*! \endcond */ /// <summary> /// This method will flush all World Variable values and write them to a text file for later retrieval. Normally not needed. If you find your variable values get lost, call this before changing Scenes. I've never seen it happen myself. /// </summary> public static void FlushAll() { #if UNITY_WEBPLAYER || UNITY_WP8 || UNITY_METRO || UNITY_WIIU // can't compile this class #else PlayerPrefs.Flush(); #endif }
/// <summary> /// Gets the existing world variable value. This should only be used in startup code. Otherwise grab the variable from GetWorldVariable /// </summary> /// <returns> /// The existing World Variable value in PlayerPrefs. /// </returns> /// <param name='variableName'>World Variable name.</param> /// <param name="startingValue">The value to use if not present.</param> public static float?GetExistingWorldVariableFloatValue(string variableName, float startingValue) { var tokenKey = InGameWorldVariable.GetTokenPrefsKey(variableName); // save this if we need it later. if (!VariableExistsInScene(variableName)) { return(null); } if (!PlayerPrefs.HasKey(tokenKey)) { // if this is the first time, set it! PlayerPrefs.SetFloat(tokenKey, startingValue); } return(PlayerPrefs.GetFloat(tokenKey)); }
void OnDisable() { PlayerPrefs.Flush(); }
void OnEnable() { PlayerPrefs.Flush(); }
public void Remove(string id) { PlayerPrefs.DeleteKey(id); }
public bool Exists(string id) { return(PlayerPrefs.HasKey(id)); }
public string Get(string id) { return(PlayerPrefs.GetString(id, string.Empty)); }
public void Set(string id, string val) { PlayerPrefs.SetString(id, val); }
public int GetInt(string id) { return(PlayerPrefs.GetInt(id, 0)); }
public void SetInt(string id, int val) { PlayerPrefs.SetInt(id, val); }
public void Save() { PlayerPrefs.Flush(); }