private static OOFormArray InitForm(DataTable dt) { OOFormArray form; int colNum = dt.Columns.Count; int rowNum = dt.Rows.Count; form = new OOFormArray(); colNum = dt.Columns.Count; rowNum = dt.Rows.Count; // init form for (int i = 0; i < colNum; i++) { form.InsertColumn(i); } for (int i = 0; i < rowNum + 1; i++) { form.InsertRow(i); } // set column key for (int c = 0; c < colNum; c++) { string cName = dt.Columns[c].ColumnName; form.SetString(cName, c, 0); } return(form); }
/// <summary> /// Get OOFormArray from json string. /// </summary> /// <param name="jsonString"></param> /// <returns></returns> public static OOFormArray GetFormByJsonString(string jsonString) { OOFormArray form_array = new OOFormArray(); List <Hashtable> table_list = OOLitJson.JsonMapper.ToObject <List <Hashtable> >(jsonString); form_array.InsertRow(0); form_array.InsertColumn(0); //int row = 0; foreach (Hashtable table in table_list) { form_array.InsertRow(form_array.mRowCount); foreach (string key_str in table.Keys) { if (form_array.GetColumn(key_str) == -1) { if (form_array.mColumnDic.Count <= 1) { form_array.SetString(key_str, 0, 0); form_array.AddColumnName(key_str, 0); } else { form_array.InsertColumn(form_array.mColumnCount); form_array.SetString(key_str, form_array.mColumnCount - 1, 0); form_array.AddColumnName(key_str, form_array.mColumnCount - 1); } } form_array.SetString(table[key_str].ToString(), form_array.GetColumn(key_str), form_array.mRowCount - 1); } } return(form_array); }
/// <summary> /// Show table in table view. /// </summary> /// <param name="idx"></param> void ShowTableData(int idx) { if (mFormManager == null) { return; } if (mFormManager.mTableList.Count > 0) { if (idx < mFormManager.mTableList.Count) { if (idx < 0) { idx = GetFirst(); } mCurrentColumnPage = 1; mCurrentRowPage = 1; mSelectionIndex = idx; mSelectionAsset = mFormManager.mTableList[idx]; mSelectionAssetPath = AssetDatabase.GetAssetPath(mSelectionAsset.GetInstanceID()); mSelectionTable = OOFormArray.ReadFromFile(mSelectionAssetPath); } } }
// 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()); }
public static string GetString(object key) { if (mForm == null) { mForm = OOFormArray.ReadFromResources("OOForm/Tables/StringTable"); } return(mForm.GetString(mLanguage.ToString(), key)); }
public static string DataTable2CSV(DataTable dt) { OOFormArray form = DataTable2OOFormArray(dt); string csv = form.ToCSVString(); print(csv); return(csv); }
IEnumerator StartGetNetTable() { string url = @"http://ooform.ooroom.com/NetItem.txt"; Debug.Log(url); WWW www = new WWW(url); yield return(www); System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding(); mFormArray = OOFormArray.GetForm(converter.GetString(www.bytes)); }
void SetAsset(TextAsset textAsset) { mSelectionAsset = textAsset; if (textAsset == null) { mSelectionTable = null; mSelectionAssetPath = ""; } else { mSelectionTable = OOFormArray.GetForm(textAsset.text); mSelectionAssetPath = AssetDatabase.GetAssetPath(textAsset.GetInstanceID()); } }
// 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 + "/RuntimeTable.txt"; if (File.Exists(mSavePath)) { mForm = OOFormArray.ReadFromFile(mSavePath); } else { mForm = OOFormArray.ReadFromResources("OOForm/Tables/RuntimeTable"); } }
/// <summary> /// Get OOFormArray from xml string; /// </summary> /// <param name="xmlString"></param> /// <returns></returns> public static OOFormArray GetFormByXMLString(string xmlString) { //if string with BOM,remove it. if ((int)xmlString[0] == 65279) { xmlString = xmlString.Substring(1); } OOFormArray form_array = new OOFormArray(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlString); form_array.InsertRow(0); form_array.InsertColumn(0); XmlNode node = xmlDoc.FirstChild; XmlNodeList component_list = node.ChildNodes; foreach (XmlNode row_node in component_list) { form_array.InsertRow(form_array.mRowCount); foreach (XmlAttribute attr in row_node.Attributes) { if (form_array.GetColumn(attr.Name) == -1) { if (form_array.mColumnDic.Count <= 1) { form_array.SetString(attr.Name, 0, 0); form_array.AddColumnName(attr.Name, 0); } else { form_array.InsertColumn(form_array.mColumnCount); form_array.SetString(attr.Name, form_array.mColumnCount - 1, 0); form_array.AddColumnName(attr.Name, form_array.mColumnCount - 1); } } form_array.SetString(attr.Value.ToString(), form_array.GetColumn(attr.Name), form_array.mRowCount - 1); } } return(form_array); }
void OnGUI() { if (GUI.Button(new Rect(10, 75, 150, 30), "Animals(CSV)")) { TextAsset csv_text = Resources.Load("OOForm/OtherFormatTables/AnimalsCSV.csv") as TextAsset; mFormArray = OOFormArray.GetFormByCSVString(csv_text.text); } if (GUI.Button(new Rect(170, 75, 150, 30), "GameConfig(Json)")) { TextAsset json_text = Resources.Load("OOForm/OtherFormatTables/GameConfigJson") as TextAsset; mFormArray = OOFormArray.GetFormByJsonString(json_text.text); } if (GUI.Button(new Rect(330, 75, 150, 30), "StringTable(XML)")) { TextAsset xml_text = Resources.Load("OOForm/OtherFormatTables/StringTableXML") as TextAsset; //System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding(); //mFormArray = OOFormArray.GetForm(converter.GetString(www.bytes)); //byte[] b = ""; mFormArray = OOFormArray.GetFormByXMLString(xml_text.text); } if (mFormArray != null) { for (int i = 0; i < mFormArray.mRowCount; i++) { for (int j = 0; j < mFormArray.mColumnCount; j++) { GUI.Label(new Rect(j * 120 + 100, i * 25 + 150, 100, 23), mFormArray.mData[j][i]); } } } }
/// <summary> /// Convert text to a OOFormArray /// </summary> /// <param name="formString"></param> /// <returns></returns> public static OOFormArray GetForm(string formString) { OOFormArray form_array = new OOFormArray(); string[] string_rows = formString.Split('\n'); int column_count = 0; int row_count = string_rows.Length; if (row_count > 0) { string[] string_firstRow = string_rows[0].Split('\t'); column_count = string_firstRow.Length; form_array.InsertRow(0); for (int i = 0; i < column_count; i++) { form_array.InsertColumn(i); form_array.mData[i][0] = string_firstRow[i].Replace("\r", ""); } for (int j = 1; j < row_count; j++) { string[] string_oneRow = string_rows[j].Split('\t'); int nod_count = Mathf.Min(column_count, string_oneRow.Length); form_array.InsertRow(j); for (int i = 0; i < nod_count; i++) { form_array.mData[i][j] = string_oneRow[i].Replace("\r", ""); } } } return(form_array); }
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); }
private static OOFormArray DataTable2OOFormArray(DataTable dt) { OOFormArray form = new OOFormArray(); // csv = ""; form = InitForm(dt); int colNum = dt.Columns.Count; int rowNum = dt.Rows.Count; for (int r = 0; r < rowNum; r++) { var dr = dt.Rows[r]; for (int c = 0; c < colNum; c++) { string cName = dt.Columns[c].ColumnName; int row = r + 1; int col = c; System.Type tp = dt.Columns[c].DataType; //print(tp); if (tp == typeof(int)) { int val = (int)dr[c]; bool bSet = form.SetInt(val, col, row); // print("Set Int:" + val.ToString() + " OK?" + bSet.ToString()); } else if (tp == typeof(Vector2)) { Vector2 val = (Vector2)dr[c]; bool bSet = form.SetVector2(val, col, row); //print("Set Vec2:" + val.ToString() + " OK?" + bSet.ToString()); } else if (tp == typeof(Vector3)) { Vector3 val = (Vector3)dr[c]; bool bSet = form.SetVector3(val, col, row); //print("Set Vec3:" + val.ToString() + " OK?" + bSet.ToString()); } else if (tp == typeof(Vector4)) { Vector4 val = (Vector4)dr[c]; bool bSet = form.SetVector4(val, col, row); //print("Set Vec4:" + val.ToString() + " OK?" + bSet.ToString()); } else if (tp == typeof(string)) { string val = (string)dr[c]; bool bSet = form.SetString(val, col, row); //print("Set String:" + val + " OK?" + bSet.ToString()); } else if (tp == typeof(float)) { float val = (float)dr[c]; bool bSet = form.SetFloat(val, col, row); // print("Set Float:" + val + " OK?" + bSet.ToString()); } else if (tp == typeof(Rect)) { Rect val = (Rect)dr[c]; bool bSet = form.SetRect(val, col, row); // print("Set Rect:" + val + " OK?" + bSet.ToString()); } else if (tp == typeof(bool)) { bool val = (bool)dr[c]; bool bSet = form.SetBool(val, col, row); //print("Set Bool:" + val + " OK?" + bSet.ToString()); } else { int val = (int)dr[c]; bool bSet = form.SetInt(val, col, row); } } } return(form); }
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- }
// Use this for initialization void Start() { mAnimalArray = OOFormArray.ReadFromResources("OOForm/Tables/Animals"); SetAnimal(mCurrentAnimal); }