public void BuildCSFile() { if (mDatas.Count == 0) { _LoadExcel(); } Debug.LogError("自动生成:" + mPath.ClassName + "类,请重新打包"); List <VariableData> varTypes = _GetVariable(); string nameSpace = null; string jxClass = mPath.ClassName; int index = mPath.ClassName.IndexOf("."); if (index != -1) { nameSpace = mPath.ClassName.Substring(0, index); jxClass = mPath.ClassName.Substring(index + 1); } AssetFile aFile = new AssetFile(jxClass.Substring(0, jxClass.Length - "Asset".Length)); if (!string.IsNullOrEmpty(nameSpace)) { aFile.SetNamespace(nameSpace); } for (int i = 0; i < varTypes.Count; i++) { var variable = varTypes[i]; if (!string.IsNullOrEmpty(variable.name)) { string ex = !string.IsNullOrEmpty(variable.context) ? (" //" + variable.context) : ""; if (!string.IsNullOrEmpty(variable.typeName)) { aFile.SetVariable(variable.typeName, variable.name + ";" + ex); } else { StringAnalyisis sa = new StringAnalyisis(); sa.Encrypt("{" + ComputerString(variable.typeValue, false) + "}"); sa.MoveNextPath("0"); var posIndex = sa.GetPos(); List <string> fTypeFiles = new List <string>(); bool isSameType = true; for (int p = 0; p < posIndex.Vluaes.Count; p++) { string value = sa.GetValue(p.ToString()); var fType = _StringTryBasicTypeName(value); fTypeFiles.Add(fType); if (fTypeFiles[0] != fType) { isSameType = false; } } if (fTypeFiles.Count == 0) { aFile.SetVariable("string", variable.name + ";" + ex); } else if (fTypeFiles.Count == 1) { aFile.SetVariable(fTypeFiles[0], variable.name + ";" + ex); } else { if (isSameType) { //数组 if (fTypeFiles[0] != "string") { //必定为数组 aFile.SetVariable(fTypeFiles[0] + "[]", variable.name + ";" + ex); } else { //超级复杂结构||类结构[]||string[] string allValue = sa.GetPatchValue(posIndex); if (allValue.IndexOf("{") == -1) { //字符数组 aFile.SetVariable("string[]", variable.name + ";" + ex); } else { isSameType = true; List <string> Last = null; for (int c = 0; c < posIndex.Vluaes.Count; c++) { List <string> tempStrs = new List <string>(); var vPatch = posIndex.GetPatchByName(c.ToString()); if (vPatch != null) { foreach (var k in vPatch.Vluaes) { tempStrs.Add(_StringTryBasicTypeName(sa.GetPatchValue(k.Value))); } } if (Last != null) { if (tempStrs.Count != Last.Count) { isSameType = false; } else { for (int s = 0; s < Last.Count; s++) { if (Last[s] != tempStrs[s]) { isSameType = false; } } } } Last = tempStrs; } if (isSameType) { //类数组 aFile.SetVariable(variable.name + "_Data[]", variable.name + ";" + ex); for (int p = 0; p < Last.Count; p++) { Last[p] = Last[p] + " param_" + p.ToString(); } aFile.SetSubClass(variable.name + "_Data", Last.ToArray()); } else { //超级复杂结构,不解析,给用户自定义 aFile.SetVariable(variable.name + "_Data", variable.name + ";" + ex); string[] pars = new string[fTypeFiles.Count]; for (int p = 0; p < pars.Length; p++) { pars[p] = "string" + " param_" + p.ToString(); } aFile.SetSubClass(variable.name + "_Data", pars); } } } } else { //类结构 aFile.SetVariable(variable.name + "_Data", variable.name + ";" + ex); string[] pars = new string[fTypeFiles.Count]; for (int p = 0; p < pars.Length; p++) { pars[p] = fTypeFiles[p] + " param_" + p.ToString(); } aFile.SetSubClass(variable.name + "_Data", pars); } } } } } FEPath.CreateDirectory(mPath.CSPath); aFile.Build(mPath.CSPath + "/" + jxClass + ".cs"); }