public static IEnumerator SaveTexture(Texture2D _tex, string _name) { float ratio = ( float )_tex.width / _tex.height; int width = 0, height = 0; // 如果比例大于阈值,则使用Fix width方案 // 反之使用Fix Height方案 if (ratio > FIX_HEIGHT_THRESHOLD) { width = FIX_WIDTH; height = Mathf.RoundToInt(width / ratio); } else { height = FIX_HEIGHT; width = Mathf.RoundToInt(height * ratio); // 如果使用Fix Height方案后,宽度还是超标 // 则再转位Fix Width方案 if (width > FIX_WIDTH) { width = FIX_WIDTH; height = Mathf.RoundToInt(width / ratio); } } Debug.Log("Saved Texture Sizes: " + width + ", " + height); _tex = TextureScaler.ResizeTexture(_tex, width, height); byte[] bytes = _tex.EncodeToPNG(); string path = TGPaths.FullScreenshotPath(_name); Debug.Log("截图路径: " + path); // 写入文件 LMFileWriter.Write(path, bytes); // 写到Dicionary里,好之后写入ret.txt TGData.SaveScreenshot(_name); yield return(null); }
private static void OutputConfigs(SceneData _sceneData, string _targetFolder) { CopyConfigToPath(FRAMEWORK_ROOT, _targetFolder, TGConfigs.MAIN_CONFIG_FILENAME); string srcConfigFolder = FRAMEWORK_ROOT + "Configs/"; string dstConfigFolder = _targetFolder + "Configs/"; Directory.CreateDirectory(dstConfigFolder); string[] outputConfigs = new string[] { TGConfigs.EVAL_SETTING_FILENAME, TGConfigs.KEY_INPUT_CONFIG_FILENAME }; foreach (var c in outputConfigs) { CopyConfigToPath(srcConfigFolder, dstConfigFolder, c); } // 制作Json为读取表 LMFileWriter.Write(dstConfigFolder + TGConfigs.SCENE_SETTING_FILENAME, JsonUtility.ToJson(_sceneData, true)); }