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); }
void DrawToolBar() { GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); //2A+ GUILayout.BeginHorizontal(GUILayout.Width(mLeftBarWidth - 6)); //2B+ GUI.SetNextControlName("ForFouce"); _mAsset = mSelectionAsset; mSelectionAsset = (TextAsset)EditorGUILayout.ObjectField(mSelectionAsset, typeof(TextAsset), false); if (_mAsset != mSelectionAsset) { ReadFromTextAsset(); } GUILayout.EndHorizontal(); //2B- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); //2C+ if (mSelectionAsset != null) { if (GUILayout.Button("Import", EditorStyles.toolbarDropDown, GUILayout.Width(65))) { GUIContent[] menuItems = new GUIContent[] { new GUIContent("from OOForm table..."), new GUIContent("from Json..."), new GUIContent("from XML..."), new GUIContent("from CSV...") }; EditorUtility.DisplayCustomMenu(new Rect(mLeftBarWidth, 16, 0, 0), menuItems, -1, delegate(object userData, string[] options, int selected) { switch (selected) { case 0: { string path = EditorUtility.OpenFilePanel("Select file to import!", "", "txt"); if (path != "") { mSelectionTable = OOFormArray.ReadFromFile(path); mIsModify = true; } } break; case 1: { string path = EditorUtility.OpenFilePanel("Select file to import!", "", "txt"); if (path != "") { mSelectionTable = OOFormArray.ReadFromJsonFile(path); mIsModify = true; } } break; case 2: { string path = EditorUtility.OpenFilePanel("Select file to import!", "", "xml"); if (path != "") { mSelectionTable = OOFormArray.ReadFromXMLFile(path); mIsModify = true; } } break; case 3: { string path = EditorUtility.OpenFilePanel("Select file to import!", "", "csv"); if (path != "") { mSelectionTable = OOFormArray.ReadFormCSVFile(path); mIsModify = true; } } break; } } , null); } if (GUILayout.Button("Export", EditorStyles.toolbarDropDown, GUILayout.Width(65))) { GUIContent[] menuItems = new GUIContent[] { new GUIContent("to OOForm table..."), new GUIContent("to Json..."), new GUIContent("to XML..."), new GUIContent("to CSV...") }; EditorUtility.DisplayCustomMenu(new Rect(mLeftBarWidth + 65, 16, 0, 0), menuItems, -1, delegate(object userData, string[] options, int selected) { switch (selected) { case 0: { string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "txt"); if (path != "") { OOFormTools.WriteFileText(path, mSelectionTable.ToString()); } } break; case 1: { string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "txt"); if (path != "") { OOFormTools.WriteFileText(path, mSelectionTable.ToJsonString()); } } break; case 2: { string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "xml"); if (path != "") { OOFormTools.WriteFileText(path, mSelectionTable.ToXMLString(), System.Text.Encoding.UTF8); } } break; case 3: { string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "csv"); if (path != "") { OOFormTools.WriteFileText(path, mSelectionTable.ToCSVString(), System.Text.Encoding.UTF8); } } break; } } , null); } GUILayout.Label(""); GUILayout.Label("Search:", GUILayout.Width(50)); mSearchString = GUILayout.TextField(mSearchString, OOFormSkin.OStyle_ToolbarSearch, GUILayout.Width(120)); GUILayout.Label("", OOFormSkin.OStyle_ToolbarSearchRightCap); GUILayout.Label(" Column Page:", GUILayout.ExpandWidth(false)); if (GUILayout.Button("<", EditorStyles.toolbarButton, GUILayout.Width(40))) { mCurrentColumnPage--; mCurrentColumnPage = Mathf.Max(mCurrentColumnPage, 1); GUI.FocusControl("ForFouce"); } int max_column_page = mSelectionTable.mColumnCount / mPageColumnCount + 1; GUILayout.Label(mCurrentColumnPage.ToString() + "/" + max_column_page.ToString(), EditorStyles.textField, GUILayout.Width(50)); if (GUILayout.Button(">", EditorStyles.toolbarButton, GUILayout.Width(40))) { mCurrentColumnPage++; mCurrentColumnPage = Mathf.Min(mCurrentColumnPage, max_column_page); GUI.FocusControl("ForFouce"); } } GUILayout.EndHorizontal(); //2C- GUILayout.EndHorizontal(); //2A- }