public static bool ExportTexture2D(AssetItem item, string exportPath, string format) { var converter = new Texture2DConverter((Texture2D)item.Asset); ImageFormat dstFormat = ImageFormat.Png; if (format == "recommanded" || format == "png") { format = "png"; dstFormat = ImageFormat.Png; } var oriPath = item.Asset.assetsFile.originalPath; var exportFullName = exportPath + Path.GetFileNameWithoutExtension(oriPath) + "." + format; if (format != "original") { var bitmap = converter.ConvertToBitmap(true); if (bitmap == null) { return(false); } bitmap.Save(exportFullName, dstFormat); bitmap.Dispose(); return(true); } else { File.WriteAllBytes(exportFullName, converter.ConvertToContainer()); return(true); } }
public static bool ExportTexture2D(AssetItem item, string exportPathName) { var m_Texture2D = new Texture2D(item.reader, true); if (m_Texture2D.image_data == null || m_Texture2D.image_data.Length == 0) { return(false); } var converter = new Texture2DConverter(m_Texture2D); var convertTexture = (bool)Properties.Settings.Default["convertTexture"]; if (convertTexture) { var bitmap = converter.ConvertToBitmap(true); if (bitmap == null) { return(false); } ImageFormat format = null; var ext = (string)Properties.Settings.Default["convertType"]; switch (ext) { case "BMP": format = ImageFormat.Bmp; break; case "PNG": format = ImageFormat.Png; break; case "JPEG": format = ImageFormat.Jpeg; break; } var exportFullName = exportPathName + item.Text + "." + ext.ToLower(); if (ExportFileExists(exportFullName)) { return(false); } bitmap.Save(exportFullName, format); bitmap.Dispose(); return(true); } else { var exportFullName = exportPathName + item.Text + converter.GetExtensionName(); if (ExportFileExists(exportFullName)) { return(false); } File.WriteAllBytes(exportFullName, converter.ConvertToContainer()); return(true); } }
private void RunDownload() { if (!Directory.Exists(txt_Save.Text + "Unity3D")) { Directory.CreateDirectory(txt_Save.Text + "Unity3D"); } List <DownloadInfo> list = new List <DownloadInfo>(); string Extension = (chb_Unity3d.Checked ? ".unity3d" : ""); string[] FileList = lib_File.Items.Cast <string>().ToArray(); string Url; if (rdb_ST.Checked) { Url = "http://img.wcproject.so-net.tw/assets/469/"; } else if (rdb_SJ.Checked) { Url = "http://i.wcat.colopl.jp/assets/2018/"; } else if (rdb_SK.Checked) { Url = "http://i-wcat-colopl-kr.akamaized.net/assets/465/"; } else if (rdb_tennis.Checked) { Url = "http://i-tennis-colopl-jp.akamaized.net/asset_bundle/"; } else { Url = txt_URL.Text; } if (rdb_tennis.Checked && RB_A.Checked) { Url += "android/0.0.1/"; } else if (rdb_tennis.Checked && RB_I.Checked) { Url += "ios/0.0.1/"; } else if (!rdb_Custom.Checked && RB_A.Checked) { Url += "a/"; } else if (!rdb_Custom.Checked && RB_I.Checked) { Url += "i/"; } SetProgressBarValue(0, PB_TotalFile); tbManager.SetProgressValue(0, FileList.Length); tbManager.SetProgressState(TaskbarProgressBarState.Normal); foreach (string fileName in FileList) { if (fileName == "" || fileName.Substring(0, 1) == "'" || !fileName.ComparisonFileName()) { DelListBox(fileName.ToString(), lib_File); } else { string urlAddress = Url + fileName + Extension + "?r=" + DateTime.Now.ToFileTime().ToString(); DownloadInfo info = new DownloadInfo(urlAddress, txt_Save.Text, this, fileName + ".unity3d"); list.Add(info); info.StartDownload(); } } list.ForEach(delegate(DownloadInfo item) { SetToolStripLabelText("下載中 (" + (PB_TotalFile.Value * 100.0 / list.Count).ToString("0.0") + "%)", lab_Status); while (!item.IsDone) { if (!isWorking) { if (item.WC != null) { item.WC.CancelAsync(); } break; } SetLabelText("下載檔案: " + item.FileName, lab_Download); SetLabelText(string.Format("{0} KB / {1} KB", item.KBytesReceived.ToString("0.0"), item.TotalKBytesToReceive.ToString("0.0")), lab_Speed); SetProgressBarValue(item.KBytesReceived, PB_SingleFile); SetProgressBarMaxValue(item.TotalKBytesToReceive, PB_SingleFile); Thread.Sleep(500); } if (item.IsCancelled) { AddListBoxItem(Path.GetFileNameWithoutExtension(item.FileName), lib_Error); } else if (item.Error != "") { AddListBoxItem(Path.GetFileNameWithoutExtension(item.FileName), lib_Error); } SetProgressBarValue(PB_TotalFile.Value + 1, PB_TotalFile); SetToolStripLabelText("錯誤檔案數: " + lib_Error.Items.Count.ToString(), lab_ErrorItem); SetToolStripLabelText("已下載數: " + PB_TotalFile.Value, lab_DownItem); DelListBox(Path.GetFileNameWithoutExtension(item.FileName), lib_File); tbManager.SetProgressValue(PB_TotalFile.Value, FileList.Length); }); list.Clear(); SetProgressBarValue(0, PB_SingleFile); SetProgressBarMaxValue(0, PB_SingleFile); SetLabelText("0 KB / 0 KB", lab_Speed); if (extFile.Count != 0) { SetToolStripLabelText("檔案數: " + extFile.Count, lab_Item); SetProgressBarValue(0, PB_TotalFile); SetProgressBarMaxValue(extFile.Count, PB_TotalFile); SetToolStripLabelText("載入資料中", lab_Status); assetsManager.LoadFolder(txt_Save.Text + "Unity3D"); SetToolStripLabelText("解包中", lab_Status); Parallel.ForEach(assetsManager.assetsFileList, (item) => { string fileName = Path.GetFileNameWithoutExtension(item.originalPath); if (!extFile.Contains(fileName + ".unity3d")) { return; } bool Export = true; if (TSM_UnPrefab.Checked && TSM_Exclude.Text != "") { foreach (string item2 in TSM_Exclude.Text.Split(new char[] { ',' })) { if (fileName.ToLower().Contains(item2.ToLower())) { Export = false; break; } } } if (Export) { SetToolStripLabelText("解包: " + fileName, lab_Execute); foreach (var item2 in item.m_Objects) { string SavePath = ""; ObjectReader OR = new ObjectReader(item.reader, item, item2); switch (OR.type) { case ClassIDType.Texture2D: SavePath = txt_Save.Text + "Texture\\"; if (File.Exists(SavePath + fileName + ".png")) { return; } if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } var m_Texture2D = new Texture2D(OR); var converter = new Texture2DConverter(m_Texture2D); var bitmap = converter.ConvertToBitmap(true); if (bitmap != null) { if (fileName.StartsWith("Card")) { if (!fileName.Contains("std") && !fileName.EndsWith("w_png") && (bitmap.Width == 1024 && bitmap.Height == 1024)) { bitmap = bitmap.ResizeImage(1024, 1331); } } else if (fileName.StartsWith("Location")) { if (bitmap.Width == 512 && bitmap.Height == 512) { bitmap = bitmap.ResizeImage(768, 512); } else if (bitmap.Width == 1024 && bitmap.Height == 1024) { bitmap = bitmap.ResizeImage(1536, 1024); } } else if (fileName.Contains("loginBonus_bg") && (bitmap.Width == 1024 && bitmap.Height == 1024)) { bitmap = bitmap.ResizeImage(1024, 1536); } bitmap.Save(SavePath + fileName + ".png", ImageFormat.Png); bitmap.Dispose(); } m_Texture2D = null; break; case ClassIDType.AudioClip: SavePath = txt_Save.Text + "Audio\\"; if (fileName.StartsWith("Sound_Voice")) { string[] path = fileName.Split(new char[] { '_' }); string finalPath = ""; for (int i = 0; i < path.Length - 2; i++) { finalPath += path[i] + "_"; } SavePath += finalPath.Remove(finalPath.Length - 1) + "\\"; } if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } AudioClip m_AudioClip = new AudioClip(OR); var audioClipConverter = new AudioClipConverter(m_AudioClip); if (audioClipConverter.IsFMODSupport) { byte[] m_AudioData = audioClipConverter.ConvertToWav(); File.WriteAllBytes(SavePath + fileName + ".wav", m_AudioData); } else { byte[] m_AudioData = m_AudioClip.m_AudioData.Value; File.WriteAllBytes(SavePath + fileName + audioClipConverter.GetExtensionName(), m_AudioData); } m_AudioClip = null; break; case ClassIDType.TextAsset: SavePath = txt_Save.Text + "Text\\"; if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } TextAsset TA = new TextAsset(OR); File.WriteAllBytes(SavePath + fileName + ".txt", TA.m_Script); TA = null; break; } } } else { string SavePath = txt_Save.Text + "Unity3D\\"; if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } SetToolStripLabelText("略過: " + fileName, lab_Execute); File.Move(item.originalPath, SavePath + fileName + ".unity3d"); } SetProgressBarValue(PB_TotalFile.Value + 1, PB_TotalFile); tbManager.SetProgressValue(PB_TotalFile.Value, extFile.Count); SetToolStripLabelText("已解包數: " + PB_TotalFile.Value, lab_DownItem); }); assetsManager.Clear(); extFile.Clear(); GC.Collect(); } SW.Stop(); timer1.Stop(); SetLabelText("下載檔案:無", lab_Download); SetToolStripLabelText("等待中", lab_Status); Work_Event(false); tbManager.SetProgressState(TaskbarProgressBarState.NoProgress); Invoke(new Action(delegate { Text = "清單檔案下載器 "; })); if (Program.autoClose) { Environment.Exit(1); } if (lib_Error.Items.Count <= 0) { SetButtonEnable(false, btn_Save_Error); } Environment.ExitCode = 1; MessageBox.Show("下載完成"); }
public static Bitmap GetCardArt(Card card) { var texture2DConverter = new Texture2DConverter(_loadedAssets[$"{card.CardArt}_AIF"]); return(texture2DConverter.ConvertToBitmap(true)); }
public static bool ExportTexture2D(AssetItem item, string exportPathName) { var converter = new Texture2DConverter((Texture2D)item.Asset); var convertTexture = (bool)Properties.Settings.Default["convertTexture"]; if (convertTexture) { var bitmap = converter.ConvertToBitmap(true); if (bitmap == null) { return(false); } ImageFormat format = null; var ext = (string)Properties.Settings.Default["convertType"]; bool tga = false; switch (ext) { case "BMP": format = ImageFormat.Bmp; break; case "PNG": format = ImageFormat.Png; break; case "JPEG": format = ImageFormat.Jpeg; break; case "TGA": tga = true; break; } var exportFullName = exportPathName + item.Text + "." + ext.ToLower(); if (ExportFileExists(exportFullName)) { return(false); } if (tga) { var file = new TGA(bitmap); file.Save(exportFullName); } else { bitmap.Save(exportFullName, format); } bitmap.Dispose(); return(true); } else { var exportFullName = exportPathName + item.Text + converter.GetExtensionName(); if (ExportFileExists(exportFullName)) { return(false); } File.WriteAllBytes(exportFullName, converter.ConvertToContainer()); return(true); } }