public void SaveNode(GameObject _object) { bufs = new Dictionary <string, byte[]>(); resmgr = new ResMgr(this); if (debug) { Debug.Log("SaveNode:" + _object); } MyJson.JsonNode_Object _json = new MyJson.JsonNode_Object(); Obj2Json(_object, _json);//扫描转换 //将树也加入bufs StringBuilder sb = new StringBuilder(); _json.ConvertToStringWithFormat(sb, 4); byte[] bs = System.Text.Encoding.UTF8.GetBytes(sb.ToString()); string sha1 = ResLibTool.ComputeHashString(bs); bufs[sha1 + ".jsontree.txt"] = bs; }
void SaveItem() { //GameObject setobj = null;//选中的对象 //bool bUseHashName = true;//是否使用hash作为资源文件名 //string exportResult = null;//导出结果 //string exportPath = null;//导出路径 //bool bUseHashTreeName = false;//是否使用hash作为导出节点名 //string exportNodeName = "";//导出节点名称 nodeParser.nodeParser np = new nodeParser.nodeParser(); np.SaveNode(this.setobj);//先强制使用HashName if (System.IO.Directory.Exists(exportPath) == false) { System.IO.Directory.CreateDirectory(exportPath); } string respath = System.IO.Path.Combine(exportPath, "resources"); if (System.IO.Directory.Exists(respath) == false) { System.IO.Directory.CreateDirectory(respath); } MyJson.JsonNode_Array indexfile = new MyJson.JsonNode_Array(); foreach (var f in np.bufs) { //写入文件 { var file = System.IO.Path.Combine(respath, f.Key); System.IO.File.WriteAllBytes(file, f.Value); } //记录索引 MyJson.JsonNode_Object indexitem = new MyJson.JsonNode_Object(); indexitem["Name"] = new MyJson.JsonNode_ValueString("resources/" + f.Key); indexitem["Length"] = new MyJson.JsonNode_ValueNumber(f.Value.Length); indexfile.Add(indexitem); } indexfile.Sort((a, b) => { return(string.Compare(a.asDict()["Name"].AsString(), b.asDict()["Name"].AsString())); }); {//保存索引文件 byte[] indexcode = System.Text.Encoding.UTF8.GetBytes(indexfile.ToString()); exportResult = exportNodeName; if (bUseHashTreeName) { exportResult = ResLibTool.ComputeHashString(indexcode); } string outfile = System.IO.Path.Combine(exportPath, exportResult + ".indexlist.txt"); System.IO.File.WriteAllBytes(outfile, indexcode); } }
public string SaveTexture(Texture2D tex) { int id = tex.GetInstanceID(); string name = null; if (savecache.TryGetValue(id, out name)) { return(name); } #if UNITY_EDITOR name = SaveTextureEditor(tex); savecache[id] = name; return(name); #endif if (parser.debug) { Debug.Log("SaveTexture" + tex.name); } int i = tex.name.LastIndexOf("."); string ext = "png"; if (i < 0) { tex.name = tex.name + ".png"; } else { ext = tex.name.Substring(i + 1); } if (ext == "png") { byte[] bs = tex.EncodeToPNG(); string sha1 = ResLibTool.ComputeHashString(bs); name = sha1 + "." + ext; bufs[name] = bs; } else if (ext == "jpg") { byte[] bs = tex.EncodeToJPG(); string sha1 = ResLibTool.ComputeHashString(bs); name = sha1 + "." + ext; bufs[name] = bs; } else { throw new Exception("不知道文件类型" + ext); } savecache[id] = name; return(name); }
public string SaveMat(Material mat) { int id = mat.GetInstanceID(); string name = null; if (savecache.TryGetValue(id, out name)) { return(name); } MyJson.JsonNode_Object _json = new MyJson.JsonNode_Object(); //parser.matParser.WriteToJson(this, mat, _json); #if UNITY_EDITOR if (parser.GetMatParser(mat.shader.name) == null) { var json = nodeParser.GetMatConfig(mat); parser.InitMatParser(mat.shader.name, json); #region 自动保存shaderparser配置,这一段可以关闭 string path = Application.dataPath + "/resources/shaderparser"; if (System.IO.Directory.Exists(path) == false) { System.IO.Directory.CreateDirectory(path); } string shadername = mat.shader.name; shadername = shadername.Replace("/", "%2f"); string file = path + "/" + shadername + ".shaderparser.txt"; if (System.IO.File.Exists(file)) { System.IO.File.Delete(file); } System.IO.File.WriteAllText(file, json.ToString()); #endregion } #endif parser.GetMatParser(mat.shader.name).WriteToJson(this, mat, _json); System.Text.StringBuilder sb = new System.Text.StringBuilder(); _json.ConvertToStringWithFormat(sb, 4); byte[] bs = System.Text.Encoding.UTF8.GetBytes(sb.ToString()); string sha1 = ResLibTool.ComputeHashString(bs); name = sha1 + ".jsonmat.txt"; bufs[name] = bs; savecache[id] = name; return(name); }
string SaveTextureEditor(Texture2D tex) { string localp = System.IO.Path.GetDirectoryName(Application.dataPath); string path = AssetDatabase.GetAssetPath(tex); string filename = localp + "/" + path; int i = tex.name.LastIndexOf("."); string ext = "png"; if (i >= 0) { ext = tex.name.Substring(i + 1); } byte[] bs = System.IO.File.ReadAllBytes(filename); string sha1 = ResLibTool.ComputeHashString(bs); string name = sha1 + "." + ext; bufs[name] = bs; Debug.Log("filename=" + name + " ext=" + ext); return(name); }
public string SaveAniClip(AniClip clip) { int id = clip.GetInstanceID(); string name = null; if (savecache.TryGetValue(id, out name)) { return(name); } using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { BitHelper.WriteAniClip(clip, ms); byte[] bs = ms.ToArray(); string sha1 = ResLibTool.ComputeHashString(bs); name = sha1 + ".aniclip.bin"; bufs[name] = bs; } return(name); }
public string SaveMesh(Mesh mesh) { int id = mesh.GetInstanceID(); string name = null; if (savecache.TryGetValue(id, out name)) { return(name); } using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { BitHelper.WriteMesh(mesh, ms); byte[] bs = ms.ToArray(); string sha1 = ResLibTool.ComputeHashString(bs); name = sha1 + ".mesh.bin"; bufs[name] = bs; } savecache[id] = name; return(name); }