fix the probe launcher sound effects

This commit is contained in:
Mister_Nebula 2021-12-15 21:09:10 +00:00
parent 8b83b20caa
commit 5982de7e7d
7 changed files with 97 additions and 18 deletions

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.Audio
{
internal class QSBJetpackThrusterAudio : QSBThrusterAudio
{
public OWAudioSource _underwaterSource;
public OWAudioSource _oxygenSource;
public OWAudioSource _boostSource;
}
}

View File

@ -27,8 +27,17 @@ namespace QSB.Audio
private void Start()
{
DebugLog.DebugWrite($"START");
_oneShotExternalSource = CreateBaseAudio("OneShotAudio_PlayerExternal", false, 0, 1, AudioType.None, OWAudioMixer.TrackName.Player_External, false);
_repairToolSource = CreateBaseAudio("RepairToolAudio", true, 128, 0.5f, AudioType.None, OWAudioMixer.TrackName.Player_External, false);
_oneShotExternalSource = CreateBaseAudio(transform, "OneShotAudio_PlayerExternal", false, 0, 1, AudioType.None, OWAudioMixer.TrackName.Player_External, false);
_repairToolSource = CreateBaseAudio(transform, "RepairToolAudio", true, 128, 0.5f, AudioType.None, OWAudioMixer.TrackName.Player_External, false);
var thrusterAudio = new GameObject("REMOTE_ThrusterAudio").transform;
thrusterAudio.parent = transform;
var jetpatchThrusterAudio = thrusterAudio.gameObject.AddComponent<QSBJetpackThrusterAudio>();
jetpatchThrusterAudio._rotationalSource = CreateBaseAudio(thrusterAudio, "RotationalSource", false, 0, 1, AudioType.None, OWAudioMixer.TrackName.Player, false);
jetpatchThrusterAudio._translationalSource = CreateBaseAudio(thrusterAudio, "TranslationalSource", true, 0, 0.1f, AudioType.PlayerSuitJetpackThrustTranslational_LP, OWAudioMixer.TrackName.Player_External, false);
jetpatchThrusterAudio._underwaterSource = CreateBaseAudio(thrusterAudio, "UnderwaterSource", true, 0, 0.1f, AudioType.PlayerSuitJetpackThrustUnderwater_LP, OWAudioMixer.TrackName.Player_External, false);
jetpatchThrusterAudio._oxygenSource = CreateBaseAudio(thrusterAudio, "OxygenPropellantSource", true, 0, 0.2f, AudioType.PlayerSuitJetpackOxygenPropellant_LP, OWAudioMixer.TrackName.Player_External, false);
jetpatchThrusterAudio._boostSource = CreateBaseAudio(thrusterAudio, "BoosterSource", true, 0, 0.35f, AudioType.PlayerSuitJetpackBoost, OWAudioMixer.TrackName.Player_External, false);
}
public void PlayEquipTool()
@ -44,6 +53,7 @@ namespace QSB.Audio
=> _oneShotExternalSource.PlayOneShot(AudioType.ToolFlashlightOff, 1f);
private OWAudioSource CreateBaseAudio(
Transform parent,
string name,
bool loop,
int priority,
@ -54,7 +64,7 @@ namespace QSB.Audio
{
DebugLog.DebugWrite($"createBaseAudio {name}");
var go = new GameObject(name);
go.transform.parent = transform;
go.transform.parent = parent;
go.transform.localPosition = Vector3.zero;
go.transform.localScale = Vector3.one;

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.Audio
{
internal class QSBThrusterAudio : MonoBehaviour
{
public OWAudioSource _translationalSource;
public OWAudioSource _rotationalSource;
}
}

View File

@ -3,6 +3,7 @@ using QSB.Events;
using QSB.Patches;
using QSB.Player;
using QSB.Tools.ProbeLauncherTool.WorldObjects;
using QSB.Utility;
using QSB.WorldSync;
using UnityEngine;
@ -67,23 +68,31 @@ namespace QSB.Tools.ProbeLauncherTool.Patches
return false;
}
// BUG : This plays the sound to everyone
// TODO : ehhhh idk about this. maybe copy each sound source so we have a 2d version (for local) and a 3d version (for remote)?
// this would probably be a whole qsb version on it's own
[HarmonyPrefix]
[HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayRetrievalClip))]
public static bool ProbeLauncherEffects_PlayRetrievalClip(OWAudioSource ____owAudioSource)
public static bool ProbeLauncherEffects_PlayRetrievalClip(ProbeLauncherEffects __instance)
{
____owAudioSource.GetAudioSource().spatialBlend = 1f;
if (__instance._owAudioSource == null)
{
DebugLog.ToConsole($"Error - _owAudioSource of {__instance._owAudioSource}", OWML.Common.MessageType.Error);
return true;
}
__instance._owAudioSource.GetAudioSource().spatialBlend = 1f;
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayLaunchClip))]
public static bool ProbeLauncherEffects_PlayLaunchClip(OWAudioSource ____owAudioSource)
public static bool ProbeLauncherEffects_PlayLaunchClip(ProbeLauncherEffects __instance)
{
____owAudioSource.GetAudioSource().spatialBlend = 1f;
if (__instance._owAudioSource == null)
{
DebugLog.ToConsole($"Error - _owAudioSource of {__instance._owAudioSource}", OWML.Common.MessageType.Error);
return true;
}
__instance._owAudioSource.GetAudioSource().spatialBlend = 1f;
return true;
}
}

