Add pitch variations (#874)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
|
using Content.Shared.Audio;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
@@ -16,17 +17,24 @@ namespace Content.Server.GameObjects.Components.Sound
|
|||||||
public override string Name => "EmitSoundOnUse";
|
public override string Name => "EmitSoundOnUse";
|
||||||
|
|
||||||
public string _soundName;
|
public string _soundName;
|
||||||
|
public float _pitchVariation;
|
||||||
|
|
||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
serializer.DataField(ref _soundName, "sound", "");
|
serializer.DataField(ref _soundName, "sound", string.Empty);
|
||||||
|
serializer.DataField(ref _pitchVariation, "variation", 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(_soundName))
|
if (!string.IsNullOrWhiteSpace(_soundName))
|
||||||
{
|
{
|
||||||
|
if (_pitchVariation > 0.0)
|
||||||
|
{
|
||||||
|
Owner.GetComponent<SoundComponent>().Play(_soundName, AudioHelpers.WithVariation(_pitchVariation).WithVolume(-2f));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Owner.GetComponent<SoundComponent>().Play(_soundName, AudioParams.Default.WithVolume(-2f));
|
Owner.GetComponent<SoundComponent>().Play(_soundName, AudioParams.Default.WithVolume(-2f));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
22
Content.Shared/Audio/AudioHelpers.cs
Normal file
22
Content.Shared/Audio/AudioHelpers.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Shared.GameObjects.Components.Sound;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Random;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Log;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
namespace Content.Shared.Audio
|
||||||
|
{
|
||||||
|
public static class AudioHelpers{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a random pitch.
|
||||||
|
/// </summary>
|
||||||
|
public static AudioParams WithVariation(float amplitude)
|
||||||
|
{
|
||||||
|
var scale = (float)(IoCManager.Resolve<IRobustRandom>().NextGaussian(1, amplitude));
|
||||||
|
return AudioParams.Default.WithPitchScale(scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
- type: Sound
|
- type: Sound
|
||||||
- type: EmitSoundOnUse
|
- type: EmitSoundOnUse
|
||||||
sound: /Audio/items/bikehorn.ogg
|
sound: /Audio/items/bikehorn.ogg
|
||||||
|
variation: 0.2
|
||||||
|
|
||||||
- type: UseDelay
|
- type: UseDelay
|
||||||
delay: 0.5
|
delay: 0.5
|
||||||
|
|||||||
Reference in New Issue
Block a user