/// <summary>サウンドの再生を停止する</summary> /// <param name="channelId">停止するチャンネルID</param> public static void Stop(int channelId) { var channel = ChannelAllocator.GetChannel(channelId); channel.audioSrc.Stop(); channel.used = false; }
/// <summary>指定座標でサウンドを再生する</summary> /// <param name="key">サウンドのキー</param> /// <param name="position">再生する座標</param> /// <param name="loop">ループするか</param> /// <param name="spatialBlend">3Dブレンド(0f~1f)</param> /// <returns>チャンネルID</returns> public static int PlayAtPoint(string key, Vector3 position, bool loop = false, float spatialBlend = 1f) { if (!ChannelAllocator.initialized) { ChannelAllocator.Initialize(); } if (!_updater) { _updater = new GameObject("Updater@TFSound"); GameObject.DontDestroyOnLoad(_updater); _updater.AddComponent <Updater>(); } var channel = ChannelAllocator.Allocate(); if (channel != null) { channel.audioSrc.clip = _audioDict[key]; channel.audioSrc.Play(); channel.audioSrc.loop = loop; channel.audioSrc.spatialBlend = spatialBlend; channel.channelObject.transform.position = position; channel.target = null; return(channel.id); } return(-1); }
/// <summary>サウンドを再生する</summary> /// <param name="prop">オーディオプロパティ</param> /// <param name="trackingTarget">追跡ターゲット(オプション)</param> /// <returns>チャンネルID</returns> public static int Play(AudioProperty prop, Transform trackingTarget = null) { if (!ChannelAllocator.initialized) { ChannelAllocator.Initialize(); } if (!_updater) { _updater = new GameObject("Updater@TFSound"); GameObject.DontDestroyOnLoad(_updater); _updater.AddComponent <Updater>(); } var channel = ChannelAllocator.Allocate(); if (channel != null) { channel.audioSrc.clip = prop._clip; channel.audioSrc.Play(); channel.audioSrc.loop = prop._loop; channel.audioSrc.spatialBlend = prop._spatialBlend; channel.audioSrc.volume = prop._volume; channel.target = trackingTarget; return(channel.id); } return(-1); }
public void OverflowTest() { ChannelAllocator allocator = new ChannelAllocator(); List <SingleBeat> test = new List <SingleBeat>( Enumerable.Range(0, 20).Select(i => new SingleBeat(InstrumentType.AccousticGrandPiano + i, 64, 64, i * 0.1, (i * 0.1) + 3))); Assert.Throws <OutOfChannelsException>(() => allocator.Add(test)); }
public void ChannelRotation() { ChannelAllocator allocator = new ChannelAllocator(); List <SingleBeat> test = new List <SingleBeat>( Enumerable.Range(0, 20).Select(i => new SingleBeat(InstrumentType.AccousticGrandPiano + i, 64, 64, i * 2, (i * 2) + 1))); Assert.DoesNotThrow(() => allocator.Add(test)); }
/// <summary>全てのサウンドの再生を停止する</summary> public static void StopAll() { var channels = ChannelAllocator.GetChannels(); for (int f1 = 0; f1 < channels.Length; f1++) { channels[f1].audioSrc.Stop(); channels[f1].used = false; } }
public void SauritateTest() { ChannelAllocator allocator = new ChannelAllocator(); List <SingleBeat> test = new List <SingleBeat>( Enumerable.Range(0, 99).Select(i => new SingleBeat(InstrumentType.AccousticGrandPiano + (i % 15), 64, 64, i * 0.1, (i * 0.1) + 1.5))); Assert.DoesNotThrow(() => allocator.Add(test)); List <SimpleMidiMessage> list = new List <SimpleMidiMessage>(new AsEnumerable(allocator)); CollectionAssert.IsOrdered(list, new Comp()); }
public void ChannelRotationReuse() { ChannelAllocator allocator = new ChannelAllocator(); List <SingleBeat> test = new List <SingleBeat>( Enumerable.Range(0, 20).Select(i => new SingleBeat(InstrumentType.AccousticGrandPiano + i, 64, 64, i * 2, (i * 2) + 1))); List <SingleBeat> test2 = new List <SingleBeat>( Enumerable.Range(0, 20).Select(i => new SingleBeat(InstrumentType.AccousticGrandPiano + i, 64, 64, (i * 2) + 45, (i * 2) + 46))); Assert.DoesNotThrow(() => allocator.Add(test)); Assert.DoesNotThrow(() => allocator.Add(test2)); List <SimpleMidiMessage> list = new List <SimpleMidiMessage>(new AsEnumerable(allocator)); CollectionAssert.IsOrdered(list, new Comp()); }
public AsEnumerable(ChannelAllocator inner) { _inner = inner; }
void Update() { ChannelAllocator.Update(); }