Skip to content

Commit

Permalink
feat(sfx): set up a system for managing and playing sound effects. (#31)
Browse files Browse the repository at this point in the history
* refactor(audio): improve AudioCueEventChannelSO and add extensions
  • Loading branch information
Long18 authored Jan 29, 2024
1 parent c817bc3 commit af7ba59
Show file tree
Hide file tree
Showing 34 changed files with 394 additions and 66 deletions.
5 changes: 5 additions & 0 deletions Assets/AddressableAssetsData/AssetGroups/MusicAssets.asset
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ MonoBehaviour:
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 28eb4ad9a65ec494a9907a5a07171cff
m_Address: Assets/Data/Audio/SFX
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
m_ReadOnly: 0
m_Settings: {fileID: 11400000, guid: 140825c59dff30f4ebecb9ab06661447, type: 2}
m_SchemaSet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e853e723cfbf4e7da615b054cfc4db64, type: 3}
m_Name: PlayMusicChannel
m_Name: PlayBGMChannel
m_EditorClassIdentifier:
14 changes: 14 additions & 0 deletions Assets/Events/Audio/PlaySFXChannel.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e853e723cfbf4e7da615b054cfc4db64, type: 3}
m_Name: PlaySFXChannel
m_EditorClassIdentifier:
8 changes: 8 additions & 0 deletions Assets/Events/Audio/PlaySFXChannel.asset.meta

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

4 changes: 2 additions & 2 deletions Assets/Prefabs/Audio/AudioManager.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1c78340c157f82a4180e563ecf5962c3, type: 3}
m_Name:
m_EditorClassIdentifier:
_musicEventChannel: {fileID: 11400000, guid: d4a1ab99002686347aa83683e22ea4c9, type: 2}
_pool: {fileID: 5200358429395339823}
_bgmEventChannel: {fileID: 11400000, guid: d4a1ab99002686347aa83683e22ea4c9, type: 2}
_sfxEventChannel: {fileID: 11400000, guid: b38999da36c039a4fb6d26a16e19eb32, type: 2}
--- !u!114 &5200358429395339823
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion Assets/Prefabs/Audio/PlayBGM.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_musicEventChannel: {fileID: 11400000, guid: d4a1ab99002686347aa83683e22ea4c9, type: 2}
MusicTrack: {fileID: 11400000, guid: 3ef5f4ffd0dde264eb3f0f45ca6f6d77, type: 2}
musicTrack: {fileID: 11400000, guid: 3ef5f4ffd0dde264eb3f0f45ca6f6d77, type: 2}
49 changes: 49 additions & 0 deletions Assets/Prefabs/Audio/PlaySFX.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &9122669388108318780
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8666167773005286318}
- component: {fileID: 3928733278479930333}
m_Layer: 0
m_Name: PlaySFX
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8666167773005286318
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9122669388108318780}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3928733278479930333
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9122669388108318780}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f81e3fcda3c84252865b0e3fb135efc3, type: 3}
m_Name:
m_EditorClassIdentifier:
_sfxEventChannel: {fileID: 11400000, guid: b38999da36c039a4fb6d26a16e19eb32, type: 2}
soundEffectTrack: {fileID: 11400000, guid: cf0b786ed6e71294b8b6dbd259fcc245, type: 2}
_playOnStart: 1
7 changes: 7 additions & 0 deletions Assets/Prefabs/Audio/PlaySFX.prefab.meta

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

62 changes: 58 additions & 4 deletions Assets/Scenes/WIP/AudioTestScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2562790482221263767, guid: c9bf6a9e0f8b04a49b050c870e2836f8, type: 3}
propertyPath: MusicTrack2
value:
objectReference: {fileID: 11400000, guid: 9b88bfe29001451418cce8880e694393, type: 2}
- target: {fileID: 4611095384279485090, guid: c9bf6a9e0f8b04a49b050c870e2836f8, type: 3}
propertyPath: m_Name
value: PlayBGM
Expand Down Expand Up @@ -333,10 +329,68 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c9bf6a9e0f8b04a49b050c870e2836f8, type: 3}
--- !u!1001 &7632763323000777513
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8666167773005286318, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9122669388108318780, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
propertyPath: m_Name
value: PlaySFX
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 22c91612358240c4182c6b18b2897e4d, type: 3}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- {fileID: 963194228}
- {fileID: 5195643990652047523}
- {fileID: 7240087349313893617}
- {fileID: 7632763323000777513}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 300fb8065a394e88bbfe59c3856aaad3, type: 3}
m_Name: BGM_CoCo
m_Name: BGMCoCo
m_EditorClassIdentifier:
Looping: 1
_audioClipGroups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 300fb8065a394e88bbfe59c3856aaad3, type: 3}
m_Name: BGM_Idol
m_Name: BGMIdol
m_EditorClassIdentifier:
Looping: 1
_audioClipGroups:
Expand Down
8 changes: 8 additions & 0 deletions Assets/ScriptableObjects/Audio/SFX.meta

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

30 changes: 30 additions & 0 deletions Assets/ScriptableObjects/Audio/SFX/SFXButtonClick.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 52c2d72f37834e9c843cd272363710d6, type: 3}
m_Name: SFXButtonClick
m_EditorClassIdentifier:
IsLooping: 0
_audioClipGroups:
- _mode: 0
_audioClips:
- m_AssetGUID: 57e6a45092a44fd49a197c3bc110b036
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
- m_AssetGUID: 15004dc56195a1443a5ff86164b3f446
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 1
- m_AssetGUID: a443a7258813b434d87bde43d326ed96
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 1
8 changes: 8 additions & 0 deletions Assets/ScriptableObjects/Audio/SFX/SFXButtonClick.asset.meta

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

11 changes: 11 additions & 0 deletions Assets/Scripts/Events/UnityActionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@ public static void SafeInvoke(this UnityAction action, string log = DEFAULT_LOG)

action.Invoke();
}

public static void SafeInvoke(this UnityAction action, params object[] args)
{
if (action == null)
{
Debug.LogWarning(DEFAULT_LOG);
return;
}

action.DynamicInvoke(args);
}
}
}
43 changes: 43 additions & 0 deletions Assets/Scripts/Events/UnityDelegateExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using UnityEngine;

namespace Long18.Events
{
public static class DelegateExtensions
{
private const string DEFAULT_LOG = "Event was raised but no one was listening.";

public static void SafeInvoke<T>(this Delegate action, T value, string log = DEFAULT_LOG)
{
if (action == null)
{
Debug.LogWarning(log);
return;
}

action.DynamicInvoke(value);
}

public static void SafeInvoke(this Delegate action, string log = DEFAULT_LOG)
{
if (action == null)
{
Debug.LogWarning(log);
return;
}

action.DynamicInvoke();
}

public static void SafeInvoke(this Delegate action, params object[] args)
{
if (action == null)
{
Debug.LogWarning(DEFAULT_LOG);
return;
}

action.DynamicInvoke(args);
}
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/Events/UnityDelegateExtensions.cs.meta

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

Loading

0 comments on commit af7ba59

Please sign in to comment.