/// <summary> /// Initialize from a blob /// </summary> /// <param name="blob"></param> /// <param name="platform"></param> public NamedSounds(Span <byte> blob, DataPlatform platform) { FullBuffer = new Memory <byte>(blob.ToArray()); Header = MemoryMarshal.Read <NamedSoundHeader>(blob); Logger.Assert(Header.Count == 1, "Header.Count == 1"); var offset = SizeHelper.SizeOf <NamedSoundHeader>(); Filenames = new List <string?>(Header.Count); for (var i = 0; i < Header.Count; ++i) { var pointer = MemoryMarshal.Read <int>(blob.Slice(offset)); Filenames.Add(blob.Slice(pointer).ReadString()); offset += 4; } offset = Header.PointersTablePointer; for (var i = 0; i < Header.Count; ++i) { var name = blob.Slice(offset).ReadStringNonNull(); offset += name.Length + 1; Filenames.Add(name); } var pointers = MemoryMarshal.Cast <byte, int>(blob.Slice(Header.PointersTablePointer, 4 * Header.Count)); foreach (var pointer in pointers) { Sections.Add(SoundResource.DecodeSection(blob.Slice(pointer), platform)); } }
private static BuildTarget GetBuildTarget(DataPlatform platform) { BuildTarget target; switch (platform) { case DataPlatform.Android: target = BuildTarget.Android; break; case DataPlatform.IOS: target = BuildTarget.iOS; break; case DataPlatform.Editor: target = BuildTarget.StandaloneWindows64; break; case DataPlatform.WebGL: target = BuildTarget.WebGL; break; default: target = BuildTarget.StandaloneWindows64; break; } return(target); }
/// <summary> /// Decodes KTSR Section /// </summary> /// <param name="buffer"></param> /// <param name="platform"></param> /// <returns></returns> public static ISoundResourceSection DecodeSection(Span <byte> buffer, DataPlatform platform) { var header = MemoryMarshal.Read <SoundResourceEntry>(buffer); var sectionData = buffer.Slice(0, header.Size); return(header.SectionType switch { SoundResourceSectionType.SoundSample => new OGGSound(sectionData), SoundResourceSectionType.ADPCMSound => new NamedSounds(sectionData, platform), SoundResourceSectionType.GCADPCMSound when platform == DataPlatform.Switch => new GCADPCMSound(sectionData), SoundResourceSectionType.GCADPCMSound when platform == DataPlatform.Windows => new MSADPCMSound(sectionData), _ => new UnknownSound(sectionData) });
public static void Build(string assetName, DataPlatform platform) { var target = GetBuildTarget(platform); var outputPath = Config.BUNDLE_FOLDER_PATH + Enum.GetName(typeof(DataPlatform), platform); var buildMap = new AssetBundleBuild[1]; var resourcesAssets = new string[1]; //此资源包下面有多少文件 resourcesAssets[0] = Config.ASSET_FOLDER_PATH + assetName + ".asset"; buildMap[0].assetBundleName = assetName; buildMap[0].assetNames = resourcesAssets; BuildPipeline.BuildAssetBundles(outputPath, buildMap, BuildAssetBundleOptions.ForceRebuildAssetBundle, target); Debug.Log("wocao"); }
/// <summary> /// Initialize a KTSR from a Span buffer /// </summary> /// <param name="buffer"></param> /// <param name="platform"></param> public SoundResource(Span <byte> buffer, DataPlatform platform) { Platform = platform; Header = MemoryMarshal.Read <SoundResourceHeader>(buffer); var offset = SizeHelper.SizeOf <SoundResourceHeader>().Align(0x40); Logger.Assert(Header.Size == Header.CompressedSize, "Header.Size == Header.CompressedSize"); while (offset < Header.Size) { var section = DecodeSection(buffer.Slice(offset), platform); Entries.Add(section); offset += section.Base.Size; } }
/// <summary> /// Initialize a KTSR from a Stream /// </summary> /// <param name="stream"></param> /// <param name="platform"></param> public SoundResource(Stream stream, DataPlatform platform) : this(stream.ToSpan(), platform) { }