Done with Audio Implementation via C# #347

Merged
mushgunAX merged 14 commits from AudioImplementation into main 2023-02-04 10:18:26 +08:00
17 changed files with 152 additions and 37 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,23 @@
using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting.Audio
{
public static class AudioHandler
{
public static Dictionary<string, AudioClipHandler> audioClipHandlers = new Dictionary<string, AudioClipHandler>();
//Functions here, maybe
public static void stopAllSounds(bool fadeOut)
{
foreach (KeyValuePair<string, AudioClipHandler> h in audioClipHandlers)
{
h.Value.Stop(fadeOut);
}
}
}
}

View File

@ -0,0 +1,3 @@
Name: AudioHandler
ID: 159235425
Type: 9

View File

@ -14,6 +14,7 @@
using SHADE; using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree; using SHADE_Scripting.AIBehaviour.BehaviourTree;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -99,6 +100,17 @@ public partial class Homeowner1 : BehaviourTree
SetData("turningSpeed", turningSpeed); SetData("turningSpeed", turningSpeed);
SetData("distanceToCapture", distanceToCapture); SetData("distanceToCapture", distanceToCapture);
SetData("baseCaptureTime", captureTime);*/ SetData("baseCaptureTime", captureTime);*/
//These should be somewhere else
//Debug.Log("TESTING");
AudioHandler.audioClipHandlers["BGMUnalert"] = Audio.CreateAudioClip("event:/Music/player_undetected");
AudioHandler.audioClipHandlers["BGMAlert"] = Audio.CreateAudioClip("event:/Music/player_detected");
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive");
AudioHandler.audioClipHandlers["SFXFootstep"] = Audio.CreateAudioClip("event:/Homeowner/homeowner_footsteps");
AudioHandler.audioClipHandlers["SFXDetectAh"] = Audio.CreateAudioClip("event:/Homeowner/homeowner_detect_raccoon");
AudioHandler.audioClipHandlers["SFXDetectSting"] = Audio.CreateAudioClip("event:/Music/stingers/player_detected");
} }
//Called every tick //Called every tick
@ -132,7 +144,6 @@ public partial class Homeowner1 : BehaviourTree
if (GetData("baseCaptureTime") == null || (float)GetData("baseCaptureTime") != captureTime) if (GetData("baseCaptureTime") == null || (float)GetData("baseCaptureTime") != captureTime)
SetData("baseCaptureTime", captureTime); SetData("baseCaptureTime", captureTime);
events.Tick(); events.Tick();
//Footsteps SFX, move them somewhere else soon //Footsteps SFX, move them somewhere else soon
@ -141,7 +152,8 @@ public partial class Homeowner1 : BehaviourTree
footstepTimeRemaining -= velocity * Time.DeltaTimeF; footstepTimeRemaining -= velocity * Time.DeltaTimeF;
if (footstepTimeRemaining < 0.0f) if (footstepTimeRemaining < 0.0f)
{ {
Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_footsteps"); //Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_footsteps");
//AudioHandler.audioClipHandlers["SFXFootstep"].Play();
footstepTimeRemaining = footstepSFXIntervalMultiplier; footstepTimeRemaining = footstepSFXIntervalMultiplier;
} }
//Debug.Log("Ticked"); //Debug.Log("Ticked");

View File

@ -11,6 +11,7 @@
using SHADE; using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree; using SHADE_Scripting.AIBehaviour.BehaviourTree;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -111,7 +112,9 @@ public partial class LeafChase : BehaviourTreeNode
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{ {
Audio.PlaySFXOnce2D("event:/Homeowner/humming"); //AudioHandler.audioClipHandlers["BGMAdpative"].SetParameter("Detected", 0.0f);
Audio.SetParameter("Detected", 0.0f);
AudioHandler.audioClipHandlers["SFXHumming"].Play();
} }
SetNodeData("isAlert", false); SetNodeData("isAlert", false);

View File

@ -11,6 +11,7 @@
using SHADE; using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree; using SHADE_Scripting.AIBehaviour.BehaviourTree;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -239,9 +240,12 @@ public partial class LeafPatrol : BehaviourTreeNode
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert")) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert"))
{ {
//Debug.Log("Unalert"); //Debug.Log("Unalert");
Audio.PlaySFXOnce2D("event:/Homeowner/humming"); //AudioHandler.audioClipHandlers["BGMAlert"].Stop(true);
Audio.StopAllSounds(); //Audio.PlaySFXOnce2D("event:/Homeowner/humming");
Audio.PlayBGMOnce2D("event:/Music/player_undetected"); AudioHandler.audioClipHandlers["SFXHumming"].Play();
//AudioHandler.audioClipHandlers["BGMUnalert"].Play();
//AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 0.0f);
Audio.SetParameter("Detected", 0.0f);
} }
SetNodeData("isAlert", false); SetNodeData("isAlert", false);
} }

