コード例 #1
0
        public static string CreateSoundAsset(string soundFilePath, bool keepAssetId = false)
        {
            var soundFileExtension = Path.GetExtension(soundFilePath);

            if (!IsSupportedSoundFileFormat(soundFileExtension))
            {
                throw new ArgumentException($"Sound file format {soundFileExtension} is not supported.", nameof(soundFilePath));
            }

            var directoryPath = Path.GetDirectoryName(soundFilePath) ??
                                throw new ArgumentException("The path does not point to any file.", nameof(soundFilePath));

            var soundAssetFileName = AssetFileUtils.AppendExtension(Path.GetFileNameWithoutExtension(soundFilePath));
            var soundAssetFilePath = Path.Combine(directoryPath, soundAssetFileName);

            var soundAssetContent = new SoundAssetContent
            {
                SoundFilePath = Path.GetFileName(soundFilePath)
            };

            var assetId   = GetAssetId(keepAssetId, soundAssetFilePath);
            var assetData = AssetData.CreateWithJsonContent(assetId, AudioAssetTypes.Sound, soundAssetContent);

            assetData.Save(soundAssetFilePath);

            return(soundAssetFilePath);
        }
コード例 #2
0
        public void SetUp()
        {
            _audioBackend = Substitute.For <IAudioBackend>();
            _fileSystem   = Substitute.For <IFileSystem>();
            _assetStore   = Substitute.For <IAssetStore>();

            const string      soundFilePath = "sound.wav";
            const SoundFormat soundFormat   = SoundFormat.Wav;

            const string assetFilePath     = "sound-asset-path";
            var          soundAssetContent = new SoundAssetContent
            {
                SoundFilePath = soundFilePath
            };

            _assetInfo = new AssetInfo(AssetId.CreateUnique(), AudioAssetTypes.Sound, assetFilePath);
            var assetData    = AssetData.CreateWithJsonContent(_assetInfo.AssetId, _assetInfo.AssetType, soundAssetContent);
            var memoryStream = new MemoryStream();

            assetData.Save(memoryStream);
            memoryStream.Position = 0;

            var assetFile = Substitute.For <IFile>();

            assetFile.OpenRead().Returns(memoryStream);
            _fileSystem.GetFile(assetFilePath).Returns(assetFile);

            var soundFile = Substitute.For <IFile>();
            var stream    = Substitute.For <Stream>();

            soundFile.OpenRead().Returns(stream);
            _fileSystem.GetFile(soundFilePath).Returns(soundFile);

            _sound = Substitute.For <ISound>();
            _audioBackend.CreateSound(stream, soundFormat).Returns(_sound);

            _soundAssetLoader = new SoundAssetLoader(_audioBackend, _fileSystem);
        }