There's no built-in way to get a list of all existing PlayerPrefs in Unity (moreover you also need to each one's type).
There is a plugin that can do that in the editor, maybe you can use it and modify it to work in runtime as well: https://assetstore.unity.com/packages/tools/playersprefs-editor-and-utilities-26656
A second alternative would be to manually search the place where the prefs are saved (in windows its in the registery, for example). You can see the location the prefs are saved in each platform here: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
Last, and this would be my suggestion - you can use PlayerPrefs.DeleteAll()
to delete all player prefs. However, this will delete them and not set a default value like in your code, so you will have to change the code that accesses the player prefs and provide it with a default value.
public void Drop()
{
PlayerPrefs.DeleteAll(); // Remove all keys so we can get their default values
PlayerPrefs.Save();
SceneManager.LoadScene(0);
}
public int MyGetInt(string prefName) {
return PlayerPrefs.GetInt(prefName, 0);
}
public float MyGetFloat(string prefName) {
return PlayerPrefs.GetFloat(prefName, 0f);
}
private void Update() {
Debug.Log("CPU Value: " + MyGetFloat("CPU")); // When using this instead of directly PlayerPrefs.GetFloat, then it will return 0 if the value doesn't exist, including after Drop() was run
}
Note that this will delete ALL your keys in the game. If you only want to reset a certain list of keys, there is no avoiding making a list of it in a JSON file, array, or some other structure. The program can not guess which values you want to reset and which not.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…