示例#1
0
 private bool Converter(string srcPath, string dstPath)
 {
     using (var stream = new FileStream(srcPath, FileMode.Open)) {
         // All sounds below 100kb size (can be changed with cooking rules) are converted
         // from OGG to Wav/Adpcm
         var rules = AssetCooker.CookingRulesMap[srcPath];
         if (stream.Length > rules.ADPCMLimit * 1024)
         {
             AssetCooker.AssetBundle.ImportFile(dstPath, stream, 0, oggExtension, File.GetLastWriteTime(srcPath),
                                                AssetAttributes.None, AssetCooker.CookingRulesMap[srcPath].SHA1);
         }
         else
         {
             Console.WriteLine("Converting sound to ADPCM/IMA4 format...");
             using (var input = new OggDecoder(stream)) {
                 using (var output = new MemoryStream()) {
                     WaveIMA4Converter.Encode(input, output);
                     output.Seek(0, SeekOrigin.Begin);
                     AssetCooker.AssetBundle.ImportFile(dstPath, output, 0, oggExtension, File.GetLastWriteTime(srcPath),
                                                        AssetAttributes.None, AssetCooker.CookingRulesMap[srcPath].SHA1);
                 }
             }
         }
         return(true);
     }
 }
示例#2
0
        private static void SyncSounds()
        {
            const string sourceExtension = ".ogg";

            if (Platform == TargetPlatform.Unity)
            {
                SyncRawAssets(sourceExtension);
                return;
            }
            SyncUpdated(sourceExtension, ".sound", (srcPath, dstPath) => {
                using (var stream = new FileStream(srcPath, FileMode.Open)) {
                    // All sounds below 100kb size (can be changed with cooking rules) are converted
                    // from OGG to Wav/Adpcm
                    var rules = cookingRulesMap[srcPath];
                    if (stream.Length > rules.ADPCMLimit * 1024)
                    {
                        AssetBundle.ImportFile(dstPath, stream, 0, sourceExtension, AssetAttributes.None, cookingRulesMap[srcPath].SHA1);
                    }
                    else
                    {
                        Console.WriteLine("Converting sound to ADPCM/IMA4 format...");
                        using (var input = new OggDecoder(stream)) {
                            using (var output = new MemoryStream()) {
                                WaveIMA4Converter.Encode(input, output);
                                output.Seek(0, SeekOrigin.Begin);
                                AssetBundle.ImportFile(dstPath, output, 0, sourceExtension, AssetAttributes.None, cookingRulesMap[srcPath].SHA1);
                            }
                        }
                    }
                    return(true);
                }
            });
        }