public override void Play(IUTKAudioSource audioSource, bool loop = false) { if (this.onPlay != null) { this.onPlay(audioSource, loop); } }
/// <summary> /// Plays <see cref="clip"/> /// </summary> public override void Play(IUTKAudioSource audioSource, bool loop = false) { audioSource.clipVolume = this.volume.GetRandomInRange(); audioSource.clipPitch = this.pitch.GetRandomInRange(); audioSource.minDistance = this.minDistance; audioSource.maxDistance = this.maxDistance; audioSource.rolloffMode = this.rolloffMode; audioSource.Play(this.clip, loop); }
public void TestOneShotPlayer() { // Arrange var wsPrefab = new GameObject("WSPrefab"); var proxPrefab = new GameObject("ProxPrefab"); var nsPrefab = new GameObject("NSPrefab"); GameObject testGo = new GameObject("TEST"); var wsPrefabAS = wsPrefab.AddComponent <UTKAudioSource>(); var proxPrefabAS = proxPrefab.AddComponent <ProximityBasedAudio>(); var nsPrefabAS = nsPrefab.AddComponent <NonSpatialAudioSource>(); var audioOneShotPlayer = new GameObject("OSPlayer"); var aosp = audioOneShotPlayer.AddComponent <AudioOneShotPlayer>(); aosp.Awake(); AudioOneShotPlayer.instance.worldspacePrefab = wsPrefabAS; AudioOneShotPlayer.instance.proximityBasedPrefab = proxPrefabAS; AudioOneShotPlayer.instance.nonSpatialPrefab = nsPrefabAS; var proximityPlayer = new GameObject("Proximity Player"); proximityPlayer.AddComponent <ProximityPlayer>(); AudioEventMock evtMock = new AudioEventMock(); bool wasPlayed = false; IUTKAudioSource playedSource = null; bool wasLooped = false; evtMock.onPlay += (source, loop) => { wasLooped = loop; wasPlayed = true; playedSource = source; }; // Act AudioOneShotPlayer.instance.PlayNonSpatial(evtMock); Assert.IsTrue(wasPlayed); Assert.IsFalse(wasLooped); Assert.AreNotEqual(null, playedSource); Assert.AreEqual(typeof(NonSpatialAudioSource), playedSource.GetType()); // Reset and act again wasPlayed = wasLooped = false; playedSource = null; AudioOneShotPlayer.instance.PlayWorldspace(evtMock, testGo); Assert.IsTrue(wasPlayed); Assert.IsFalse(wasLooped); Assert.AreNotEqual(null, playedSource); Assert.AreEqual(testGo.transform, ((UTKAudioSource)playedSource).transform.parent); Assert.AreEqual(typeof(UTKAudioSource), playedSource.GetType()); // Reset and act again wasPlayed = wasLooped = false; playedSource = null; AudioOneShotPlayer.instance.PlayProximity(evtMock, testGo); Assert.IsTrue(wasPlayed); Assert.IsFalse(wasLooped); Assert.AreNotEqual(null, playedSource); Assert.AreEqual(testGo.transform, ((ProximityBasedAudio)playedSource).transform.parent); Assert.AreEqual(typeof(ProximityBasedAudio), playedSource.GetType()); // Reset and act again wasPlayed = wasLooped = false; playedSource = null; }
/// <summary> /// Will play one event randomly selected from <see cref="events"/> /// <see cref="AudioEvent.Play(IUTKAudioSource, bool)"/> /// </summary> public override void Play(IUTKAudioSource audioSource, bool loop = false) { this.events.RandomItem().Play(audioSource, loop); }
/// <summary> /// Plays <see cref="clip"/> /// </summary> public override void Play(IUTKAudioSource source, bool loop = false) { source.Play(this.clip, loop); }
/// <summary> /// Called when this audio event is being fired. /// Plays the event on the specified audio source. /// </summary> /// <param name="audioSource">The audio source to play the event on.</param> /// <param name="loop">Whether or not starting to play this sound in a loop, if it is being looped it will play until you call <see cref="IUTKAudioSource.Stop"/> on your audio source!</param> public abstract void Play(IUTKAudioSource audioSource, bool loop = false);