PlayerPrefsCommands.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using UnityEngine;
  2. namespace IngameDebugConsole.Commands
  3. {
  4. public class PlayerPrefsCommands
  5. {
  6. [ConsoleMethod( "prefs.int", "Returns the value of an Integer PlayerPrefs field" ), UnityEngine.Scripting.Preserve]
  7. public static string PlayerPrefsGetInt( string key )
  8. {
  9. if( !PlayerPrefs.HasKey( key ) ) return "Key Not Found";
  10. return PlayerPrefs.GetInt( key ).ToString();
  11. }
  12. [ConsoleMethod( "prefs.int", "Sets the value of an Integer PlayerPrefs field" ), UnityEngine.Scripting.Preserve]
  13. public static void PlayerPrefsSetInt( string key, int value )
  14. {
  15. PlayerPrefs.SetInt( key, value );
  16. }
  17. [ConsoleMethod( "prefs.float", "Returns the value of a Float PlayerPrefs field" ), UnityEngine.Scripting.Preserve]
  18. public static string PlayerPrefsGetFloat( string key )
  19. {
  20. if( !PlayerPrefs.HasKey( key ) ) return "Key Not Found";
  21. return PlayerPrefs.GetFloat( key ).ToString();
  22. }
  23. [ConsoleMethod( "prefs.float", "Sets the value of a Float PlayerPrefs field" ), UnityEngine.Scripting.Preserve]
  24. public static void PlayerPrefsSetFloat( string key, float value )
  25. {
  26. PlayerPrefs.SetFloat( key, value );
  27. }
  28. [ConsoleMethod( "prefs.string", "Returns the value of a String PlayerPrefs field" ), UnityEngine.Scripting.Preserve]
  29. public static string PlayerPrefsGetString( string key )
  30. {
  31. if( !PlayerPrefs.HasKey( key ) ) return "Key Not Found";
  32. return PlayerPrefs.GetString( key );
  33. }
  34. [ConsoleMethod( "prefs.string", "Sets the value of a String PlayerPrefs field" ), UnityEngine.Scripting.Preserve]
  35. public static void PlayerPrefsSetString( string key, string value )
  36. {
  37. PlayerPrefs.SetString( key, value );
  38. }
  39. [ConsoleMethod( "prefs.delete", "Deletes a PlayerPrefs field" ), UnityEngine.Scripting.Preserve]
  40. public static void PlayerPrefsDelete( string key )
  41. {
  42. PlayerPrefs.DeleteKey( key );
  43. }
  44. [ConsoleMethod( "prefs.clear", "Deletes all PlayerPrefs fields" ), UnityEngine.Scripting.Preserve]
  45. public static void PlayerPrefsClear()
  46. {
  47. PlayerPrefs.DeleteAll();
  48. }
  49. }
  50. }