UniDDataBase-introduction and main usage summary, uniddatabase-usage

Source: Internet
Author: User

UniDDataBase-introduction and main usage summary, uniddatabase-usage

UniDDatabase can process data types such as INT, TEXT, FLOAT, DATE, TIME, Prefab, Texture2D, Audio, Position, Rotation, and ScriptFile. Folder structure: the folder structure of UniDDataBase helps developers manage files. All the content you want UniDDatabase to help you manage must be put in the correct folder. Place audio clips in the audio_uni folder. The UniDDatabase file is automatically placed in the DDatabase_uni folder. Prefabs is in the prefab_uni folder. Put the image in the Texture_2D_uni folder. Supports standalone and Professional edition of The unity3d engine. 100% compatible with the unity engine, using a line of code to access any data in a row. the data access speed is only 1000 ms for 0.193 rows of queries.

UnidDDataBase is a database Unity plug-in used to store and read local data. It stores data through a txt file or, more specifically, saves the data table to a txt file in its own unique string format. The most basic operations of a Database: add, delete, modify, and query. We already know that this plug-in allows us to manually create data tables, enter data, change data, add records, and delete records. The following describes how to use code to dynamically operate data tables.

In fact, these methods UniDDataBase have helped us encapsulate them and we only need to call them. These methods are class methods in the UniDDataBaseCs. cs file.

When calling a method, first declare the public TextAsset field name in the script. The txt file to be operated must be dragged in and cannot be loaded through Resources. Load.

1. Add record:

Public static void AddNewRecord (TextAsset ddatabase)

Description: adds a row of records to the data table and assigns the default value.

2. Delete record:

Public static void DeleteRecord (TextAsset ddatabase, int recordNumber)

Description: Delete the recordNumber row record.

Note: If you delete all the data in the data table, you must delete the data from the back to the back. Otherwise, you will find that some rows are not deleted because each row in the data table needs to move the remaining rows forward.

3. Update Data:

A function is provided to update the data of a cell in a data table, but the function that can update a row of records in a data table is not displayed. Of course this is enough.

Public static bool UpdateCell (TextAsset ddatabase, string tKeyCellData, int userInputInt)

Description: This is a method for updating an int-type cell. Of course, there are many other types.

Error: Programmer Error !!! This cell Does not support INT, itsupports: NULL;

It indicates that the updated cell does not exist at all. Check whether the row number and column number are bounded.

4. query data:

Only functions for querying the data of a cell are provided. For each type of function, the following is an int type method:

Public static int GetIntWhereColumnRowEquals (TextAsset ddatabase, int columnNumber, int rowNumber)

Description: obtains the value of a cell in column columnNumber of row rowNumber.

Public static String [] GetArrayOfDdKeyInColumn (TextAsset ddatabase, string columnName)

Description: obtains all values of the columnName column.

5. Other functions:

Public static string GetColumnName (TextAsset ddatabase, int rowNumber)

Description: Obtain the column name by column number. RowNumber should be colmunNumber. In other classes, there are also situations where the row number does not match the column number parameter. Try it by yourself.

Public static String [] GetArrayOfDdKeyInColumn (TextAsset ddatabase, string columnName)

Description: obtains all ddkeys corresponding to a column in the database file, that is, keys in each row of the txt data file.

Public static String [] GetArrayOfTextInColumnByPattern (TextAsset ddatabase, string columnName, Enum typeOfOperation, string stringPattern)

Description: some values in a column are obtained in some way. The typeOfOperation enumeration must be as declared by the enumeration in the example in the plug-in and cannot be changed, because the implementation code uses the string corresponding to the enumerated value for judgment, the declaration of this enumeration must be as follows:

[System. Serializable]
Public enum OperationType
{
All,
Equals,
Contains,
Greater,
GreaterThanOrEqual,
LessThan,
LessThanOrEqual,
Between
}

Public static int GetTotalColumns (TextAsset ddatabase)

Description: obtains the total number of columns in a data table.

Public static int GetTotalRows (TextAsset ddatabase)

Description: obtains the total number of data tables.

I also implemented this function myself:

Using System. text;

Using System. IO;

Private int GetTotalRows (string txtPath, int columnNumber) {// columnNumber indicates the number of fields in the data table
Using (StreamReader read = new StreamReader (txtPath, Encoding. Default ))
{
Return (read. ReadToEnd (). Split ('\ n'). Length-4)/(2 * columnNumber)-1;//Kai Tou 3 And Jiewei 1;
}
}

Tips:

1> In the txt file, you will find "EnemyContentTEXT0Default.txt [@ * _ * @] EnemyContentTEXTTable [@-_ * @] ColumnNumber = 0 [@ * _-@] RowNumber = 2 [@] INT "string, this is a key-value pair of the record value type. Before "INT", the keys used by UniDDataBase to interpret the txt file are themselves. "INT" is the value, and other rows are similar. This special string is returned through the public static string GetCellDataKeyStatic (string currentDatabaseName, string currentTableName, int rowNumber, int columnNumber) in the pseudo dolinqdatabase_unity class. Of course, this class is a class in the Editor folder that we cannot call. I am reminding you that we can rename it to our own class for calling. Of course, all the content related to the Editor class should be deleted.

2> when creating a data table, it is best not to include numbers in the table name. The specific reason is...

Related Article

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.