View File

@ -6,6 +6,6 @@ namespace QSB.Tools.ProbeLauncherTool
internal class ProbeLauncherManager : WorldObjectManager
{
protected override void RebuildWorldObjects(OWScene scene)
=> QSBWorldSync.Init<QSBProbeLauncher, ProbeLauncher>();
=> QSBWorldSync.Init<QSBProbeLauncher, ProbeLauncher>(typeof(PlayerProbeLauncher));
}
}

View File

@ -1,4 +1,5 @@
using UnityEngine;
using QSB.Utility;
using UnityEngine;
namespace QSB.Tools.ProbeLauncherTool
{
@ -10,6 +11,13 @@ namespace QSB.Tools.ProbeLauncherTool
public void RetrieveProbe(bool playEffects)
{
DebugLog.DebugWrite($"{Player.PlayerId} retrieveProbe");
if (Effects._owAudioSource == null)
{
Effects._owAudioSource = Player.AudioController._repairToolSource;
}
PreLaunchProbeProxy.SetActive(true);
if (playEffects)
{
@ -20,11 +28,16 @@ namespace QSB.Tools.ProbeLauncherTool
public void LaunchProbe()
{
DebugLog.DebugWrite($"{Player.PlayerId} launchProbe");
PreLaunchProbeProxy.SetActive(false);
if (Effects._owAudioSource == null)
{
Effects._owAudioSource = Player.AudioController._repairToolSource;
}
// TODO : make this do underwater stuff correctly
Effects.PlayLaunchClip(false);
// BUG : this plays particles on everyone's launcher...
Effects.PlayLaunchParticles(false);
}
}

View File

@ -109,17 +109,33 @@ namespace QSB.WorldSync
where TUnityObject : MonoBehaviour
{
var list = GetUnityObjects<TUnityObject>().ToList();
//DebugLog.DebugWrite($"{typeof(TWorldObject).Name} init : {list.Count} instances.", MessageType.Info);
for (var id = 0; id < list.Count; id++)
Init<TWorldObject, TUnityObject>(list);
}
public static void Init<TWorldObject, TUnityObject>(params Type[] typesToExclude)
where TWorldObject : WorldObject<TUnityObject>, new()
where TUnityObject : MonoBehaviour
{
var list = GetUnityObjects<TUnityObject>().Where(x => !typesToExclude.Contains(x.GetType()));
Init<TWorldObject, TUnityObject>(list);
}
private static void Init<TWorldObject, TUnityObject>(IEnumerable<TUnityObject> listToInitFrom)
where TWorldObject : WorldObject<TUnityObject>, new()
where TUnityObject : MonoBehaviour
{
//DebugLog.DebugWrite($"{typeof(TWorldObject).Name} init : {listToInitFrom.Count()} instances.", MessageType.Info);
foreach (var item in listToInitFrom)
{
var obj = new TWorldObject
{
AttachedObject = list[id],
AttachedObject = item,
ObjectId = WorldObjects.Count
};
obj.Init();
WorldObjects.Add(obj);
WorldObjectsToUnityObjects.Add(list[id], obj);
WorldObjectsToUnityObjects.Add(item, obj);
}
}