View File

@ -11,6 +11,7 @@
using SHADE; using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree; using SHADE_Scripting.AIBehaviour.BehaviourTree;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -65,7 +66,9 @@ public partial class LeafSearch : BehaviourTreeNode
{ {
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{ {
Audio.PlaySFXOnce2D("event:/Homeowner/humming"); //AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 0.0f);
Audio.SetParameter("Detected", 0.0f);
AudioHandler.audioClipHandlers["SFXHumming"].Play();
reevaluateWaypoint(); reevaluateWaypoint();
} }
SetNodeData("isAlert", false); SetNodeData("isAlert", false);
@ -185,19 +188,27 @@ public partial class LeafSearch : BehaviourTreeNode
if (GetNodeData("isAlert") == null) if (GetNodeData("isAlert") == null)
{ {
SetNodeData("isAlert", true); SetNodeData("isAlert", true);
Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_detect_raccoon"); //Audio.StopAllSounds();
Audio.PlaySFXOnce2D("event:/Music/stingers/player_detected"); AudioHandler.audioClipHandlers["SFXDetectAh"].Play();
Audio.StopAllSounds(); AudioHandler.audioClipHandlers["SFXDetectSting"].Play();
Audio.PlayBGMOnce2D("event:/Music/player_detected"); //AudioHandler.audioClipHandlers["BGMAlert"].Play();
AudioHandler.audioClipHandlers["SFXHumming"].Stop(false);
//AudioHandler.audioClipHandlers["BGMUnalert"].Stop(true);
//AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 1.0f);
Audio.SetParameter("Detected", 1.0f);
} }
else else
{ {
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == false) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == false)
{ {
Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_detect_raccoon"); //Audio.StopAllSounds();
Audio.PlaySFXOnce2D("event:/Music/stingers/player_detected"); AudioHandler.audioClipHandlers["SFXDetectAh"].Play();
Audio.StopAllSounds(); AudioHandler.audioClipHandlers["SFXDetectSting"].Play();
Audio.PlayBGMOnce2D("event:/Music/player_detected"); //AudioHandler.audioClipHandlers["BGMAlert"].Play();
AudioHandler.audioClipHandlers["SFXHumming"].Stop(false);
//AudioHandler.audioClipHandlers["BGMUnalert"].Stop(true);
//AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 1.0f);
Audio.SetParameter("Detected", 1.0f);
} }
SetNodeData("isAlert", true); SetNodeData("isAlert", true);
} }

View File

@ -1,4 +1,5 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -31,6 +32,8 @@ public class Breakable : Script
} }
isBreak = false; isBreak = false;
AudioHandler.audioClipHandlers["SFXBreak"] = Audio.CreateAudioClip("event:/Props/impact_break");
} }
protected override void update() protected override void update()
@ -72,7 +75,7 @@ public class Breakable : Script
} }
isBreak = false; isBreak = false;
Audio.PlaySFXOnce2D("event:/Props/impact_break"); AudioHandler.audioClipHandlers["SFXBreak"].Play();
GameObject.SetActive(false); GameObject.SetActive(false);
} }
} }

View File

@ -1,4 +1,5 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
using System; using System;
public class Item : Script public class Item : Script
{ {
@ -29,6 +30,9 @@ public class Item : Script
collider.GetCollisionShape(0).Density = density; collider.GetCollisionShape(0).Density = density;
returnBack = false; returnBack = false;
AudioHandler.audioClipHandlers["SFXImpactElastic"] = Audio.CreateAudioClip("event:/Props/impact_elastic");
AudioHandler.audioClipHandlers["SFXImpactHard"] = Audio.CreateAudioClip("event:/Props/impact_hard");
} }
protected override void start() protected override void start()
@ -55,10 +59,10 @@ public class Item : Script
if (playSound) if (playSound)
{ {
if(currCategory == ItemCategory.LIGHT) if (currCategory == ItemCategory.LIGHT)
Audio.PlaySFXOnce2D("event:/Props/impact_elastic"); AudioHandler.audioClipHandlers["SFXImpactElastic"].Play();
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY) else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
Audio.PlaySFXOnce2D("event:/Props/impact_hard"); AudioHandler.audioClipHandlers["SFXImpactHard"].Play();
playSound = false; playSound = false;
} }

View File

