// Use this for initialization void Start() { audioRecorder = GetComponent <AudioRecorder>(); dataStorageHandler = new DataStorageHandler <RecordingData>(); audioClipConverter = new AudioClipConverter(); }
public static bool ExportAudioClip(AssetItem item, string exportPath) { var m_AudioClip = (AudioClip)item.Asset; var m_AudioData = m_AudioClip.m_AudioData.GetData(); if (m_AudioData == null || m_AudioData.Length == 0) { return(false); } var converter = new AudioClipConverter(m_AudioClip); if (Properties.Settings.Default.convertAudio && converter.IsSupport) { if (!TryExportFile(exportPath, item, ".wav", out var exportFullPath)) { return(false); } var buffer = converter.ConvertToWav(); if (buffer == null) { return(false); } File.WriteAllBytes(exportFullPath, buffer); } else { if (!TryExportFile(exportPath, item, converter.GetExtensionName(), out var exportFullPath)) { return(false); } File.WriteAllBytes(exportFullPath, m_AudioData); } return(true); }
public static bool ExportAudioClip(AssetItem item, string exportPath, string format) { var m_AudioClip = (AudioClip)item.Asset; var m_AudioData = m_AudioClip.m_AudioData.Value; if (m_AudioData == null || m_AudioData.Length == 0) { return(false); } var converter = new AudioClipConverter(m_AudioClip); if (format == "recommanded" || format == "wav") { format = "wav"; } var oriPath = item.Asset.assetsFile.originalPath; var exportFullName = exportPath + Path.GetFileNameWithoutExtension(oriPath) + "." + format; if (format == "wav" && converter.IsFMODSupport) { var buffer = converter.ConvertToWav(); if (buffer == null) { return(false); } File.WriteAllBytes(exportFullName, buffer); } else { File.WriteAllBytes(exportFullName, m_AudioData); } return(true); }
public void SaveRecording() { if (dataStorageHandler == null) { dataStorageHandler = new DataStorageHandler <RecordingData>(); } if (audioClipConverter == null) { audioClipConverter = new AudioClipConverter(); } RecordingData data = audioClipConverter.ConvertAudioClipToData(audioRecorder.GetRecording()); dataStorageHandler.SaveData(data, recordingFileName); }
public void LoadRecording() { if (dataStorageHandler == null) { dataStorageHandler = new DataStorageHandler <RecordingData>(); } if (audioClipConverter == null) { audioClipConverter = new AudioClipConverter(); } RecordingData data = dataStorageHandler.LoadData(recordingFileName); AudioClip clip = audioClipConverter.ConvertDataToAudioClip(data); audioRecorder.SetRecording(clip); }
public static bool ExportAudioClip(AssetItem item, string exportPath) { var m_AudioClip = (AudioClip)item.Asset; var m_AudioData = m_AudioClip.m_AudioData.Value; if (m_AudioData == null || m_AudioData.Length == 0) { return(false); } var convertAudio = (bool)Properties.Settings.Default["convertAudio"]; var converter = new AudioClipConverter(m_AudioClip); if (convertAudio && converter.IsFMODSupport) { var exportFullName = exportPath + item.Text + ".wav"; if (ExportFileExists(exportFullName)) { return(false); } var buffer = converter.ConvertToWav(); if (buffer == null) { return(false); } File.WriteAllBytes(exportFullName, buffer); } else { var exportFullName = exportPath + item.Text + converter.GetExtensionName(); if (ExportFileExists(exportFullName)) { return(false); } File.WriteAllBytes(exportFullName, m_AudioData); } return(true); }
private void diagramXmlParseBody_(XmlNode diagramElementNode, string xmlFilePath, TreeNode treeNode, int objectIndex) { string diagramElementName = diagramElementNode.Name; AlternateContent altContent = treeNode.Presentation.AlternateContentFactory.CreateAlternateContent(); AlternateContentAddCommand cmd_AltContent = treeNode.Presentation.CommandFactory.CreateAlternateContentAddCommand(treeNode, altContent); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent); Metadata diagramElementName_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata(); diagramElementName_Metadata.NameContentAttribute = new MetadataAttribute(); diagramElementName_Metadata.NameContentAttribute.Name = DiagramContentModelHelper.DiagramElementName; diagramElementName_Metadata.NameContentAttribute.NamespaceUri = null; diagramElementName_Metadata.NameContentAttribute.Value = diagramElementName; AlternateContentMetadataAddCommand cmd_AltContent_diagramElementName_Metadata = treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand( treeNode, null, altContent, diagramElementName_Metadata, null ); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElementName_Metadata); if (diagramElementNode.Attributes != null) { for (int i = 0; i < diagramElementNode.Attributes.Count; i++) { XmlAttribute attribute = diagramElementNode.Attributes[i]; if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":")) { // } else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS) { // } else if (attribute.Name == DiagramContentModelHelper.TOBI_Audio) { string fullPath = null; if (FileDataProvider.isHTTPFile(attribute.Value)) { fullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(attribute.Value); } else { fullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), attribute.Value); } if (fullPath != null && File.Exists(fullPath)) { string extension = Path.GetExtension(fullPath); bool isWav = extension.Equals(DataProviderFactory.AUDIO_WAV_EXTENSION, StringComparison.OrdinalIgnoreCase); AudioLibPCMFormat wavFormat = null; if (isWav) { Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read); try { uint dataLength; wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength); } finally { fileStream.Close(); } } string originalFilePath = null; DebugFix.Assert(treeNode.Presentation.MediaDataManager.EnforceSinglePCMFormat); bool wavNeedsConversion = false; if (wavFormat != null) { wavNeedsConversion = !wavFormat.IsCompatibleWith(treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data); } if (!isWav || wavNeedsConversion) { originalFilePath = fullPath; var audioFormatConvertorSession = new AudioFormatConvertorSession( //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY, treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath, treeNode.Presentation.MediaDataManager.DefaultPCMFormat, false, m_UrakawaSession.IsAcmCodecsDisabled); //filePath = m_AudioFormatConvertorSession.ConvertAudioFileFormat(filePath); bool cancelled = false; var converter = new AudioClipConverter(audioFormatConvertorSession, fullPath); bool error = ShellView.RunModalCancellableProgressTask(true, "Converting audio...", converter, () => { m_Logger.Log(@"Audio conversion CANCELLED", Category.Debug, Priority.Medium); cancelled = true; }, () => { m_Logger.Log(@"Audio conversion DONE", Category.Debug, Priority.Medium); cancelled = false; }); if (cancelled) { //DebugFix.Assert(!result); break; } fullPath = converter.ConvertedFilePath; if (string.IsNullOrEmpty(fullPath)) { break; } m_Logger.Log(string.Format("Converted audio {0} to {1}", originalFilePath, fullPath), Category.Debug, Priority.Medium); //Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read); //try //{ // uint dataLength; // wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength); //} //finally //{ // fileStream.Close(); //} } ManagedAudioMedia manAudioMedia = treeNode.Presentation.MediaFactory.CreateManagedAudioMedia(); AudioMediaData audioMediaData = treeNode.Presentation.MediaDataFactory.CreateAudioMediaData(DataProviderFactory.AUDIO_WAV_EXTENSION); manAudioMedia.AudioMediaData = audioMediaData; FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); dataProv.InitByCopyingExistingFile(fullPath); audioMediaData.AppendPcmData(dataProv); // Stream wavStream = null; // try // { // wavStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read); // uint dataLength; // AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength); // if (!treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data.IsCompatibleWith(pcmInfo)) // { //#if DEBUG // Debugger.Break(); //#endif //DEBUG // wavStream.Close(); // wavStream = null; // var audioFormatConvertorSession = // new AudioFormatConvertorSession( // //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY, // treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath, // treeNode.Presentation.MediaDataManager.DefaultPCMFormat, m_UrakawaSession.IsAcmCodecsDisabled); // string newfullWavPath = audioFormatConvertorSession.ConvertAudioFileFormat(fullPath); // FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); // dataProv.InitByMovingExistingFile(newfullWavPath); // audioMediaData.AppendPcmData(dataProv); // } // else // use original wav file by copying it to data directory // { // FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); // dataProv.InitByCopyingExistingFile(fullPath); // audioMediaData.AppendPcmData(dataProv); // } // } // finally // { // if (wavStream != null) wavStream.Close(); // } AlternateContentSetManagedMediaCommand cmd_AltContent_diagramElement_Audio = treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode, altContent, manAudioMedia); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElement_Audio); //SetDescriptionAudio(altContent, audio, treeNode); } } else { Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata(); diagramElementAttribute_Metadata.NameContentAttribute = new MetadataAttribute(); diagramElementAttribute_Metadata.NameContentAttribute.Name = attribute.Name; diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI; diagramElementAttribute_Metadata.NameContentAttribute.Value = attribute.Value; AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata = treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand( treeNode, null, altContent, diagramElementAttribute_Metadata, null ); treeNode.Presentation.UndoRedoManager.Execute( cmd_AltContent_diagramElementAttribute_Metadata); } } } int nObjects = -1; XmlNode textNode = diagramElementNode; if (diagramElementName == DiagramContentModelHelper.D_SimplifiedImage || diagramElementName == DiagramContentModelHelper.D_Tactile) { string localTourName = DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Tour); XmlNode tour = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(diagramElementNode, false, localTourName, DiagramContentModelHelper.NS_URL_DIAGRAM); textNode = tour; IEnumerable <XmlNode> objects = XmlDocumentHelper.GetChildrenElementsOrSelfWithName(diagramElementNode, false, DiagramContentModelHelper. Object, DiagramContentModelHelper. NS_URL_ZAI, false); nObjects = 0; foreach (XmlNode obj in objects) { nObjects++; } int i = -1; foreach (XmlNode obj in objects) { i++; if (i != objectIndex) { continue; } if (obj.Attributes == null || obj.Attributes.Count <= 0) { break; } for (int j = 0; j < obj.Attributes.Count; j++) { XmlAttribute attribute = obj.Attributes[j]; if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":")) { // } else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS) { // } else if (attribute.Name == DiagramContentModelHelper.Src) { // } else if (attribute.Name == DiagramContentModelHelper.SrcType) { // } else { Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata(); diagramElementAttribute_Metadata.NameContentAttribute = new MetadataAttribute(); diagramElementAttribute_Metadata.NameContentAttribute.Name = attribute.Name; diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI; diagramElementAttribute_Metadata.NameContentAttribute.Value = attribute.Value; AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata = treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand( treeNode, null, altContent, diagramElementAttribute_Metadata, null ); treeNode.Presentation.UndoRedoManager.Execute( cmd_AltContent_diagramElementAttribute_Metadata); } } XmlAttribute srcAttr = (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.Src); if (srcAttr != null) { XmlAttribute srcType = (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.SrcType); ManagedImageMedia img = treeNode.Presentation.MediaFactory.CreateManagedImageMedia(); string imgFullPath = null; if (FileDataProvider.isHTTPFile(srcAttr.Value)) { imgFullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(srcAttr.Value); } else { imgFullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), srcAttr.Value); } if (imgFullPath != null && File.Exists(imgFullPath)) { string extension = Path.GetExtension(imgFullPath); ImageMediaData imgData = treeNode.Presentation.MediaDataFactory.CreateImageMediaData(extension); if (imgData != null) { imgData.InitializeImage(imgFullPath, Path.GetFileName(imgFullPath)); img.ImageMediaData = imgData; AlternateContentSetManagedMediaCommand cmd_AltContent_Image = treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand( treeNode, altContent, img); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Image); } } } } } if (textNode != null) { string strText = textNode.InnerXml; if (!string.IsNullOrEmpty(strText)) { strText = strText.Trim(); strText = Regex.Replace(strText, @"\s+", " "); strText = strText.Replace("\r\n", "\n"); } if (!string.IsNullOrEmpty(strText)) { TextMedia txtMedia = treeNode.Presentation.MediaFactory.CreateTextMedia(); txtMedia.Text = strText; AlternateContentSetManagedMediaCommand cmd_AltContent_Text = treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode, altContent, txtMedia); treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Text); } } if (nObjects > 0 && ++objectIndex <= nObjects - 1) { diagramXmlParseBody_(diagramElementNode, xmlFilePath, treeNode, objectIndex); } }
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("下載完成"); }