Skip to content
高凯 edited this page Dec 19, 2017 · 3 revisions

Data

editor tool

Open Data Editor
Window -> 数据编辑器(Data Editor)

In the 新增数据(new data) tab, enter the data name(数据名) and primary key name (主键) to create data tables, data tables will be placed Resources/Data directory, support recursive directory After building in the current data(当前数据) options, select the data you just created, edit data(编辑数据) tab, edit the fields you want
After editing the data, you can add the data by adding a new Data(新增数据) tab

  • StringArray type different data separated by '|'
  • Edit the data Remember to click the Save button to save the data, the new data Remember to re-click to generate the package file(重新生成打包文件)
  • Datasheet file support WPS directly open edit, if there are characters remember to save as UTF-8 encoding Excel can also edit datasheet files via conversion tools

Data table support into the corresponding class, more convenient to use, through DataGenerateManager read
Click 生成Data类(Generate Data Class) button, it will be in the Assets/Scipt/DataClassGenerate directory to create a Generate end of the cs file
Click 生成全部Data类(Generate All Data Class) button, it will generate all the data tables cs file

API

** DataManager**
public static bool GetIsExistData (string DataName) To determine whether a data exists
public static DataTable GetData (string DataName) Get a DataTable

DataGenerateManager
public static T GetData (string key) Get a generated data class

DataTable
public SingleData GetLineFromKey (string key) Get a row of data

SingleData
public int GetInt (string key) Get an Int
public float GetFloat (string key) Get a Float
public bool GetBool (string key) Get a Bool
public string GetString (string key) Get a String
public Vector2 GetVector2 (string key) Get a Vector2
public Vector3 GetVector3 (string key) Get a Vector3
public Color GetColor (string key) Get a Color
public T GetEnum <T> (string key) where T: struct Get an enumeration
public string [] GetStringArray (string key) Get a String array
public int [] GetIntArray (string key) Get an Int array

example

Not use the generated class

DataTable itemData = DataManager.GetData ("item");
for (int i = 0; i <itemData.TableIDs.Count; i ++)
{
    SingleData singleData = itemData.GetLineFromKey (itemData.TableIDs [i]);

    string itemName = singleData.GetString ("Name");
    int cost = singleData.GetInt ("Cost");
}

By generating the class

itemGenerate data = DataGenerateManager <itemGenerate> .GetData ("1");
string itemName = data.m_ItemName;
int cost = data.m_Cost;
Clone this wiki locally