@ -1,5 +1,6 @@
using SHADE; using SHADE;
using SHADE_Scripting; using SHADE_Scripting;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using static PlayerController; using static PlayerController;
@ -43,6 +44,8 @@ public class PickAndThrow : Script
if(!tpc) if(!tpc)
Debug.LogError("TPC EMPTY"); Debug.LogError("TPC EMPTY");
AudioHandler.audioClipHandlers["SFXThrow"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_throw");
timer = delayTimer; timer = delayTimer;
} }
protected override void update() protected override void update()
@ -72,7 +75,7 @@ public class PickAndThrow : Script
if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming) if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming)
{ {
Audio.PlaySFXOnce2D("event:/Raccoon/raccoon_throw"); AudioHandler.audioClipHandlers["SFXThrow"].Play();
itemRidigBody.IsGravityEnabled = true; itemRidigBody.IsGravityEnabled = true;
itemCollider.GetCollisionShape(0).IsTrigger = false; itemCollider.GetCollisionShape(0).IsTrigger = false;
pc.isAiming = false; pc.isAiming = false;

View File

@ -1,4 +1,5 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -38,6 +39,23 @@ public class GameManager : Script
public static GameManager Instance { get; private set; } public static GameManager Instance { get; private set; }
protected override void start()
{
base.start();
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive");
AudioHandler.audioClipHandlers["BGMAdaptive"].Play();
Audio.SetParameter("Detected", 0.0f);
AudioHandler.audioClipHandlers["KitchenAmbience"] = Audio.CreateAudioClip("event:/Ambience/roomtone_kitchen");
AudioHandler.audioClipHandlers["KitchenAmbience"].Play();
AudioHandler.audioClipHandlers["SFXHumming"] = Audio.CreateAudioClip("event:/Homeowner/homeowner_humming");
AudioHandler.audioClipHandlers["SFXHumming"].SetVolume(0.15f);
AudioHandler.audioClipHandlers["SFXHumming"].Play();
}
protected override void awake() protected override void awake()
{ {
if (Instance != null && Instance != this) if (Instance != null && Instance != this)
@ -45,8 +63,12 @@ public class GameManager : Script
else else
Instance = this; Instance = this;
Audio.PlayBGMOnce2D("event:/Music/player_undetected");
Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen"); //AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 0.0f);
//Audio.PlayBGMOnce2D("event:/Music/player_undetected");
//Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen");
totalItemCount = 0; totalItemCount = 0;
Score = 0; Score = 0;
currGameState = GameState.START; currGameState = GameState.START;
@ -54,6 +76,9 @@ public class GameManager : Script
currMultiplierCombo = 1; currMultiplierCombo = 1;
currMultiplierDuration = 0; currMultiplierDuration = 0;
fontScalar = new Vector3(multiplierFont / maxMultiplierDuration, multiplierFont / maxMultiplierDuration , multiplierFont / maxMultiplierDuration); fontScalar = new Vector3(multiplierFont / maxMultiplierDuration, multiplierFont / maxMultiplierDuration , multiplierFont / maxMultiplierDuration);
AudioHandler.audioClipHandlers["BGMWin"] = Audio.CreateAudioClip("event:/Music/stingers/game_win");
AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose");
} }
protected override void update() protected override void update()
@ -89,16 +114,22 @@ public class GameManager : Script
if ((timer > 0 && totalItemCount < 0) || Input.GetKeyDown(Input.KeyCode.F1)) if ((timer > 0 && totalItemCount < 0) || Input.GetKeyDown(Input.KeyCode.F1))
{ {
currGameState = GameState.WIN; currGameState = GameState.WIN;
Audio.StopAllSounds(); //Audio.StopAllSounds(); //Calling this outright breaks audio clip handlers
AudioHandler.stopAllSounds(false);
AudioHandler.audioClipHandlers["BGMWin"].Play();
SceneManager.ChangeScene(winScene); SceneManager.ChangeScene(winScene);
Audio.PlaySFXOnce2D("event:/Music/stingers/game_win"); //Audio.PlaySFXOnce2D("event:/Music/stingers/game_win");
} }
else if(timer < 0 || Input.GetKeyDown(Input.KeyCode.F2)) else if(timer < 0 || Input.GetKeyDown(Input.KeyCode.F2))
{ {
currGameState = GameState.LOSE; currGameState = GameState.LOSE;
Audio.StopAllSounds(); //Audio.StopAllSounds();
AudioHandler.stopAllSounds(false);
AudioHandler.audioClipHandlers["BGMLose"].Play();
SceneManager.ChangeScene(loseScene); SceneManager.ChangeScene(loseScene);
Audio.PlaySFXOnce2D("event:/Music/stingers/game_lose"); //Audio.PlaySFXOnce2D("event:/Music/stingers/game_lose");
} }
} }
} }

View File

