Skip to content

Commit

Permalink
Implement game audio
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyDuchess committed Sep 6, 2024
1 parent ef59947 commit bd867a5
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 86 deletions.
29 changes: 29 additions & 0 deletions MapStation.Common/Runtime/GameAudio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Reptile;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace MapStation.Common.Runtime {
[RequireComponent(typeof(AudioSource))]
public class GameAudio : MonoBehaviour {
public enum AudioTypes {
Master = 0,
Music = 4,
SFX = 1,
UI = 2,
Gameplay = 3,
Voices = 5,
Ambience = 6
}
public AudioTypes AudioType = AudioTypes.Gameplay;
#if BEPINEX
private void Awake() {
var audioSource = GetComponent<AudioSource>();
audioSource.outputAudioMixerGroup = Core.Instance.AudioManager.mixerGroups[(int) AudioType];
}
#endif
}
}
11 changes: 11 additions & 0 deletions MapStation.Common/Runtime/GameAudio.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,65 +1,78 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5531776540454774869
--- !u!1 &911695850910785175
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1075615974772501728}
- component: {fileID: 5884451559065249828}
- component: {fileID: 7512777971387938246}
- component: {fileID: 4902003743957009481}
- component: {fileID: 6726315859376625976}
- component: {fileID: 761963668604459004}
m_Layer: 0
m_Name: Ambient Sound
m_Name: Audio Source
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1075615974772501728
--- !u!4 &4902003743957009481
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5531776540454774869}
m_GameObject: {fileID: 911695850910785175}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 26.938553, y: 1.185, z: 3.76005}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!82 &5884451559065249828
--- !u!114 &6726315859376625976
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 911695850910785175}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 128b8b6b497f5054a8d5dd64ea15a2e1, type: 3}
m_Name:
m_EditorClassIdentifier:
AudioType: 3
--- !u!82 &761963668604459004
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5531776540454774869}
m_GameObject: {fileID: 911695850910785175}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 24300000, guid: 2f929fd3a018c48449995bb7f2a1b192, type: 2}
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 256
DopplerLevel: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 1.01
MaxDistance: 500
Pan2D: 0
rolloffMode: 2
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 1
BypassReverbZones: 1
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
Expand Down Expand Up @@ -129,67 +142,3 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!114 &7512777971387938246
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5531776540454774869}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d3f53950e5e641f459d8726da39a49ff, type: 3}
m_Name:
m_EditorClassIdentifier:
components:
rid: 6810966811538882560
references:
version: 2
RefIds:
- rid: -2
type: {class: , ns: , asm: }
- rid: 6810966811538882560
type: {class: VanillaAssetReferenceV2/SList_Components, ns: MapStation.Common.VanillaAssets, asm: MapStation.Common}
data:
linkedList:
rid: 6810966811538882561
items:
- rid: 6810966811538882562
- rid: 6810966811538882561
type: {class: Node, ns: MapStation.Common.Serialization, asm: MapStation.Common}
data:
value:
rid: 6810966811538882562
next:
rid: -2
- rid: 6810966811538882562
type: {class: ComponentEntry, ns: MapStation.Common.VanillaAssets, asm: MapStation.Common}
data:
Component: {fileID: 5884451559065249828}
fields:
rid: 6810966811538882563
- rid: 6810966811538882563
type: {class: ComponentEntry/SList_FieldEntry, ns: MapStation.Common.VanillaAssets, asm: MapStation.Common}
data:
linkedList:
rid: 6810966811538882566
items:
- rid: 6810966811538882567
- rid: 6810966811538882566
type: {class: Node, ns: MapStation.Common.Serialization, asm: MapStation.Common}
data:
value:
rid: 6810966811538882567
next:
rid: -2
- rid: 6810966811538882567
type: {class: FieldEntry, ns: MapStation.Common.VanillaAssets, asm: MapStation.Common}
data:
Enabled: 1
AutoSync: 1
Name: outputAudioMixerGroup
Index: -1
BundleName: coreassets
Path: Assets/audio/MasterMixer.mixer
SubAssetType: 1
SubPath: Gameplay

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions MapStation.Tools/Editor/Inspectors/GameAudioEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using MapStation.Tools.Editor;
using MapStation.Common.Runtime;
using Reptile;
using UnityEditor;

[CustomEditor(typeof(GameAudio))]
[CanEditMultipleObjects]
public class GameAudioEditor : Editor {
public override void OnInspectorGUI() {
EditorHelper.MakeDocsButton("Game-Audio");
DrawDefaultInspector();
}
}
11 changes: 11 additions & 0 deletions MapStation.Tools/Editor/Inspectors/GameAudioEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions MapStation.Tools/Editor/PrefabContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ private enum UnpackMode {
private const int Priority = -30;
private const string PrefabPathPrefix = "Packages/com.brcmapstation.tools/Assets/MapComponents/";

[MenuItem("GameObject/" + UIConstants.menuLabel + "/Audio/Ambient Sound", priority = Priority)]
private static void CreateAmbientSound(MenuCommand menuCommand) {
CreatePrefabUnderContext(menuCommand.context, "Ambient Sound", true, UnpackMode.UnpackCompletely);
[MenuItem("GameObject/" + UIConstants.menuLabel + "/Audio/Audio Source", priority = Priority)]
private static void CreateAudioSource(MenuCommand menuCommand) {
CreatePrefabUnderContext(menuCommand.context, "Audio Source", true, UnpackMode.UnpackCompletely);
}

[MenuItem("GameObject/" + UIConstants.menuLabel + "/Spawners/Respawn Point", priority = Priority)]
Expand Down

0 comments on commit bd867a5

Please sign in to comment.