diff --git a/QSB/Audio/PlayerAudioManager.cs b/QSB/Audio/PlayerAudioManager.cs new file mode 100644 index 00000000..29dd39c9 --- /dev/null +++ b/QSB/Audio/PlayerAudioManager.cs @@ -0,0 +1,24 @@ +using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace QSB.Audio +{ + internal class PlayerAudioManager + { + public static QSBPlayerAudioController InitRemote(Transform playerBody) + { + DebugLog.DebugWrite($"InitRemote {playerBody.name}"); + var REMOTE_Audio_Player = new GameObject("REMOTE_Audio_Player"); + REMOTE_Audio_Player.transform.parent = playerBody; + REMOTE_Audio_Player.transform.localPosition = Vector3.zero; + REMOTE_Audio_Player.transform.localScale = Vector3.one; + + return REMOTE_Audio_Player.AddComponent(); + } + } +} diff --git a/QSB/Audio/QSBPlayerAudioController.cs b/QSB/Audio/QSBPlayerAudioController.cs new file mode 100644 index 00000000..99de4ed0 --- /dev/null +++ b/QSB/Audio/QSBPlayerAudioController.cs @@ -0,0 +1,75 @@ +using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace QSB.Audio +{ + public class QSBPlayerAudioController : MonoBehaviour + { + //public OWAudioSource _oneShotSource; + public OWAudioSource _oneShotExternalSource; + //public OWAudioSource _mapTrackSource; + public OWAudioSource _repairToolSource; + //public OWAudioSource _translatorSource; + //public OWAudioSource _damageAudioSource; + //public OWAudioSource _damageAudioSourceExternal; + //public OWAudioSource _notificationAudio; + //public OWAudioSource _fluidVolumeSource; + //public OWAudioSource _forceVolumeAudio; + //public OWAudioSource _oxygenLeakSource; + //public OWAudioSource _recorderLoopSource; + //public NomaiTextRevealAudioController[] _nomaiTextAudioControllers; + + 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); + } + + public void PlayEquipTool() + => _oneShotExternalSource.PlayOneShot(AudioType.ToolTranslatorEquip, 1f); + + public void PlayUnequipTool() + => _oneShotExternalSource.PlayOneShot(AudioType.ToolTranslatorUnequip, 1f); + + private OWAudioSource CreateBaseAudio( + string name, + bool loop, + int priority, + float volume, + AudioType audioLibraryClip, + OWAudioMixer.TrackName track, + bool randomize) + { + DebugLog.DebugWrite($"createBaseAudio {name}"); + var go = new GameObject(name); + go.transform.parent = transform; + go.transform.localPosition = Vector3.zero; + go.transform.localScale = Vector3.one; + + var audioSource = go.AddComponent(); + audioSource.mute = false; + audioSource.bypassEffects = false; + audioSource.bypassListenerEffects = false; + audioSource.bypassReverbZones = false; + audioSource.playOnAwake = false; + audioSource.loop = loop; + audioSource.priority = priority; + audioSource.volume = volume; + audioSource.spatialBlend = 1f; + + var owAudioSource = go.AddComponent(); + owAudioSource._audioLibraryClip = audioLibraryClip; + owAudioSource._clipSelectionOnPlay = OWAudioSource.ClipSelectionOnPlay.RANDOM; + owAudioSource._track = track; + owAudioSource._randomizePlayheadOnAwake = randomize; + + return owAudioSource; + } + } +} diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index da426922..b791592f 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -1,6 +1,7 @@ using OWML.Common; using QSB.Animation.Player; using QSB.Animation.Player.Thrusters; +using QSB.Audio; using QSB.CampfireSync.WorldObjects; using QSB.ClientServerStateSync; using QSB.Events; @@ -130,6 +131,7 @@ namespace QSB.Player public bool SignalscopeEquipped { get; set; } public bool TranslatorEquipped { get; set; } public bool ProbeActive { get; set; } + public QSBPlayerAudioController AudioController { get; set; } // Local only public PlayerProbeLauncher LocalProbeLauncher diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index ef2e0209..db463ccd 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -1,5 +1,6 @@ using OWML.Utils; using QSB.Animation.Player; +using QSB.Audio; using QSB.Events; using QSB.Instruments; using QSB.RoastingSync; @@ -173,12 +174,12 @@ namespace QSB.Player.TransformSync REMOTE_Player_Body.AddComponent().PlayerName = Player.Name; + Player.AudioController = PlayerAudioManager.InitRemote(REMOTE_Player_Body.transform); + /* * SET UP PLAYER CAMERA */ - PlayerToolsManager.InitRemote(REMOTE_PlayerCamera.transform); - var camera = REMOTE_PlayerCamera.AddComponent(); camera.enabled = false; var owcamera = REMOTE_PlayerCamera.AddComponent(); @@ -189,6 +190,8 @@ namespace QSB.Player.TransformSync Player.CameraBody = REMOTE_PlayerCamera; _visibleCameraRoot = REMOTE_PlayerCamera.transform; + PlayerToolsManager.InitRemote(Player); + /* * SET UP ROASTING STICK */ diff --git a/QSB/Tools/FlashlightTool/FlashlightCreator.cs b/QSB/Tools/FlashlightTool/FlashlightCreator.cs index 3478edf5..7865d82b 100644 --- a/QSB/Tools/FlashlightTool/FlashlightCreator.cs +++ b/QSB/Tools/FlashlightTool/FlashlightCreator.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using QSB.Player; +using UnityEngine; namespace QSB.Tools.FlashlightTool { @@ -6,7 +7,7 @@ namespace QSB.Tools.FlashlightTool { private static readonly Vector3 FlashlightOffset = new(0.7196316f, -0.2697681f, 0.3769455f); - internal static void CreateFlashlight(Transform cameraBody) + internal static void CreateFlashlight(PlayerInfo player) { var flashlightRoot = Object.Instantiate(GameObject.Find("FlashlightRoot")); flashlightRoot.name = "REMOTE_FlashlightRoot"; @@ -17,7 +18,7 @@ namespace QSB.Tools.FlashlightTool component.Init(oldComponent); oldComponent.enabled = false; - flashlightRoot.transform.parent = cameraBody; + flashlightRoot.transform.parent = player.CameraBody.transform; flashlightRoot.transform.localPosition = FlashlightOffset; flashlightRoot.SetActive(true); } diff --git a/QSB/Tools/PlayerToolsManager.cs b/QSB/Tools/PlayerToolsManager.cs index ac284566..c29b6c06 100644 --- a/QSB/Tools/PlayerToolsManager.cs +++ b/QSB/Tools/PlayerToolsManager.cs @@ -1,4 +1,5 @@ -using QSB.Tools.FlashlightTool; +using QSB.Player; +using QSB.Tools.FlashlightTool; using QSB.Tools.ProbeLauncherTool; using QSB.Tools.SignalscopeTool; using QSB.Tools.TranslatorTool; @@ -19,11 +20,11 @@ namespace QSB.Tools public static Material Props_HEA_Lightbulb_OFF_mat; public static Material Structure_HEA_PlayerShip_Screens_mat; - public static void InitRemote(Transform playerCamera) + public static void InitRemote(PlayerInfo player) { try { - CreateStowTransforms(playerCamera); + CreateStowTransforms(player.CameraBody.transform); Props_HEA_PlayerTool_mat = GameObject.Find("Props_HEA_ProbeLauncher_ProbeCamera/ProbeLauncherChassis").GetComponent().materials[0]; Props_HEA_Lightbulb_OFF_mat = GameObject.Find("Props_HEA_Probe_Prelaunch").GetComponent().materials[1]; @@ -48,10 +49,10 @@ namespace QSB.Tools DebugLog.ToConsole($"Error when trying to find materials : {ex}", OWML.Common.MessageType.Error); } - FlashlightCreator.CreateFlashlight(playerCamera); - SignalscopeCreator.CreateSignalscope(playerCamera); - ProbeLauncherCreator.CreateProbeLauncher(playerCamera); - TranslatorCreator.CreateTranslator(playerCamera); + FlashlightCreator.CreateFlashlight(player); + SignalscopeCreator.CreateSignalscope(player); + ProbeLauncherCreator.CreateProbeLauncher(player); + TranslatorCreator.CreateTranslator(player); } public static void InitLocal() diff --git a/QSB/Tools/ProbeLauncherTool/ProbeLauncherCreator.cs b/QSB/Tools/ProbeLauncherTool/ProbeLauncherCreator.cs index c349b81d..38b4bcaf 100644 --- a/QSB/Tools/ProbeLauncherTool/ProbeLauncherCreator.cs +++ b/QSB/Tools/ProbeLauncherTool/ProbeLauncherCreator.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using QSB.Player; +using UnityEngine; using UnityEngine.Rendering; namespace QSB.Tools.ProbeLauncherTool @@ -7,7 +8,7 @@ namespace QSB.Tools.ProbeLauncherTool { private static readonly Vector3 ProbeLauncherOffset = new(0.5745087f, -0.26f, 0.4453125f); - internal static void CreateProbeLauncher(Transform cameraBody) + internal static void CreateProbeLauncher(PlayerInfo player) { var ProbeLauncher = GameObject.Find("PlayerCamera/ProbeLauncher"); @@ -29,7 +30,7 @@ namespace QSB.Tools.ProbeLauncherTool var effects = REMOTE_ProbeLauncher.AddComponent(); effects._launchParticles = REMOTE_LaunchParticleEffect.GetComponent(); effects._underwaterLaunchParticles = REMOTE_LaunchParticleEffect_Underwater.GetComponent(); - effects._owAudioSource = ProbeLauncher.GetComponent()._owAudioSource; + effects._owAudioSource = player.AudioController._repairToolSource; var recallEffect = REMOTE_Props_HEA_ProbeLauncher.Find("RecallEffect"); @@ -71,11 +72,12 @@ namespace QSB.Tools.ProbeLauncherTool tool.ArrivalDegrees = 5f; tool.Type = ToolType.ProbeLauncher; tool.ToolGameObject = REMOTE_Props_HEA_ProbeLauncher.gameObject; + tool.Player = player; tool.PreLaunchProbeProxy = preLaunchProbe.gameObject; tool.ProbeRetrievalEffect = recallEffect.GetComponent(); tool.Effects = effects; - REMOTE_ProbeLauncher.transform.parent = cameraBody; + REMOTE_ProbeLauncher.transform.parent = player.CameraBody.transform; REMOTE_ProbeLauncher.transform.localPosition = ProbeLauncherOffset; //QSBCore.UnityEvents.FireInNUpdates(() => REMOTE_ProbeLauncher.SetActive(true), 5); diff --git a/QSB/Tools/QSBTool.cs b/QSB/Tools/QSBTool.cs index 1a001d99..c9ae35fc 100644 --- a/QSB/Tools/QSBTool.cs +++ b/QSB/Tools/QSBTool.cs @@ -1,9 +1,11 @@ -using UnityEngine; +using QSB.Player; +using UnityEngine; namespace QSB.Tools { public class QSBTool : PlayerTool { + public PlayerInfo Player { get; set; } public ToolType Type { get; set; } public GameObject ToolGameObject { get; set; } @@ -44,5 +46,17 @@ namespace QSB.Tools UnequipTool(); } + + public override void EquipTool() + { + base.EquipTool(); + Player.AudioController.PlayEquipTool(); + } + + public override void UnequipTool() + { + base.UnequipTool(); + Player.AudioController.PlayUnequipTool(); + } } } \ No newline at end of file diff --git a/QSB/Tools/SignalscopeTool/SignalscopeCreator.cs b/QSB/Tools/SignalscopeTool/SignalscopeCreator.cs index 2db6adc2..798ab360 100644 --- a/QSB/Tools/SignalscopeTool/SignalscopeCreator.cs +++ b/QSB/Tools/SignalscopeTool/SignalscopeCreator.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using QSB.Player; +using UnityEngine; using UnityEngine.Rendering; namespace QSB.Tools.SignalscopeTool @@ -7,7 +8,7 @@ namespace QSB.Tools.SignalscopeTool { private static readonly Vector3 SignalscopeScale = new(1.5f, 1.5f, 1.5f); - internal static void CreateSignalscope(Transform cameraBody) + internal static void CreateSignalscope(PlayerInfo player) { var signalscopeRoot = Object.Instantiate(GameObject.Find("Signalscope")); signalscopeRoot.name = "REMOTE_Signalscope"; @@ -26,12 +27,13 @@ namespace QSB.Tools.SignalscopeTool tool.ArrivalDegrees = 5f; tool.Type = ToolType.Signalscope; tool.ToolGameObject = Props_HEA_Signalscope.gameObject; + tool.Player = player; oldSignalscope.enabled = false; Props_HEA_Signalscope.GetComponent().material = PlayerToolsManager.Props_HEA_PlayerTool_mat; Props_HEA_Signalscope.GetComponent().shadowCastingMode = ShadowCastingMode.On; - signalscopeRoot.transform.parent = cameraBody; + signalscopeRoot.transform.parent = player.CameraBody.transform; signalscopeRoot.transform.localPosition = Vector3.zero; signalscopeRoot.transform.localScale = SignalscopeScale; signalscopeRoot.SetActive(true); diff --git a/QSB/Tools/TranslatorTool/TranslatorCreator.cs b/QSB/Tools/TranslatorTool/TranslatorCreator.cs index 7fea6a20..8064767d 100644 --- a/QSB/Tools/TranslatorTool/TranslatorCreator.cs +++ b/QSB/Tools/TranslatorTool/TranslatorCreator.cs @@ -1,4 +1,5 @@ -using QSB.Utility; +using QSB.Player; +using QSB.Utility; using UnityEngine; using UnityEngine.Rendering; @@ -8,7 +9,7 @@ namespace QSB.Tools.TranslatorTool { private static readonly Vector3 TranslatorScale = new(0.75f, 0.75f, 0.75f); - internal static void CreateTranslator(Transform cameraBody) + internal static void CreateTranslator(PlayerInfo player) { var NomaiTranslatorProp = GameObject.Find("NomaiTranslatorProp"); @@ -51,7 +52,8 @@ namespace QSB.Tools.TranslatorTool tool.ArrivalDegrees = 5f; tool.Type = ToolType.Translator; tool.ToolGameObject = REMOTE_TranslatorGroup.gameObject; - tool.RaycastTransform = cameraBody; + tool.Player = player; + tool.RaycastTransform = player.CameraBody.transform; Object.Destroy(oldTranslator); PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Screen").material = PlayerToolsManager.Structure_HEA_PlayerShip_Screens_mat; @@ -65,7 +67,7 @@ namespace QSB.Tools.TranslatorTool PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Button_R").material = PlayerToolsManager.Props_HEA_Lightbulb_mat; PlayerToolsManager.GetRenderer(REMOTE_NomaiTranslatorProp, "Props_HEA_Translator_Button_R").shadowCastingMode = ShadowCastingMode.On; - REMOTE_NomaiTranslatorProp.transform.parent = cameraBody; + REMOTE_NomaiTranslatorProp.transform.parent = player.CameraBody.transform; REMOTE_NomaiTranslatorProp.transform.localPosition = Vector3.zero; REMOTE_NomaiTranslatorProp.transform.localScale = TranslatorScale; QSBCore.UnityEvents.FireInNUpdates(() => REMOTE_NomaiTranslatorProp.SetActive(true), 5);