@ -1,17 +1,19 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
using System; using System;
public class ScoringZone : Script public class ScoringZone : Script
{ {
protected override void awake() protected override void awake()
{ {
AudioHandler.audioClipHandlers["SFXItemScore"] = Audio.CreateAudioClip("event:/Music/stingers/item_scored");
} }
protected override void onTriggerEnter(CollisionInfo info) protected override void onTriggerEnter(CollisionInfo info)
{ {
if (GameManager.Instance && info.GameObject.GetScript<Item>() && info.GameObject.IsActiveSelf) if (GameManager.Instance && info.GameObject.GetScript<Item>() && info.GameObject.IsActiveSelf)
{ {
Audio.PlaySFXOnce2D("event:/Music/stingers/item_scored"); AudioHandler.audioClipHandlers["SFXItemScore"].Play();
GameManager.Instance.Score += info.GameObject.GetScript<Item>().Score * GameManager.Instance.currMultiplierCombo; GameManager.Instance.Score += info.GameObject.GetScript<Item>().Score * GameManager.Instance.currMultiplierCombo;
GameManager.Instance.ItemScored(); GameManager.Instance.ItemScored();
info.GameObject.SetActive(false); info.GameObject.SetActive(false);

View File

@ -1,5 +1,6 @@
using System; using System;
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
public class EndScene : Script public class EndScene : Script
{ {
@ -8,28 +9,36 @@ public class EndScene : Script
protected override void awake() protected override void awake()
{ {
AudioHandler.audioClipHandlers["SFXMouseDownElement"] = Audio.CreateAudioClip("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXUISuccess"] = Audio.CreateAudioClip("event:/UI/success");
} }
protected override void update() protected override void update()
{ {
if (Input.GetKeyDown(Input.KeyCode.R)) if (Input.GetKeyDown(Input.KeyCode.R))
{ {
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); //Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXMouseDownElement"].Play();
} }
if (Input.GetKeyUp(Input.KeyCode.R)) if (Input.GetKeyUp(Input.KeyCode.R))
{ {
Audio.PlaySFXOnce2D("event:/UI/success"); //Audio.PlaySFXOnce2D("event:/UI/success");
Audio.StopAllSounds(); //Audio.StopAllSounds();
AudioHandler.stopAllSounds(false);
AudioHandler.audioClipHandlers["SFXUISuccess"].Play();
SceneManager.ChangeScene(mainGameScene); SceneManager.ChangeScene(mainGameScene);
} }
if (Input.GetKeyDown(Input.KeyCode.M)) if (Input.GetKeyDown(Input.KeyCode.M))
{ {
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); //Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXMouseDownElement"].Play();
} }
if (Input.GetKeyUp(Input.KeyCode.M)) if (Input.GetKeyUp(Input.KeyCode.M))
{ {
Audio.PlaySFXOnce2D("event:/UI/success"); //Audio.PlaySFXOnce2D("event:/UI/success");
Audio.StopAllSounds(); //Audio.StopAllSounds();
AudioHandler.stopAllSounds(false);
AudioHandler.audioClipHandlers["SFXUISuccess"].Play();
SceneManager.ChangeScene(mainMainScene); SceneManager.ChangeScene(mainMainScene);
} }

View File

@ -1,23 +1,30 @@
using System; using System;
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
public class MainMenu : Script public class MainMenu : Script
{ {
public uint sceneID; public uint sceneID;
protected override void awake() protected override void awake()
{ {
Audio.PlayBGMOnce2D("event:/Music/main_menu"); AudioHandler.audioClipHandlers["BGMMainMenu"] = Audio.CreateAudioClip("event:/Music/main_menu");
AudioHandler.audioClipHandlers["SFXMouseDownElement"] = Audio.CreateAudioClip("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXUISuccess"] = Audio.CreateAudioClip("event:/UI/success");
//Audio.PlayBGMOnce2D("event:/Music/main_menu");
AudioHandler.audioClipHandlers["BGMMainMenu"].Play();
} }
protected override void update() protected override void update()
{ {
if (Input.GetKeyDown(Input.KeyCode.Space)) if (Input.GetKeyDown(Input.KeyCode.Space))
{ {
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); //Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXMouseDownElement"].Play();
} }
if (Input.GetKeyUp(Input.KeyCode.Space)) if (Input.GetKeyUp(Input.KeyCode.Space))
{ {
Audio.PlaySFXOnce2D("event:/UI/success"); //Audio.PlaySFXOnce2D("event:/UI/success");
AudioHandler.audioClipHandlers["SFXUISuccess"].Play();
SceneManager.ChangeScene(sceneID); SceneManager.ChangeScene(sceneID);
Audio.StopAllSounds(); Audio.StopAllSounds();
} }