we poppin
This commit is contained in:
1 parent
336945533b
commit
9f6e615653
88 files changed
+979
-170
No files matched your search
+49
-101
@@ -13,11 +13,11 @@ public enum Sound {
|
||||
Decelerate,
|
||||
Strafe,
|
||||
|
||||
Damage,
|
||||
Respawn,
|
||||
Damage, // noise pop
|
||||
Respawn, // noise pop
|
||||
|
||||
BoostAcceleration,
|
||||
BoostDeceleration,
|
||||
BoostAccelerate,
|
||||
BoostDecelerate,
|
||||
BoostStrafe,
|
||||
BoostShield,
|
||||
|
||||
@@ -30,55 +30,64 @@ public enum Sound {
|
||||
public class ShipAudio : MonoBehaviour {
|
||||
// Match these two up
|
||||
[SerializeField]
|
||||
Sound[] soundNames;
|
||||
Sound[] powerUnitSounds;
|
||||
|
||||
[SerializeField]
|
||||
AudioClip[] clips;
|
||||
AudioClip[] powerUnitClips;
|
||||
|
||||
[SerializeField]
|
||||
AudioClip[] noiseClips;
|
||||
[SerializeField]
|
||||
AudioClip[] bigNoiseClips;
|
||||
|
||||
Dictionary<Sound, AudioClip> sounds = new();
|
||||
|
||||
AudioSource srcAccel;
|
||||
AudioSource srcDecel;
|
||||
AudioSource srcStrafe;
|
||||
AudioSource srcShipAccel;
|
||||
AudioSource srcShipDecel;
|
||||
AudioSource srcShipStrafe;
|
||||
|
||||
AudioSource src;
|
||||
|
||||
SpaceRaceInput input;
|
||||
ShipControls ship;
|
||||
|
||||
void Awake() {
|
||||
for (int i = 0; i < clips.Length; i++) {
|
||||
sounds.Add(soundNames[i], clips[i]);
|
||||
for (int i = 0; i < powerUnitClips.Length; i++) {
|
||||
sounds.Add(powerUnitSounds[i], powerUnitClips[i]);
|
||||
}
|
||||
|
||||
ship = GetComponentInParent<ShipControls>();
|
||||
|
||||
srcAccel = gameObject.AddComponent<AudioSource>();
|
||||
srcAccel.clip = sounds[Sound.Accelerate];
|
||||
srcAccel.loop = true;
|
||||
srcAccel.volume = 0f;
|
||||
srcAccel.Play();
|
||||
src = gameObject.AddComponent<AudioSource>();
|
||||
|
||||
srcDecel = gameObject.AddComponent<AudioSource>();
|
||||
srcDecel.clip = sounds[Sound.Decelerate];
|
||||
srcDecel.loop = true;
|
||||
srcDecel.volume = 0f;
|
||||
srcDecel.Play();
|
||||
srcShipAccel = gameObject.AddComponent<AudioSource>();
|
||||
srcShipAccel.clip = sounds[Sound.Accelerate];
|
||||
srcShipAccel.loop = true;
|
||||
srcShipAccel.volume = 0f;
|
||||
srcShipAccel.Play();
|
||||
|
||||
srcStrafe = gameObject.AddComponent<AudioSource>();
|
||||
srcStrafe.clip = sounds[Sound.Strafe];
|
||||
srcStrafe.loop = true;
|
||||
srcStrafe.volume = 0f;
|
||||
srcStrafe.Play();
|
||||
srcShipDecel = gameObject.AddComponent<AudioSource>();
|
||||
srcShipDecel.clip = sounds[Sound.Decelerate];
|
||||
srcShipDecel.loop = true;
|
||||
srcShipDecel.volume = 0f;
|
||||
srcShipDecel.Play();
|
||||
|
||||
srcShipStrafe = gameObject.AddComponent<AudioSource>();
|
||||
srcShipStrafe.clip = sounds[Sound.Strafe];
|
||||
srcShipStrafe.loop = true;
|
||||
srcShipStrafe.volume = 0f;
|
||||
srcShipStrafe.Play();
|
||||
|
||||
RegisterEvents();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
srcAccel.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
|
||||
srcDecel.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
|
||||
srcStrafe.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
|
||||
srcShipAccel.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
|
||||
srcShipDecel.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
|
||||
srcShipStrafe.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
|
||||
|
||||
// Super fucking annoying
|
||||
// stops all the clicks and pops of starting / stopping the clips
|
||||
// stops all the clicks and pops of starting / stopping the powerUnitClips
|
||||
// 0.125s to get max volume
|
||||
// == 8x per second...
|
||||
float volumeDelta = Time.deltaTime * 8;
|
||||
@@ -89,96 +98,35 @@ public class ShipAudio : MonoBehaviour {
|
||||
bool strafing = input.ship.strafe.ReadValue<Vector2>().magnitude > 0;
|
||||
|
||||
if (accelerating) {
|
||||
srcAccel.volume = Math.Min(1f, srcAccel.volume + volumeDelta);
|
||||
srcShipAccel.volume = Math.Min(1f, srcShipAccel.volume + volumeDelta);
|
||||
} else {
|
||||
srcAccel.volume = Math.Max(0f, srcAccel.volume - decelDelta);
|
||||
srcShipAccel.volume = Math.Max(0f, srcShipAccel.volume - decelDelta);
|
||||
}
|
||||
|
||||
if (decelerating) {
|
||||
srcDecel.volume = Math.Min(1f, srcDecel.volume + volumeDelta);
|
||||
srcShipDecel.volume = Math.Min(1f, srcShipDecel.volume + volumeDelta);
|
||||
} else {
|
||||
srcDecel.volume = Math.Max(0f, srcDecel.volume - decelDelta);
|
||||
srcShipDecel.volume = Math.Max(0f, srcShipDecel.volume - decelDelta);
|
||||
}
|
||||
|
||||
if (strafing) {
|
||||
srcStrafe.volume = Math.Min(1f, srcStrafe.volume + volumeDelta);
|
||||
srcShipStrafe.volume = Math.Min(1f, srcShipStrafe.volume + volumeDelta);
|
||||
} else {
|
||||
srcStrafe.volume = Math.Max(0f, srcStrafe.volume - decelDelta);
|
||||
srcShipStrafe.volume = Math.Max(0f, srcShipStrafe.volume - decelDelta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public void PlaySound(Sound s) {
|
||||
// AudioSource src = sounds[s];
|
||||
// src.Play(0);
|
||||
// }
|
||||
public void PlayNoise() {
|
||||
int noiseIndex = UnityEngine.Random.Range(0, noiseClips.Length);
|
||||
src.PlayOneShot(noiseClips[noiseIndex]);
|
||||
}
|
||||
|
||||
void RegisterEvents() {
|
||||
if (input == null)
|
||||
input = new SpaceRaceInput();
|
||||
|
||||
input.ship.Enable();
|
||||
|
||||
// input.ship.accelerate.started += OnAccelerateStart;
|
||||
// input.ship.accelerate.canceled += OnAccelerateCancel;
|
||||
// input.ship.decelerate.started += OnDecelerateStart;
|
||||
// input.ship.decelerate.canceled += OnDecelerateCancel;
|
||||
// input.ship.strafe.started += OnStrafeStart;
|
||||
// input.ship.strafe.canceled += OnStrafeCancel;
|
||||
|
||||
// these we only care about the initial press
|
||||
// input.ship.respawn.started += OnRespawn;
|
||||
// input.ship.quit.started += OnQuit;
|
||||
// input.ship.powerUnit1.started += OnPowerUnit1;
|
||||
// input.ship.powerUnit2.started += OnPowerUnit2;
|
||||
// input.ship.powerUnit3.started += OnPowerUnit3;
|
||||
// input.ship.powerUnit4.started += OnPowerUnit4;
|
||||
}
|
||||
|
||||
// void OnDestroy() {
|
||||
// input.ship.accelerate.started -= OnAccelerateStart;
|
||||
// input.ship.accelerate.canceled -= OnAccelerateCancel;
|
||||
// input.ship.decelerate.started -= OnDecelerateStart;
|
||||
// input.ship.decelerate.canceled -= OnDecelerateCancel;
|
||||
// input.ship.strafe.started -= OnStrafeStart;
|
||||
// input.ship.strafe.canceled -= OnStrafeCancel;
|
||||
|
||||
|
||||
// // these we only care about the initial press
|
||||
// input.ship.respawn.started -= OnRespawn;
|
||||
// input.ship.quit.started -= OnQuit;
|
||||
// input.ship.powerUnit1.started -= OnPowerUnit1;
|
||||
// input.ship.powerUnit2.started -= OnPowerUnit2;
|
||||
// input.ship.powerUnit3.started -= OnPowerUnit3;
|
||||
// input.ship.powerUnit4.started -= OnPowerUnit4;
|
||||
// }
|
||||
|
||||
// void OnAcceleratePerformed(InputAction.CallbackContext _ctx) {
|
||||
// Debug.Log(_ctx.duration);
|
||||
// }
|
||||
|
||||
// void OnAccelerateStart(InputAction.CallbackContext _ctx) {
|
||||
// srcAccel.Play();
|
||||
// }
|
||||
|
||||
// void OnAccelerateCancel(InputAction.CallbackContext _ctx) {
|
||||
// srcAccel.Stop();
|
||||
// }
|
||||
|
||||
// void OnDecelerateStart(InputAction.CallbackContext _ctx) {
|
||||
// srcDecel.Play();
|
||||
// }
|
||||
|
||||
// void OnDecelerateCancel(InputAction.CallbackContext _ctx) {
|
||||
// srcDecel.Stop();
|
||||
// }
|
||||
|
||||
// void OnStrafeStart(InputAction.CallbackContext _ctx) {
|
||||
// srcStrafe.Play();
|
||||
// }
|
||||
|
||||
// void OnStrafeCancel(InputAction.CallbackContext _ctx) {
|
||||
// srcStrafe.Stop();
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user