//This code create by CodeEngine ,don't modify using System; using System.Collections.Generic; using System.Collections; using UnityEngine; using System.IO; using System.Text; class CharModelUIShowItem { public int DataID; public string ModelPath; public string ModelName; public Vector3 BodyPosition; public Vector3 BodyRotation; public Vector3 HalfPosition; public Vector3 HalfRotation; public string[] StrValues; } class CharModelUIShowTable { public static List _TabTitle = new List(); public static Dictionary _TabItems = new Dictionary(); public static void ReadTable() { string filePath = Application.dataPath + "/../../Public/ClientTables/CharModel.txt"; _TabItems.Clear(); _TabTitle.Clear(); if (File.Exists(filePath)) { FileStream rfs = new FileStream(filePath, FileMode.Open); StreamReader sr = new StreamReader(rfs, Encoding.GetEncoding("GB2312")); try { int i = 0; while (!sr.EndOfStream) //14,15,16,17 { if (i < 4) { _TabTitle.Add(sr.ReadLine()); ++i; continue; } string curLine = sr.ReadLine(); string[] values = curLine.Split('\t'); if (values.Length < 17) { Debug.LogError("ReadCharModel,LengthError"); return; } CharModelUIShowItem curData = new CharModelUIShowItem(); if (!values[0].StartsWith("#")) { curData.DataID = int.Parse(values[0]); curData.ModelName = (values[2]); curData.ModelPath = values[4]; curData.BodyPosition = StrToVector3(values[15]); curData.BodyRotation = StrToVector3(values[16]); curData.HalfPosition = StrToVector3(values[17]); curData.HalfRotation = StrToVector3(values[18]); curData.StrValues = values; _TabItems.Add(curData.DataID, curData); } } } catch (Exception e) { Debug.Log("Read table error:" + e.ToString()); } rfs.Close(); sr.Close(); } } public static void WriteTable() { if (_TabTitle.Count == 0) { ReadTable(); } string filePath = Application.dataPath + "/../../Public/ClientTables/CharModel.txt"; if (File.Exists(filePath)) { File.Delete(filePath); } FileStream wfs = new FileStream(filePath, FileMode.CreateNew); StreamWriter sw = new StreamWriter(wfs, Encoding.GetEncoding("GB2312")); try { foreach (var title in _TabTitle) { sw.WriteLine(title); } foreach (var tabItem in _TabItems.Values) { sw.WriteLine(TabItemToString(tabItem)); ; } } catch (Exception e) { } sw.Close(); wfs.Close(); } private static Vector3 StrToVector3(string strValue) { var splitStrs = strValue.Split(';'); if (splitStrs.Length != 3) { Debug.LogError("StrToVector3 error:" + strValue); return Vector3.zero; } return new Vector3(float.Parse(splitStrs[0]), float.Parse(splitStrs[1]), float.Parse(splitStrs[2])); } private static string Vector3ToStr(Vector3 vector) { return vector.x + ";" + vector.y + ";" + vector.z; } private static string TabItemToString(CharModelUIShowItem showItem) { string itemStr = ""; for (int i = 0; i < showItem.StrValues.Length; ++i) { if (i == 15) { itemStr += Vector3ToStr(showItem.BodyPosition); } else if (i == 16) { itemStr += Vector3ToStr(showItem.BodyRotation); } else if (i == 17) { itemStr += Vector3ToStr(showItem.HalfPosition); } else if (i == 18) { itemStr += Vector3ToStr(showItem.HalfRotation); } else { itemStr += showItem.StrValues[i]; } if (i < showItem.StrValues.Length - 1) { itemStr += "\t"; } } return itemStr; } }