// Use this for initialization void Start() { //Here i save form in "Assets" folder for test, you can change it where you like. mSavePath = Application.dataPath + "/GameConfig.txt"; if (File.Exists(mSavePath)) { mForm = OOFormArray.ReadFromFile(mSavePath); } else { mForm = OOFormArray.ReadFromResources("OOForm/Tables/GameConfig"); } //read data by column string name int run_times = mForm.GetInt("Value", "RUN_TIMES") + 1; mForm.SetInt(run_times, "Value", "RUN_TIMES"); Save(); //Read data by enum mIsTick = mForm.GetBool("Value", "IS_TICK"); mWindowRect = mForm.GetRect("Value", "WINDOW_RECT"); Debug.Log(mWindowRect.ToString()); }
void OnGUI() { Rect tmp_rect; if (mForm != null) { for (int i = 1; i < mForm.mRowCount; i++) { tmp_rect = mForm.GetRect("rect", i); if (GUI.Button(tmp_rect, mForm.GetString("name", i))) { mForm.DeleteRow(i); Save(); return; } } } }
public static bool LoadFromCSVFile(string path, ref DataTable DT) { int DTColNum = DT.Columns.Count; OOFormArray form = new OOFormArray(); form = OOFormArray.ReadFormCSVFile(path); int rowCnt = form.mRowCount; int colCnt = form.mColumnCount; //print("DTColNum" + DTColNum + " colCnt:" + colCnt + " rowCnt:" + rowCnt); if (DTColNum != colCnt) { print("Not Match!"); } List <string> Keys = new List <string>(); bool bSameKeys = true; for (int i = 0; i < colCnt; i++) { string key = form.GetString(i, 0); if (DT.Columns[i].ColumnName != key) { bSameKeys = false; break; } //print("ColumnName:" + DT.Columns[i].ColumnName + " Key:" + key); /* if(DT.Columns[i].ColumnName == key) * { * print("Good Key:" + key); * }*/ Keys.Add(key); //print("Key:" + key); } if (!bSameKeys) { return(false); } // read data for (int r = 1; r < rowCnt; r++) { DataRow dr = DT.NewRow(); for (int c = 0; c < Keys.Count; c++) { System.Type tp = DT.Columns[c].DataType; if (tp == typeof(int)) { int val = form.GetInt(c, r); dr[c] = val; DebugPrint("Int:" + val); // print("Set Int:" + val.ToString() + " OK?" + bSet.ToString()); } else if (tp == typeof(Vector2)) { Vector2 val = form.GetVector2(c, r); dr[c] = val; DebugPrint("Vector2:" + val.ToString()); } else if (tp == typeof(Vector3)) { Vector3 val = form.GetVector3(c, r); dr[c] = val; DebugPrint("Vector3:" + val.ToString()); } else if (tp == typeof(Vector4)) { Vector4 val = form.GetVector4(c, r); dr[c] = val; DebugPrint("Vector4:" + val.ToString()); } else if (tp == typeof(string)) { string val = form.GetString(c, r); dr[c] = val; DebugPrint("string:" + val); } else if (tp == typeof(float)) { float val = form.GetFloat(c, r); dr[c] = val; DebugPrint("float:" + val.ToString()); } else if (tp == typeof(Rect)) { Rect val = form.GetRect(c, r); dr[c] = val; DebugPrint("Rect:" + val.ToString()); } else if (tp == typeof(bool)) { bool val = form.GetBool(c, r); dr[c] = val; DebugPrint("Bool:" + val.ToString()); } else { DebugPrint("Invalid Datatype"); } } DT.Rows.Add(dr); //PrintDataTable(DT); } int DTRowCnt = DT.Rows.Count; print("Load DataTable Rows:" + DTRowCnt.ToString()); return(true); }