Unity data persistence-PlayerPrefs

Concept: PlayerPrefs is a [class] provided by Unity to save and read [data local persistence].
Principle: save data locally in the form of key-value [key-value pair], and then write in the code , Read and update data
Disadvantages: It will be very weak to save and read a large amount of data.
Advantages: Store some simple data, game option settings, user login information, etc.

Save method: PlayerPrefs.SetInt("key", value);//SetFloat and SetString can also be
read. Method: PlayerPrefs.GetInt("key")//GetFloat and GetString can also
delete all data. Method: PlayerPrefs.DeletAll()
Delete single data: PlayerPrefs.DeleteKey("keyA")//Delete data with key "keyA"
Security check: PlayerPrefs.HasKey("keyB")//Return data with key "keyB", if it does not exist, return to default Value 0
PlayerPrefs.Save(): Not recommended. It is used to save data for recovery when the program is suddenly exited, but it will cause the program to be interrupted, so it is not recommended

Data address:
[Window] Under Windows platform, it is stored under HKEY_CURRENT_USER\Software [company name] [product name] key in the registry, where the company and product names are set in the project setting.
[Mac] Stored in the ~/Library/Preferences folder, named unity. [company name]. [product name]. plist, where the company and product names are set in the project setting.
[Android] Data storage (persistence) on the device. The data is stored in SharedPreferences.

Clear data:
Insert picture description here
Suggestions for use: Write a document and record the key you use to avoid getting the correct data due to typing errors.

Guess you like

Origin blog.csdn.net/euphorias/article/details/108400594