Hello, I am Sun Guangdong. Reprint Please specify source: http://blog.csdn.net/u010019717
More full content Please see my game bull's address: http://www.unitymanual.com/space-uid-18602.html??
Ini files
This library can handle INI files. Note that the file can be any extension (such as. txt) as long as the contents of the file are in the correct format.
[player]name=arnoldavatar=2; This section stored hi-scores[hi-score]top1=32900top2=12000top3=4700
So how do you use this library?
1. Add "INIParser.cs" to Unity.
2. Declare a Iniparser object and use it.
Iniparser ini = new Iniparser (); Ini. Open ("C:/test.ini"); Ini. WriteValue ("Player", "Name", "Arnold"); Ini. Close ();
When multiple INI files
Please note that for each Iniparser instance, you can only have one open INI file at any one time, you may open the next INI file, but you must use Close () before.
Iniparser ini = new Iniparser (); Ini. Open ("C:/test.ini"); Ini. WriteValue ("Player", "Name", "Arnold"); Ini. WriteValue ("Hi-score", "TOP3", "n"); ini. Close (); Ini. Open ("C:/test2.ini"); Ini. WriteValue ("Position", "X", 2); Ini. WriteValue ("Position", "Y", 3); Ini. Close ();
Methods method
Open (String path)
Open Ini_file about reading and writing. If this file does not exist, it will be created. Once you have finished reading/writing remember to call Function Close (). To save all changes to this INI file.
Open (Textasset Asset)
Open a textasset as Ini_file. If you make any changes, the copy will be saved under the path of the persistent data path persistence. This function will always be looking at the persistent data path persistent paths, if there are any modifications to the Textasset copy, actually look at the game in the text resource bundle before you first see the changes in the persistent data path persistence.
Openfromstring (String str)
Creates an INI file from a string and opens it for read/write. A properly formatted string as an INI file (that is, the sections section, keys, and values) will not create the INI file correctly. Note that this INI file is temporary and only exists in memory. But you can use ToString () to return the string that can be saved to the server or to the disk's full INI file.
String ToString (String str)
Returns the full INI file string.
Close ()
This method should be called once you have finished reading or writing to any open INI file. INI file data is stored in memory until this method is called, and this data is written to disk.
String ReadValue (String section, string key, string default)
(Overloaded: bool, int, long, double, byte[], DateTime)
Reads the value from the Ini_file. If the value does not exist, (the default value) is returned.
WriteValue (string section, string key, String value)
(Overload:bool, int, long, double, byte[], DateTime)
Write a value to Ini_file
Sectiondelete (String section)
Deletes the section portion of the entire INI file, which also removes all key/value pairs associated with it.
BOOL Issectionexists (string section)
Check for the presence of section sections in the INI file. You do not need to check to prevent errors, because if you readvalue from a non-existent section stanza, ReadValue will only return the default value. However, sometimes it can be useful if the INI file has been saved for specific data.
Keydelete (string section, string key)
Delete the selected key (and the value associated with it) from the INI file.
BOOL Iskeyexists (string section, string key)
Check to see if there is a specified key present in the INI file. You do not need to check to prevent errors, because if you readvalue a non-existent section, ReadValue will only return the default value. However, sometimes it can be useful if the INI file has been saved for specific data.
Open (Textasset Asset)
Textasset is read-only, so any modifications are placed in the sandbox area (Persistentdatapath).
(reprinted) Parsing INI configuration file in unity----iniparser