public void GenData(IDataReadable reader, string outputPath = null) { IDataReadable exReader = reader; List <Dictionary <string, string> > rows = exReader.GetRows(); JsonData data = new JsonData(); string arrayString = JsonMapper.ToJson(rows); Debug.Log(arrayString); JsonData jsonArray = JsonMapper.ToObject(arrayString); data[reader.currentDataTypeName] = jsonArray; if (outputPath == null) { outputPath = PathConfig.GetLocalGameDataPath(PathConfig.DataType.Json) + Path.GetFileNameWithoutExtension(reader.currentDataTypeName) + Data.GameDatas.Json.JsonData.m_fileExtention; } if (!Directory.Exists(Path.GetDirectoryName(outputPath))) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } data.Save(outputPath); AssetDatabase.Refresh(); }
public void GenData(IDataReadable reader, string outputPath = null) { IDataReadable exReader = reader; XDocument xDoc = new XDocument(); XElement root = new XElement("Root"); xDoc.Add(root); List <string> name = exReader.GetMemberNames(); List <string> value = exReader.GetColume(2); for (int i = 0; i < name.Count; i++) { XElement item = new XElement(name[i], value[i]); root.Add(item); } if (outputPath == null) { outputPath = PathConfig.GetLocalGameDataPath(PathConfig.DataType.Pref) + Path.GetFileNameWithoutExtension(reader.currentDataTypeName) + PrefData.m_fileExtention; } if (!Directory.Exists(Path.GetDirectoryName(outputPath))) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } xDoc.Save(outputPath); AssetDatabase.Refresh(); var ai = AssetImporter.GetAtPath(PathEx.ConvertAbstractToAssetPath(outputPath)); ai.assetBundleName = PathConfig.DataBundleName; AssetDatabase.Refresh(); }
public void GenCS(IDataReadable reader) { string className = reader.currentDataTypeName; CodeGener protobufBaseGener = new CodeGener(ProtobufData.nameSpace, className); protobufBaseGener.newClass.AddMemberCostomAttribute("ProtoBuf.ProtoContract"); protobufBaseGener.AddImport("System", "ProtoBuf"); List <string> comment = reader.GetComment(); protobufBaseGener .AddBaseType("ProtobufData<" + className + ">") .AddMemberField(typeof(string), "fileName", (member) => { member.AddFieldMemberInit("\"" + className + "\""); }, System.CodeDom.MemberAttributes.Static | System.CodeDom.MemberAttributes.Final | System.CodeDom.MemberAttributes.Public); reader.GetTitle().ForEach((i, title) => { string[] titleSplit = title.Split('|'); string varName = titleSplit[0]; string typeName = titleSplit[1]; protobufBaseGener.AddMemberProperty(typeName.GetTypeByString(), varName, (member) => { member.AddComment(comment[i], true); member.AddMemberCostomAttribute("ProtoBuf.ProtoMember", (i + 1).ToString()); }); }); PathEx.MakeFileDirectoryExist(PathConfig.GetLoaclGameDataClassPath(PathConfig.DataType.Protobuf)); protobufBaseGener.GenCSharp(PathConfig.GetLoaclGameDataClassPath(PathConfig.DataType.Protobuf)); }
public void GenData(IDataReadable reader, string outputPath = null) { IDataReadable exReader = reader; XDocument xDoc = new XDocument(); XElement root = new XElement("Root"); xDoc.Add(root); List <Dictionary <string, string> > rows = exReader.GetRows(); for (int i = 0; i < rows.Count; i++) { XElement item = new XElement("item"); root.Add(item); foreach (KeyValuePair <string, string> pair in rows[i]) { item.Add(new XElement(pair.Key, pair.Value)); } } if (outputPath == null) { outputPath = PathConfig.GetLocalGameDataPath(PathConfig.DataType.Xml) + Path.GetFileNameWithoutExtension(reader.currentDataTypeName) + XmlData.m_fileExtention; } if (!Directory.Exists(Path.GetDirectoryName(outputPath))) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } xDoc.Save(outputPath); AssetDatabase.Refresh(); }
public void GenData(IDataReadable reader, string outputPath = null) { string className = reader.currentDataTypeName; Type protobufDataType = Type.GetType(ProtobufData.nameSpace + "." + className + ",Assembly-CSharp"); //Debug.Log(ProtobufData.nameSpace + "." + className + ",Assembly-CSharp" + " 是否存在" + protobufDataType.ToString()); if (protobufDataType == null) { GenCS(reader); protobufDataType = Type.GetType(ProtobufData.nameSpace + "." + className + ",Assembly-CSharp"); Debug.unityLogger.Log("Gen the CS File Please"); } List <Dictionary <string, object> > rowObjs = reader.GetRowObjs(); List <object> result = new List <object>(); for (int i = 0; i < rowObjs.Count; i++) { object item = Activator.CreateInstance(protobufDataType); PropertyInfo[] propertys = protobufDataType.GetProperties(); foreach (KeyValuePair <string, object> pair in rowObjs[i]) { PropertyInfo prop = propertys.First((pro) => { return(pro.Name == pair.Key); }); prop.SetValue(item, pair.Value, null); Debug.unityLogger.Log(pair.ConverToString()); } result.Add(item); } string protoPath = PathConfig.GetLocalGameDataPath(PathConfig.DataType.Protobuf); PathEx.MakeFileDirectoryExist(protoPath); if (ProtoBuf.Serializer.NonGeneric.CanSerialize(protobufDataType)) { string resPath = protoPath + className + ProtobufData.ex; if (outputPath != null) { resPath = outputPath; } string root = Path.GetDirectoryName(resPath); PathEx.MakeFileDirectoryExist(root); using (var file = System.IO.File.Create(resPath)) { ProtoBuf.Serializer.NonGeneric.Serialize(file, result); Debug.unityLogger.Log(resPath + "导出成功"); } } else { Debug.unityLogger.LogError("序列化", protobufDataType.FullName + "不可序列化!"); } }
public void GenData(IDataReadable reader, string outputPath = null) { string className = reader.currentDataTypeName; Type objDataType = Type.GetType(ObjData.nameSpace + "." + className + ",Assembly-CSharp"); ObjDataBundle data = ScriptableObject.CreateInstance <ObjDataBundle>(); List <Dictionary <string, object> > rowObjs = reader.GetRowObjs(); //ArrayList result = new ArrayList(); for (int i = 0; i < rowObjs.Count; i++) { var item = Activator.CreateInstance(objDataType); PropertyInfo[] propertys = objDataType.GetProperties(); foreach (KeyValuePair <string, object> pair in rowObjs[i]) { Debug.logger.Log(pair.ConverToString()); PropertyInfo prop = propertys.First((pro) => { return(pro.Name == pair.Key); }); prop.SetValue(item, pair.Value, null); } data.dataArray.Add(item); } string dataPath = PathConfig.GetLocalGameDataPath(PathConfig.DataType.Obj); PathEx.MakeDirectoryExist(dataPath); string resPath = dataPath + className + ObjData.ex; if (outputPath != null) { resPath = outputPath; } string root = Path.GetDirectoryName(resPath); PathEx.MakeDirectoryExist(root); AssetDatabase.CreateAsset(data, "Assets/" + className + ObjData.ex); string tempPath = Path.Combine(Application.dataPath, className + ObjData.ex); if (File.Exists(resPath)) { File.Delete(resPath); } File.Move(tempPath, resPath); Debug.Log("保存到了" + resPath); }
private static void GenData(IDataReadable rder) { IDataReadable reader = rder; XDocument xDoc = new XDocument(); XElement root = new XElement("Root"); xDoc.Add(root); //List<string> commentLine = reader.GetLine(0, 1); List <string> keyLine = reader.GetColume(1, 1); int num = 2; Array languageType = Enum.GetValues(typeof(LanguageConst.LanguageType)); for (int n = 0; n < languageType.Length; n++) { XElement languageEle = new XElement("item"); root.Add(languageEle); List <string> valueLine = reader.GetColume(num, 1, keyLine.Count); for (int i = 0; i < keyLine.Count; i++) { if (valueLine.Count > i) { languageEle.Add(new XElement(keyLine[i], valueLine[i])); } else { languageEle.Add(new XElement(keyLine[i], valueLine[i])); } } num++; } string outputPath = PathConfig.LanguageDataPath; if (!Directory.Exists(Path.GetDirectoryName(outputPath))) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } xDoc.Save(outputPath); AssetDatabase.Refresh(); }
public void GenData(IDataReadable reader, string outputPath = null) { IDataReadable exReader = reader; List <Dictionary <string, string> > rows = exReader.GetRows(); foreach (var dict in rows) { var keyList = new List <string>(dict.Keys); foreach (var key in keyList) { dict[key] = DataUtil.HandleExportXmlValue(dict[key], reader.attributeDict[key]); } } JsonData data = new JsonData(); string arrayString = JsonMapper.ToJson(rows); Debug.Log(arrayString); JsonData jsonArray = JsonMapper.ToObject(arrayString); data[reader.currentDataTypeName] = jsonArray; if (outputPath == null) { outputPath = PathConfig.GetLocalGameDataPath(PathConfig.DataType.Json) + Path.GetFileNameWithoutExtension(reader.currentDataTypeName) + Data.GameDatas.Json.JsonData.m_fileExtention; } if (!Directory.Exists(Path.GetDirectoryName(outputPath))) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } data.Save(outputPath); AssetDatabase.Refresh(); var ai = AssetImporter.GetAtPath(PathEx.ConvertAbstractToAssetPath(outputPath)); ai.assetBundleName = PathConfig.DataBundleName; AssetDatabase.Refresh(); }
public void GenData(IDataReadable reader, string outputPath = null) { IDataReadable exReader = reader; XDocument xDoc = new XDocument(); XElement root = new XElement("Root"); xDoc.Add(root); List <Dictionary <string, string> > rows = exReader.GetRows(); for (int i = 0; i < rows.Count; i++) { XElement item = new XElement("item"); root.Add(item); foreach (KeyValuePair <string, string> pair in rows[i]) { var finalStr = DataUtil.HandleExportXmlValue(pair.Value, reader.attributeDict[pair.Key]); item.Add(new XElement(pair.Key, finalStr)); } } if (outputPath == null) { outputPath = PathConfig.GetLocalGameDataPath(PathConfig.DataType.Xml) + Path.GetFileNameWithoutExtension(reader.currentDataTypeName) + XmlData.m_fileExtention; } if (!Directory.Exists(Path.GetDirectoryName(outputPath))) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } //xDoc.Save(outputPath); File.WriteAllText(outputPath, xDoc.ToString()); AssetDatabase.Refresh(); var ai = AssetImporter.GetAtPath(PathEx.ConvertAbstractToAssetPath(outputPath)); ai.assetBundleName = PathConfig.DataBundleName; AssetDatabase.Refresh(); }
public void GenCS(IDataReadable reader) { string className = reader.currentDataTypeName; DataClassesGener.CreateNewClass(className, typeof(Data.GameDatas.Json.JsonData), reader.fieldDict); }
public void GenCS(IDataReadable reader) { string className = reader.currentDataTypeName; ObjDataClassGener.CreateNewClass(className, reader.fieldDict, reader.attributeDict); }
public void GenData(IDataReadable reader, string outputPath = null) { string className = reader.currentDataTypeName; Type objDataType = Type.GetType(ObjData.nameSpace + "." + className + ",Assembly-CSharp"); Type bundleType = Type.GetType(ObjData.nameSpace + "." + className + "Bundle" + ",Assembly-CSharp"); //var bundleType = typeof(ObjDataBundle<>).MakeGenericType(objDataType); var data = ScriptableObject.CreateInstance(bundleType); List <Dictionary <string, object> > rowObjs = reader.GetRowObjs(); //ArrayList result = new ArrayList(); for (int i = 0; i < rowObjs.Count; i++) { var item = Activator.CreateInstance(objDataType); PropertyInfo[] propertys = objDataType.GetProperties(); foreach (KeyValuePair <string, object> pair in rowObjs[i]) { Debug.unityLogger.Log(pair.ConverToString()); PropertyInfo prop = propertys.First((pro) => { return(pro.Name == pair.Key); }); prop.SetValue(item, pair.Value, null); } var field = bundleType.GetField("dataArray"); var list = field.GetValue(data); var fieldType = field.FieldType; var fieldMethods = fieldType.GetMethods(); var method = fieldType.GetMethod("Add"); method.Invoke(list, new object[] { item }); field.SetValue(data, list); //field.InvokeByReflect("Add", item); //data.dataArray.Add(item); } string dataPath = PathConfig.GetLocalGameDataPath(PathConfig.DataType.Obj); PathEx.MakeFileDirectoryExist(dataPath); string resPath = dataPath + className + ObjData.ex; if (outputPath != null) { resPath = outputPath; } string root = Path.GetDirectoryName(resPath); PathEx.MakeFileDirectoryExist(root); AssetDatabase.CreateAsset(data, "Assets/" + className + ObjData.ex); string tempPath = Path.Combine(Application.dataPath, className + ObjData.ex); if (File.Exists(resPath)) { File.Delete(resPath); } File.Move(tempPath, resPath); Debug.Log("保存到了" + resPath); AssetDatabase.Refresh(); var ai = AssetImporter.GetAtPath(PathEx.ConvertAbstractToAssetPath(resPath)); ai.assetBundleName = PathConfig.DataBundleName; AssetDatabase.Refresh(); }
public ObjectDataReader(IDataReadable dataReadable) { this.dataReadable = dataReadable; this.enumerator = dataReadable.GetDataEnumerator(); }