/// <summary> /// 对ins进行GZip压缩,输出到outs /// </summary> /// <param name="inStream"></param> /// <param name="outStream"></param> /// <returns></returns> public static void GZipCompress(Stream inStream, Stream outStream) { var gzipStream = new GZipStream(outStream, CompressionMode.Compress, true); StdioUtil.CopyStream(inStream, gzipStream); gzipStream.Close(); }
/// <summary> /// 对ins解压,输出到outs /// </summary> /// <param name="inStream"></param> /// <param name="outStream"></param> /// <returns></returns> public static void Decompress(Stream inStream, Stream outStream) { var iis = new InflaterInputStream(inStream); StdioUtil.CopyStream(iis, outStream); iis.Close(); }
//将对象序列化到文件 public static void SerializeToFilePath <T>(T t, string file_path) where T : Google.Protobuf.IMessage { using (File.Create(file_path)) { StdioUtil.WriteFile(new FileInfo(file_path), Serialize(t)); } }
public static T CreateAsset <T>(string path, Action <T> onCreateCallback = null) where T : ScriptableObject { var asset = ScriptableObject.CreateInstance <T>(); path = path.WithoutRootPath(FilePathConst.ProjectPath); var dir = path.DirPath(); if (!dir.IsNullOrEmpty()) { StdioUtil.CreateDirectoryIfNotExist(dir); } var fileExtensionName = Path.GetExtension(path); if (!StringConst.String_Asset_Extension.Equals(fileExtensionName)) { path = path.Replace(fileExtensionName, StringConst.String_Asset_Extension); } onCreateCallback?.Invoke(asset); EditorUtility.SetDirty(asset); AssetDatabase.CreateAsset(asset, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return(asset); }
public void LoadFromPath(string path) { if (File.Exists(path)) { Load(StdioUtil.ReadTextFile(path)); } }
public static void AssetBundleClearPC() { LogCat.ClearLogs(); StdioUtil.ClearDir(FilePathConst.PersistentAssetBundleRoot); EditorUtilityCat.DisplayDialog("AssetBundle PC_Persistent Clear Finished", FilePathConst.PersistentAssetBundleRoot); }
public static void Test2() { int[][] grids = new AStarMapPath(StdioUtil.ReadTextFile("E:/WorkSpace/Unity/Test/Assets/tile/tileSet/fff.txt")) .grids; LogCat.log(grids); }
public static void Build() { AssetPathRefManager.instance.Save(); StdioUtil.WriteTextFile(BuildConst.Output_Path + AssetPathRefConst.SaveFileName, StdioUtil.ReadTextFile(AssetPathRefConst.SaveFilePath)); AssetDatabase.Refresh(); }
/// <summary> /// 对ins进行GZip解压,输出到outs /// </summary> /// <param name="inStream"></param> /// <param name="outStream"></param> /// <returns></returns> public static void GZipDecompress(Stream inStream, Stream outStream) { var inGZipStream = new GZipStream(inStream, CompressionMode.Decompress, true); StdioUtil.CopyStream(inGZipStream, outStream); inGZipStream.Close(); }
public virtual void Save() { var content = JsonSerializer.Serialize(this); var contentBytes = Encoding.UTF8.GetBytes(content); //contentBytes = CompressUtil.GZipCompress(contentBytes);//压缩 StdioUtil.WriteFile(SerializeDataConst.SaveFilePathCS, contentBytes); }
/// <summary> /// 对data从offset开始,长度为len进行GZip解压,输出到outs /// </summary> /// <param name="data"></param> /// <param name="offset"></param> /// <param name="length"></param> /// <param name="outStream"></param> /// <returns></returns> public static void GZipDecompress(byte[] data, int offset, int length, Stream outStream) { var inGZipStream = new GZipStream(new ByteInputStream(data, offset, length), CompressionMode.Decompress, true); StdioUtil.CopyStream(inGZipStream, outStream); inGZipStream.Close(); }
private void UpdateResFinish() { StdioUtil.WriteTextFile(BuildConst.ResVersionFileName.WithRootPath(FilePathConst.PersistentAssetBundleRoot), serverBuildInfo.resVersion); clientBuildInfo.Dispose(); serverBuildInfo.Dispose(); isUpdateFinish = true; Debug.LogWarning("Update Resource Finish"); }
private static void WriteLogFile(string content) { if (content.IsNullOrWhiteSpace()) { return; } string day = DateTimeUtil.GetDateTime("date", DateTimeUtil.NowTicks()); string filePath = LogCatConst.LogBasePath + day + ".txt"; StdioUtil.WriteTextFile(filePath, content, false, true); }
public static void Build() { string filePath = BuildConst.ResVersionFilePath.WithRootPath(FilePathConst.ProjectPath); StdioUtil.CreateFileIfNotExist(filePath); string resVersion = StdioUtil.ReadTextFile(filePath); resVersion = resVersion.IsNullOrWhiteSpace() ? BuildConst.ResVersionDefault : IncreaseResSubVersion(resVersion); StdioUtil.WriteTextFile(filePath, resVersion); StdioUtil.WriteTextFile(BuildConst.Output_Path + BuildConst.ResVersionFileName, resVersion); AssetDatabase.Refresh(); }
/// <summary> /// 对ins进行level级别压缩,输出到outs /// </summary> /// <param name="inStream"></param> /// <param name="level"></param> /// <param name="outStream"></param> /// <returns></returns> public static void Compress(Stream inStream, int level, Stream outStream) { var deflater = new Deflater(); if (level >= 0 && level <= 9) { deflater.SetLevel(level); } var deflaterOutputStream = new DeflaterOutputStream(outStream, deflater, 4 * 1024); StdioUtil.CopyStream(inStream, deflaterOutputStream); deflaterOutputStream.Finish(); }
public void Save() { refIdHashtable.Clear(); Hashtable dict = new Hashtable(); dict["child_list"] = GetSave_ChildList(this.transform); string content = MiniJson.JsonEncode(dict); string filePath = textAsset.GetAssetPath().WithRootPath(FilePathConst.ProjectPath); StdioUtil.WriteTextFile(filePath, content); AssetPathRefManager.instance.Save(); AssetDatabase.Refresh(); LogCat.log("保存完成"); }
/// <summary> /// 保存 /// </summary> public void Save() { if (dataDict != null) { string path = CsvConst.BasePath + (this.filePath.Contains(".csv") ? filePath : string.Format("{0}.csv", this.filePath)); List <string> columnNameList = GetColumnNames(); string columnName = ""; for (var i = 0; i < columnNameList.Count; i++) { string column = columnNameList[i]; if (keyColumnNameList.Contains(column)) { columnName += column + "(key)" + ","; } else { columnName += column + ","; } } columnName = columnName.Substring(0, columnName.Length - 1); //去掉最后一个逗号 StdioUtil.WriteTextFile(path, columnName, true); foreach (LinkedDictionary <string, string> lineDataDict in dataDict.Values) { string rowValue = ""; for (var i = 0; i < columnNameList.Count; i++) { string column = columnNameList[i]; if (lineDataDict.ContainsKey(column)) { rowValue += lineDataDict[column] + ","; } else { rowValue += ","; } } rowValue = rowValue.Substring(0, rowValue.Length - 1); //去掉最后一个逗号 StdioUtil.WriteTextFile(path, rowValue, true, true); } LogCat.LogWarning("Save Finish"); } }
public static T Load(ref bool isNewCreate) { T data; if (!File.Exists(SerializeDataConst.SaveFilePathCS)) { data = new T(); isNewCreate = true; } else { var conentBytes = StdioUtil.ReadFile(SerializeDataConst.SaveFilePathCS); //conentBytes = CompressUtil.GZipDecompress(conentBytes);--解压缩 var content = Encoding.UTF8.GetString(conentBytes); data = JsonSerializer.Deserialize(content) as T; } data.AddDataList(); return(data); }
public static void AssetBundleBuild() { LogCat.ClearLogs(); //AssetBuildInfoManagerTest.Test();//需要自动设置依赖的,请在AssetBuildInfoManagerTest中添加Root文件,然后取消注释 StdioUtil.CreateDirectoryIfNotExist(BuildConst.Output_Path); LuaBuildUtil.PreBuild(); AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(BuildConst.Output_Path, BuildAssetBundleOptions.None, BuildTarget.Android); AssetPathMapBuildUtil.Build(manifest); AssetBundleMapBuildUtil.Build(manifest); ResVersionBuildUtil.Build(); AssetPathRefBuildUtil.Build(); var netBoxPath = (BuildConst.Output_Root_Path + "/NetBox.exe").Replace("/", "\\"); Process.Start(netBoxPath); EditorUtilityCat.DisplayDialog( string.Format("AssetBundle Build Finished,output:\n {0}", BuildConst.Output_Path), BuildConst.Output_Path); }
public void SingleInit() { var fileInfo = new FileInfo(filePath); if (!fileInfo.Exists) { var org_data = new Hashtable() { { "user_id", "user1" }, { "dict_user_tmp", new Hashtable() }, { "dict_user", new Hashtable() } }; data = org_data; return; } var conentBytes = StdioUtil.ReadFile(filePath); //conentBytes = CompressUtil.GZipDecompress(conentBytes);--½âѹËõ var content = Encoding.UTF8.GetString(conentBytes); data = MiniJson.JsonDecode(content) as Hashtable; }
public static void Build(AssetBundleManifest manifest) { Dictionary <string, long> dict = new Dictionary <string, long>(); string[] allAssetBundleNames = manifest.GetAllAssetBundles(); foreach (var assetBundleName in allAssetBundleNames) { FileInfo fileInfo = new FileInfo(BuildConst.Output_Path + assetBundleName); dict[assetBundleName] = fileInfo.Length; } List <string> contentList = new List <string>(); foreach (var assetBundleName in dict.Keys) { contentList.Add(string.Format("{0},{1}", assetBundleName, dict[assetBundleName])); } string fileOutputPath = BuildConst.AssetBundleMap_File_Name.WithRootPath(BuildConst.Output_Path); StdioUtil.WriteTextFile(new FileInfo(fileOutputPath), contentList, false); }
public static void Build(AssetBundleManifest manifest) { List <string> contentList = new List <string>(); string[] allAssetBundleNames = manifest.GetAllAssetBundles(); foreach (var assetBundleName in allAssetBundleNames) { //寻找项目中assetBundle_name为assetBundle_name的asset的路径,以Asset/开头 string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); foreach (string assetPath in assetPaths) { string content = string.Format("{0}{1}{2}", assetBundleName, StringConst.String_Comma, assetPath); contentList.Add(content); } } contentList.Sort(); string fileOutputPath = BuildConst.AssetPathMap_File_Name.WithRootPath(BuildConst.Output_Path); StdioUtil.WriteTextFile(new FileInfo(fileOutputPath), contentList, false); }
private void SaveUser() { User user = Client.instance.user; Hashtable dictUser = new Hashtable(); Hashtable dictUserTmp = new Hashtable(); user.DoSave(dictUser, dictUserTmp); string userId = user.GetId(); Hashtable saveData = new Hashtable(); saveData["dict_user"] = dictUser; saveData["dict_user_tmp"] = dictUserTmp; saveData["user_id"] = userId; var content = MiniJson.JsonEncode(saveData); var contentBytes = Encoding.UTF8.GetBytes(content); //contentBytes = CompressUtil.GZipCompress(contentBytes);//ѹËõ StdioUtil.WriteFile(filePath, contentBytes); }
public void Save() { Refresh(); Hashtable jsonDict = new Hashtable(); jsonDict["ref_id"] = refId; ArrayList assetPathRefList = new ArrayList(); foreach (var keyValue in dict) { var assetPathRef = keyValue.Value; Hashtable assetPathRefDict = new Hashtable(); assetPathRefDict["ref_id"] = assetPathRef.refId; assetPathRefDict["assetPath"] = assetPathRef.assetPath; assetPathRefDict["guid"] = assetPathRef.guid; assetPathRefList.Add(assetPathRefDict); } jsonDict["assetPathRef_list"] = assetPathRefList; string contentJson = MiniJson.JsonEncode(jsonDict); StdioUtil.WriteTextFile(AssetPathRefConst.SaveFilePath.WithRootPath(FilePathConst.ProjectPath), contentJson); }
public static string ExportUIText() { var filePath = FilePathConst.ProjectPath + "py_tools/lang/excel/ui_string.xlsx"; var checkPath = "Assets/Resources/"; //检测的路径 var allAssetPaths = AssetDatabase.GetAllAssetPaths(); var allStringList = new List <string>(); foreach (var path in allAssetPaths) { if (!path.StartsWith(checkPath)) { continue; } if (!path.EndsWith(".prefab")) { continue; } var obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); var uiLangs = obj.GetComponentsInChildren <UILang>(true); foreach (var uiLang in uiLangs) { var langId = uiLang.langId; if (IsAllExcludeChars(langId)) { continue; } allStringList.Add(langId); } } allStringList.Unique(); //去重 StdioUtil.RemoveFiles(filePath); WriteToExcel(filePath, allStringList); LogCat.log("UI上的Text已经输出到", filePath); return(filePath); }
private void OnResourceWebRequesterDone(ResourceWebRequester resourceWebRequester) { // LogCat.LogError("kkkkkkkkkkkkkkk:"+resourceWebRequester.url); if (!downloadingRequestList.Contains(resourceWebRequester)) { return; } if (!resourceWebRequester.error.IsNullOrWhiteSpace()) { LogCat.LogError("Error when downloading file : " + resourceWebRequester.cache.Get <string>("file_path") + "\n from url : " + resourceWebRequester.url + "\n err : " + resourceWebRequester.error); needDownloadList.Add(resourceWebRequester.cache.Get <string>("file_path")); } else { downloadingRequestList.Remove(resourceWebRequester); needDownloadDict[resourceWebRequester.cache.Get <string>("file_path")]["is_finished"] = true; needDownloadDict[resourceWebRequester.cache.Get <string>("file_path")]["downloded_bytes"] = needDownloadDict[resourceWebRequester.cache.Get <string>("file_path")]["total_bytes"]; var filePath = resourceWebRequester.cache.Get <string>("file_path") .WithRootPath(FilePathConst.PersistentAssetBundleRoot); StdioUtil.WriteFile(filePath, resourceWebRequester.bytes); } resourceWebRequester.Destroy(); PoolCatManagerUtil.Despawn(resourceWebRequester); // LogCat.LogError("ffffffffffffaaaaaaa:"+downloadingRequest.Count); // LogCat.LogError("ffffffffffffbbbbbbb:" + needDownloadList.Count); if (downloadingRequestList.Count == 0 && needDownloadList.Count == 0) { isUpdatingRes = false; } }
public IEnumerator CheckUpdate() { if (Application.isEditor && EditorModeConst.IsEditorMode) { isUpdateFinish = true; yield break; } downloadingRequestList.Clear(); clientBuildInfo = new BuildInfo(FilePathConst.PersistentAssetBundleRoot); serverBuildInfo = new BuildInfo(URLSetting.Server_Resource_URL); // LogCat.LogWarning("fffffffffffffff1:"+ FilePathConst.GetPersistentAssetBundleRoot()); // LogCat.LogWarning("fffffffffffffff2:"+ URLSetting.SERVER_RESOURCE_URL); //Update AssetPathRefContentJson yield return(clientBuildInfo.LoadAssetPathRefContentJson()); yield return(serverBuildInfo.LoadAssetPathRefContentJson()); if (!ObjectUtil.Equals(clientBuildInfo.assetPathRefContentJson, serverBuildInfo.assetPathRefContentJson)) { StdioUtil.WriteTextFile(clientBuildInfo.WithRootPathOfUrlRoot(AssetPathRefConst.SaveFileName).Trim(), serverBuildInfo.assetPathRefContentJson); } AssetPathRefManager.instance.Load(serverBuildInfo.assetPathRefContentJson); //Update ResVersion yield return(clientBuildInfo.LoadResVersion()); yield return(serverBuildInfo.LoadResVersion()); if (!BuildUtil.CheckResVersionIsNew(clientBuildInfo.resVersion, serverBuildInfo.resVersion)) { UpdateResFinish(); yield break; } //Update Mainfest yield return(clientBuildInfo.LoadManifest()); yield return(serverBuildInfo.LoadManifest()); yield return(serverBuildInfo.LoadAssetBundleMap()); needDownloadList.Clear(); needDownloadList = BuildUtil.GetManifestDiffAssetBundleList(clientBuildInfo.manifest, serverBuildInfo.manifest); if (!needDownloadList.IsNullOrEmpty()) { for (var i = 0; i < needDownloadList.Count; i++) { var assetBundleName = needDownloadList[i]; needDownloadDict[assetBundleName] = new Hashtable(); needDownloadDict[assetBundleName]["is_finished"] = false; needDownloadDict[assetBundleName]["total_bytes"] = serverBuildInfo.assetBundleMap.dict[assetBundleName]; needDownloadDict[assetBundleName]["downloded_bytes"] = (long)0; totalNeedDownloadBytes += serverBuildInfo.assetBundleMap.dict[assetBundleName]; } yield return(serverBuildInfo.LoadAssetPathMap()); yield return(UpdateRes()); serverBuildInfo.manifest.SaveToDisk(); serverBuildInfo.assetPathMap.SaveToDisk(); serverBuildInfo.assetBundleMap.SaveToDisk(); } UpdateResFinish(); }
public static void AssetBundleClearServer() { LogCat.ClearLogs(); StdioUtil.ClearDir(BuildConst.Output_Path); EditorUtilityCat.DisplayDialog("AssetBundle Server Clear Finished", BuildConst.Output_Path); }
//将文件数据转化为对象 public static T DeserializeFromFilePath <T>(string file_path) where T : Google.Protobuf.IMessage, new() { byte[] data_bytes = StdioUtil.ReadFile(file_path); return(Deserialize <T>(data_bytes)); }
public void SaveToDisk() { var path = BuildConst.AssetBundleMap_File_Name.WithRootPath(FilePathConst.PersistentAssetBundleRoot); StdioUtil.WriteTextFile(path, fileContent); }