"Unity3d" Unity3d Registry dynamic access game Archive--playerprefs class

Source: Internet
Author: User

"Unity3d" Unity3d Registry dynamic access game Archive--playerprefs class

1.unity3d provides a class--playerprefs that is used to persist and read locally. It works very simply by saving the data in a file in the form of a key-value pair, and then the program can take out the last saved value based on that name.

The 2.PlayerPrefs class supports saving and reading of data types in 3, floating-point, shaping, and string-type.
The functions corresponding to each are:
Setint (); Save integer data;
GetInt (); Read the shaping data;


SetFloat (); Save floating-point data;
Getflost (); Read floating-point data;


SetString (); Save string data;
GetString (); Read string-type data;

Save Data   playerprefs.setstring ("Name", mname);   Playerprefs.setint ("Age", mAge);   Playerprefs.setfloat ("Grade", Mgrade)//Read data   mname=playerprefs.getstring ("Name", "DefaultValue");   Mage=playerprefs.getint ("Age", 0);   Mgrade=playerprefs.getfloat ("Grade", 0F);

  

3. With the above two pieces of code, we can find two points:

1), data persistence in Unity3d is stored as a key value, and can be viewed as a dictionary.

2), Unity3d the value is read by the key name, the value does not exist, returns the default.

Currently, only three data types such as int, string, float are supported in Unity3d, so we can use these three types of data to store simple data. Currently, the classes used in Unity3d for data persistence are layerprefs, and the main class methods are:

static function DeleteAll (): Void Description: Remove all keys and values from the settings file and use them with caution. static function DeleteKey (key:string): Void Description: Removes the key and its corresponding value from the settings file. static function GetFloat (key:string, defaultvalue:float=of): Float Description: Returns the value corresponding to the key in the settings file if it exists. If it does not exist, it will return DefaultValue. static function GetInt (key:string, defaultvalue:int): Int Description: Returns the value corresponding to the key in the settings file, if present. If it does not exist, it will return DefaultValue. static function GetString (key:string, defaultvalue:string=**): String Description: Returns the value corresponding to the key in the settings file. If present. If it does not exist, it returns defaultvalue.static function Haskey (key:string): BOOL Description: Returns True if key is present in the settings file. Static function SetFloat ( Key:string, Value:float): Void Description: Sets the value determined by key. Static function Setint (key:string, Value:int): Void Description: Sets the value determined by key. Static F Unction SetString (key:string, value:string): Void Description: Sets the value determined by key.

  

4. The usage of these functions is basically consistent using set to save, using get for reading.

5. First we click on Unity3d in the file->build Settings Select our PC side, click on the following player Settings, we will appear on the right side of a "Inspector" panel, we will see in the beginning

We changed company name and product name to the name we like.

5. Then, we "Win + R" Enter the words in our input box, enter, here we open the registry, find "HKEY_CURRENT_USER", find "HKEY_CURRENT_USER\Software", we in software inside, We didn't find the ldscode we just defined, because we didn't store the data and only stored the data before it appeared!

"Unity3d" Unity3d Registry dynamic access game Archive--playerprefs class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.