Skip to content

Commit

Permalink
add more conversion methods
Browse files Browse the repository at this point in the history
add WavLib to PostBuildEvent
  • Loading branch information
SFGrenade committed Jun 11, 2023
1 parent a2eb250 commit 6d32869
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions SFCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
<MakeDir Directories="$(ExportDir)/$(TargetName)/zip/" />
<MakeDir Condition="!Exists('$(HollowKnightRefs)/Mods/$(TargetName)/')" Directories="$(HollowKnightRefs)/Mods/$(TargetName)/" />

<Copy Condition="'$(DocumentationFile)'!=''" SourceFiles="$(TargetPath);$(TargetDir)/$(TargetName).pdb;$(TargetDir)/$(TargetName).xml" DestinationFolder="$(HollowKnightRefs)/Mods/$(TargetName)/" />
<Copy Condition="'$(DocumentationFile)'==''" SourceFiles="$(TargetPath);$(TargetDir)/$(TargetName).pdb" DestinationFolder="$(HollowKnightRefs)/Mods/$(TargetName)/" />
<Copy Condition="'$(DocumentationFile)'!=''" SourceFiles="$(TargetPath);$(TargetDir)/$(TargetName).pdb;$(TargetDir)/$(TargetName).xml;$(TargetDir)/WavLib.dll" DestinationFolder="$(HollowKnightRefs)/Mods/$(TargetName)/" />
<Copy Condition="'$(DocumentationFile)'==''" SourceFiles="$(TargetPath);$(TargetDir)/$(TargetName).pdb;$(TargetDir)/WavLib.dll" DestinationFolder="$(HollowKnightRefs)/Mods/$(TargetName)/" />

<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(ExportDir)/$(TargetName)/" />

<Copy Condition="'$(DocumentationFile)'!=''" SourceFiles="ReadMe.md;$(TargetPath);$(TargetDir)/$(TargetName).pdb;$(TargetDir)/$(TargetName).xml" DestinationFolder="$(ExportDir)/$(TargetName)/zip/" />
<Copy Condition="'$(DocumentationFile)'==''" SourceFiles="ReadMe.md;$(TargetPath);$(TargetDir)/$(TargetName).pdb" DestinationFolder="$(ExportDir)/$(TargetName)/zip/" />
<Copy Condition="'$(DocumentationFile)'!=''" SourceFiles="ReadMe.md;$(TargetPath);$(TargetDir)/$(TargetName).pdb;$(TargetDir)/$(TargetName).xml;$(TargetDir)/WavLib.dll" DestinationFolder="$(ExportDir)/$(TargetName)/zip/" />
<Copy Condition="'$(DocumentationFile)'==''" SourceFiles="ReadMe.md;$(TargetPath);$(TargetDir)/$(TargetName).pdb;$(TargetDir)/WavLib.dll" DestinationFolder="$(ExportDir)/$(TargetName)/zip/" />

<ZipDirectory SourceDirectory="$(ExportDir)/$(TargetName)/zip/" DestinationFile="$(ExportDir)/$(TargetName)/$(TargetName).zip" />
<RemoveDir Directories="$(ExportDir)/$(TargetName)/zip/" />
Expand Down
21 changes: 21 additions & 0 deletions Util/WavUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,25 @@ public static AudioClip ToAudioClip(Stream dataStream, string origName = "")
audioClip.SetData(wavSoundData, 0);
return audioClip;
}

/// <summary>
/// Converts audio data from a file into an AudioClip using WavLib.
/// </summary>
/// <returns>The AudioClip.</returns>
/// <param name="filePath">The wav file</param>
public static AudioClip ToAudioClip(string filePath)
{
return ToAudioClip(File.Open(filePath, FileMode.Open), Path.GetFileNameWithoutExtension(filePath));
}

/// <summary>
/// Converts audio data from a byte array into an AudioClip using WavLib.
/// </summary>
/// <returns>The AudioClip.</returns>
/// <param name="wavData">The wav data</param>
public static AudioClip ToAudioClip(byte[] wavData, string origName = "")
{
MemoryStream memoryStream = new MemoryStream(wavData, false);
return ToAudioClip(memoryStream, origName);
}
}

0 comments on commit 6d32869

Please sign in to comment.