feat: audio management/playback features
Every sound in the game is now a ManageableAudio prefab. The prefabs are picked up in an audio library automatically and other game objects can get the sound they need from the AudioManager. They obtain a ManageableAudio instance which offers various methods to interact with the AudioSource. Depending on how they request the ManageableAudio, the AudioSource is attached to the requesting GameObject, to the Scene or the global management Scene. This provides options to play sounds spatially, globally and scene independent. The prefabs are identified by a tag and an ID, so it is easy to swap out sounds globally, by just replacing the prefab.
This commit is contained in:
parent
6f8b9fde9f
commit
5a658d6cd4
8
Assets/Models/Materials.meta
Normal file
8
Assets/Models/Materials.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d058681f956108945a5e0a77ccaca7ae
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
132
Assets/Models/Materials/defaultMat.mat
Normal file
132
Assets/Models/Materials/defaultMat.mat
Normal file
@ -0,0 +1,132 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &-7783281861020253796
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
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: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 7
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: defaultMat
|
||||
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _AlphaToMask: 0
|
||||
- _Blend: 0
|
||||
- _BlendModePreserveSpecular: 1
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _DstBlendAlpha: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.005
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _SrcBlendAlpha: 1
|
||||
- _Surface: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 0.8, g: 0.8, b: 0.8, a: 1}
|
||||
- _Color: {r: 0.8, g: 0.8, b: 0.8, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
8
Assets/Models/Materials/defaultMat.mat.meta
Normal file
8
Assets/Models/Materials/defaultMat.mat.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d8d9f678971ac94f80eb9849d414cc5
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -62,7 +62,7 @@ AudioSource:
|
||||
OutputAudioMixerGroup: {fileID: 0}
|
||||
m_audioClip: {fileID: 8300000, guid: f03afcd094e19824e8549f6fec3655ef, type: 3}
|
||||
m_PlayOnAwake: 0
|
||||
m_Volume: 0.2
|
||||
m_Volume: 0.092
|
||||
m_Pitch: 0.95
|
||||
Loop: 1
|
||||
Mute: 0
|
||||
@ -71,7 +71,7 @@ AudioSource:
|
||||
Priority: 128
|
||||
DopplerLevel: 0
|
||||
MinDistance: 1
|
||||
MaxDistance: 500
|
||||
MaxDistance: 100
|
||||
Pan2D: 0
|
||||
rolloffMode: 1
|
||||
BypassEffects: 0
|
||||
|
||||
@ -45,11 +45,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 887650ff1f3850a43aa8d1281fc70528, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
maxParallel: 4
|
||||
id: 1
|
||||
audioTag: music
|
||||
audioSource: {fileID: 7696877450501702533}
|
||||
audioSources: []
|
||||
audioTag: sound
|
||||
--- !u!82 &7696877450501702533
|
||||
AudioSource:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -62,7 +59,7 @@ AudioSource:
|
||||
OutputAudioMixerGroup: {fileID: 0}
|
||||
m_audioClip: {fileID: 8300000, guid: 82a8d17c2698c834f96370756847edec, type: 3}
|
||||
m_PlayOnAwake: 0
|
||||
m_Volume: 0.2
|
||||
m_Volume: 0.112
|
||||
m_Pitch: 0.95
|
||||
Loop: 1
|
||||
Mute: 0
|
||||
@ -106,7 +103,7 @@ AudioSource:
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
|
||||
@ -10,8 +10,9 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 4498597859498223686}
|
||||
- component: {fileID: 4421901766771881742}
|
||||
- component: {fileID: -2235839436850680582}
|
||||
m_Layer: 0
|
||||
m_Name: AVEffectsManager
|
||||
m_Name: AudioManager
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@ -45,3 +46,17 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
audioLibrary: {fileID: 3600236761918540295, guid: 205eaed4caed63646b0c053361d7ed04, type: 3}
|
||||
--- !u!114 &-2235839436850680582
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1668925289118893306}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0bceda0769741041bf8f466bee87e01, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
audios: []
|
||||
manageableAudioFolder: Assets/Prefabs/Audio
|
||||
@ -503,7 +503,7 @@ MonoBehaviour:
|
||||
MatchManager: {fileID: 5376598442414673498, guid: ab53d1c11aaff9a4680d8265bada73b6, type: 3}
|
||||
StatisticsManager: {fileID: -4248400137136794068, guid: 602e864eae420734599caa76d056f5c5, type: 3}
|
||||
PlayerManager: {fileID: 4324267968298468629, guid: bf1ba420952f8cd4e8e6e02554c13bac, type: 3}
|
||||
AVEffectsManager: {fileID: 4421901766771881742, guid: d2fa91ae61bbe6644b3847b83f0f21fb, type: 3}
|
||||
AudioManager: {fileID: 4421901766771881742, guid: d2fa91ae61bbe6644b3847b83f0f21fb, type: 3}
|
||||
startCamera: {fileID: 1164443743}
|
||||
--- !u!1660057539 &9223372036854775807
|
||||
SceneRoots:
|
||||
|
||||
15
Assets/ScriptedAssets/AudioLibrary.asset
Normal file
15
Assets/ScriptedAssets/AudioLibrary.asset
Normal file
@ -0,0 +1,15 @@
|
||||
%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: d0bceda0769741041bf8f466bee87e01, type: 3}
|
||||
m_Name: AudioLibrary
|
||||
m_EditorClassIdentifier:
|
||||
audios: []
|
||||
8
Assets/ScriptedAssets/AudioLibrary.asset.meta
Normal file
8
Assets/ScriptedAssets/AudioLibrary.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09be763b286b985409e3cbcdba2d8bc7
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,7 +1,44 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioLibrary : MonoBehaviour
|
||||
{
|
||||
public List<ManagableAudio> audios;
|
||||
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
public List<GameObject> audios;
|
||||
public string manageableAudioFolder = "Assets/Prefabs/Audio";
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
LoadAvailableSounds();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads all the ManageableAudio prefabs from the specified folder.
|
||||
/// </summary>
|
||||
private void LoadAvailableSounds()
|
||||
{
|
||||
string[] files = Directory.GetFiles(manageableAudioFolder, "*.prefab",
|
||||
SearchOption.TopDirectoryOnly);
|
||||
List<GameObject> gos = new List<GameObject>();
|
||||
foreach (var file in files)
|
||||
{
|
||||
gos.Add(AssetDatabase.LoadAssetAtPath<GameObject>(file));
|
||||
}
|
||||
foreach (GameObject go in gos)
|
||||
{
|
||||
if (go.TryGetComponent<ManageableAudio>(out _))
|
||||
{
|
||||
audios.Add(go);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("Audio library can only load prefabs with ManageableAudio components!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using UnityEngine;
|
||||
|
||||
public class ManagableAudio : MonoBehaviour
|
||||
{
|
||||
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
[SerializeField]
|
||||
private int maxParallel = 1;
|
||||
public int id = 0;
|
||||
public string audioTag = "audio";
|
||||
public AudioSource audioSource;
|
||||
|
||||
[HideInInspector]
|
||||
public List<AudioSource> audioSources;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (gameObject.TryGetComponent(out AudioSource audioS))
|
||||
{
|
||||
audioSource = audioS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("Managable Audio Instance hasn't got an audio source game object"
|
||||
+ $". Tag:{audioTag} ID:{id}");
|
||||
return;
|
||||
}
|
||||
audioSources.Add(audioSource);
|
||||
BuildAudioSourceList();
|
||||
}
|
||||
|
||||
private void BuildAudioSourceList()
|
||||
{
|
||||
while (audioSources.Count < maxParallel)
|
||||
{
|
||||
var newAS = Instantiate(audioSource);
|
||||
audioSources.Add(newAS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
67
Assets/Scripts/ManageableAudio.cs
Normal file
67
Assets/Scripts/ManageableAudio.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using PrimeTween;
|
||||
using UnityEngine;
|
||||
|
||||
public class ManageableAudio : MonoBehaviour
|
||||
{
|
||||
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
public int id = 0;
|
||||
public string audioTag = "audio";
|
||||
public AudioSource AudioSource { get; set; }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (gameObject.TryGetComponent(out AudioSource audioS))
|
||||
{
|
||||
AudioSource = audioS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("Managable Audio Instance hasn't got an audio source game object"
|
||||
+ $". Tag:{audioTag} ID:{id}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayAudio()
|
||||
{
|
||||
if (AudioSource == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!AudioSource.enabled)
|
||||
{
|
||||
AudioSource.enabled = true;
|
||||
}
|
||||
AudioSource.Play();
|
||||
}
|
||||
|
||||
public void StopAudio()
|
||||
{
|
||||
if (AudioSource == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (AudioSource.isPlaying)
|
||||
{
|
||||
AudioSource.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void FadeOutAudio(float duration = 1)
|
||||
{
|
||||
float initVolume = AudioSource.volume;
|
||||
Tween.Custom(initVolume, 0, duration, onValueChange: value => AudioSource.volume = value)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
StopAudio();
|
||||
AudioSource.volume = initVolume;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
public class AVEffectsManager : MonoBehaviour
|
||||
{
|
||||
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
public static AVEffectsManager G { get; private set; }
|
||||
|
||||
[HideInInspector]
|
||||
public AudioLibrary audioLibrary;
|
||||
|
||||
private AudioSource centralAudioSource;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
G = this;
|
||||
Log.Info("Awake");
|
||||
if (gameObject.TryGetComponent(out AudioLibrary al))
|
||||
{
|
||||
audioLibrary = al;
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(audioLibrary == null){
|
||||
return;
|
||||
}
|
||||
centralAudioSource = audioLibrary.audios.First(a => a.tag == "music")?.audioSource;
|
||||
if(centralAudioSource != null)
|
||||
centralAudioSource.Play();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum Music
|
||||
{
|
||||
|
||||
}
|
||||
192
Assets/Scripts/Managers/AudioManager.cs
Normal file
192
Assets/Scripts/Managers/AudioManager.cs
Normal file
@ -0,0 +1,192 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
public static AudioManager G { get; private set; }
|
||||
|
||||
[HideInInspector]
|
||||
public AudioLibrary audioLibrary;
|
||||
|
||||
private Dictionary<ManageableAudio, GameObject> audioDictionary =
|
||||
new Dictionary<ManageableAudio, GameObject>();
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
G = this;
|
||||
Log.Info("Awake");
|
||||
if (gameObject.TryGetComponent(out AudioLibrary al))
|
||||
{
|
||||
audioLibrary = al;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("There is no audio library component in the AudioManager. There will be no sound.");
|
||||
}
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
if (audioLibrary == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
audioDictionary = ReadLibrary(audioLibrary);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a sound from the library which will be used for global and
|
||||
/// scene independent sound.
|
||||
/// </summary>
|
||||
/// <param name="prefabName">Name of the sound prefab</param>
|
||||
/// <param name="dependsOnScene">Should the audio be destroyed, when the calling scene is destroyed?</param>
|
||||
/// <returns>ManageableAudio instance to control the playback with.</returns>
|
||||
public ManageableAudio GetGlobalSoundByName(string prefabName, bool dependsOnScene = false)
|
||||
{
|
||||
return GetGlobalSound(null, -1, false, SearchSound(null, -1, prefabName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a sound from the library which will be used for local, spatial and
|
||||
/// scene dependent sound. It reparents the object(AudioSource + ManageableAudio component),
|
||||
/// to the provided transform.
|
||||
/// </summary>
|
||||
/// <param name="prefabName">Name of the sound prefab</param>
|
||||
/// <param name="transform">Transform which will parent the sound object.</param>
|
||||
/// <returns>ManageableAudio instance to control the playback with.</returns>
|
||||
public ManageableAudio GetLocalSoundByName(string prefabName, Transform transform)
|
||||
{
|
||||
return GetLocalSound(null, -1, transform, SearchSound(null, -1, prefabName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a sound from the library which will be used for global sound.
|
||||
/// TODO: Only makes sense, if requested prefab has 0 spatial value.
|
||||
/// </summary>
|
||||
/// <param name="audioTag">Tag of the sound</param>
|
||||
/// <param name="id">ID of the sound</param>
|
||||
/// <param name="dependsOnScene">Should the audio be destroyed, when the calling scene is destroyed?</param>
|
||||
/// <param name="go">Optionally provide the sound GameObject directly.</param>
|
||||
/// <returns>ManageableAudio instance to control the playback with.</returns>
|
||||
public ManageableAudio GetGlobalSound(string audioTag, int id, bool dependsOnScene = false,
|
||||
GameObject go = null)
|
||||
{
|
||||
GameObject sound;
|
||||
if (go == null)
|
||||
{
|
||||
sound = SearchSound(audioTag, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
sound = go;
|
||||
}
|
||||
|
||||
if (sound == null)
|
||||
{
|
||||
Log.Warn($"Requested sound: {audioTag}_{id} was not in the audio library.");
|
||||
return null;
|
||||
}
|
||||
sound = Instantiate(sound);
|
||||
if (!dependsOnScene)
|
||||
sound.transform.SetParent(gameObject.transform);
|
||||
if (sound.TryGetComponent(out ManageableAudio ma))
|
||||
{
|
||||
return ma;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn($"Prefab for sound: {audioTag}_{id} contained no ManageableAudio component");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a sound from the library which will be used for local, spatial and
|
||||
/// scene dependent sound. It reparents the object(AudioSource + ManageableAudio component),
|
||||
/// to the provided transform.
|
||||
/// </summary>
|
||||
/// <param name="audioTag">Tag of the sound</param>
|
||||
/// <param name="id">ID of the sound</param>
|
||||
/// <param name="newParent">Transform which will parent the sound object.</param>
|
||||
/// <param name="go"> Optionally provide the sound GameObject directly.</param>
|
||||
/// <returns>ManageableAudio instance to control the playback with.</returns>
|
||||
public ManageableAudio GetLocalSound(string audioTag, int id, Transform newParent,
|
||||
GameObject go = null)
|
||||
{
|
||||
GameObject sound;
|
||||
if (go == null)
|
||||
{
|
||||
sound = SearchSound(audioTag, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
sound = go;
|
||||
}
|
||||
|
||||
if (sound == null)
|
||||
{
|
||||
Log.Warn($"Requested sound: {audioTag}_{id} was not in the audio library.");
|
||||
return null;
|
||||
}
|
||||
sound = Instantiate(sound);
|
||||
sound.transform.SetParent(newParent, false);
|
||||
|
||||
if (sound.TryGetComponent(out ManageableAudio ma))
|
||||
{
|
||||
return ma;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn($"Prefab for sound: {audioTag}_{id} contained no ManageableAudio component");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// There are sounds which are scene independent and always global -> will continue playing even if the scene invoking is destroyed
|
||||
// -"- scene dependent and global -> will play globally but when the scene is destroyed they will be also destroyed
|
||||
// -"- scene dependent and local -> will play spatially from a object and be destroyed when the scene is destroyed
|
||||
|
||||
//
|
||||
|
||||
Dictionary<ManageableAudio, GameObject> ReadLibrary(AudioLibrary al)
|
||||
{
|
||||
Dictionary<ManageableAudio, GameObject> audioDictionary =
|
||||
new Dictionary<ManageableAudio, GameObject>();
|
||||
foreach (GameObject go in al.audios)
|
||||
{
|
||||
if (go.TryGetComponent(out ManageableAudio ma))
|
||||
{
|
||||
audioDictionary.Add(ma, go);
|
||||
}
|
||||
}
|
||||
return audioDictionary;
|
||||
}
|
||||
|
||||
private GameObject SearchSound(string audioTag = null, int id = -1,
|
||||
string prefabName = null)
|
||||
{
|
||||
if (prefabName == null)
|
||||
{
|
||||
return audioDictionary.
|
||||
Where(manageableAudio => manageableAudio.Key.audioTag == audioTag).
|
||||
First(manageableAudio => manageableAudio.Key.id == id).Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return audioDictionary.
|
||||
First(manageableAudio => manageableAudio.Value.name == prefabName).Value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -50,7 +50,7 @@ namespace Managers
|
||||
[SerializeField]
|
||||
private PlayerManager PlayerManager;
|
||||
[SerializeField]
|
||||
private AVEffectsManager AVEffectsManager;
|
||||
private AudioManager AudioManager;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject startCamera;
|
||||
@ -135,9 +135,9 @@ namespace Managers
|
||||
{
|
||||
Log.Error("PlayerManager Manager Prefab missing.");
|
||||
}
|
||||
if (AVEffectsManager != null)
|
||||
if (AudioManager != null)
|
||||
{
|
||||
AVEffectsManager = Instantiate(AVEffectsManager);
|
||||
AudioManager = Instantiate(AudioManager);
|
||||
Log.Info("PlayerManager Manager instantiated.");
|
||||
}
|
||||
else
|
||||
|
||||
@ -25,6 +25,8 @@ public class Ship : MonoBehaviour
|
||||
// Current Zone the player occupies
|
||||
private Zone zone = Zone.NimbleZone;
|
||||
|
||||
private ManageableAudio ThrusterSound;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (forceManager == null)
|
||||
@ -33,6 +35,7 @@ public class Ship : MonoBehaviour
|
||||
GetComponent<AffectingForcesManager>();
|
||||
}
|
||||
body = GetComponent<Rigidbody>();
|
||||
ThrusterSound = AudioManager.G.GetLocalSound("sound", 1, gameObject.transform);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
@ -92,6 +95,17 @@ public class Ship : MonoBehaviour
|
||||
/// </summary>
|
||||
void UpdateMovement()
|
||||
{
|
||||
if (state.thrustInput > 0)
|
||||
{
|
||||
if (!ThrusterSound.AudioSource.isPlaying)
|
||||
{
|
||||
ThrusterSound.PlayAudio();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrusterSound.StopAudio();
|
||||
}
|
||||
|
||||
//Debug.Log("inupdatemove " + currentThrustInput);
|
||||
// Player rotation is always possible and same speed
|
||||
|
||||
@ -18,6 +18,7 @@ namespace SlimUI.ModernMenu
|
||||
private Animator CameraObject;
|
||||
private event EventHandler<SceneLoadEventArgs> CustomSceneLoaded;
|
||||
private GameManager GM;
|
||||
private ManageableAudio MainMenuMusic;
|
||||
|
||||
// campaign button sub menu
|
||||
[Header("MENUS")]
|
||||
@ -99,6 +100,8 @@ namespace SlimUI.ModernMenu
|
||||
firstMenu.SetActive(true);
|
||||
// Position1();
|
||||
SetThemeColors();
|
||||
MainMenuMusic = AudioManager.G.GetGlobalSound("music", 1, true);
|
||||
MainMenuMusic.PlayAudio();
|
||||
}
|
||||
|
||||
void SetThemeColors()
|
||||
@ -215,6 +218,7 @@ namespace SlimUI.ModernMenu
|
||||
/// <returns>IEnumerator for async statemachine</returns>
|
||||
private IEnumerator SwitchToIngameUI()
|
||||
{
|
||||
MainMenuMusic.FadeOutAudio(2);
|
||||
AsyncOperation o = SceneManager.LoadSceneAsync((int)Scenes.GameplayUserInterface,
|
||||
LoadSceneMode.Additive);
|
||||
|
||||
|
||||
@ -3,16 +3,16 @@
|
||||
"com.kyrylokuzyk.primetween": "file:../Assets/Plugins/PrimeTween/internal/com.kyrylokuzyk.primetween.tgz",
|
||||
"com.unity.adaptiveperformance": "5.0.2",
|
||||
"com.unity.cloud.gltfast": "6.0.1",
|
||||
"com.unity.collab-proxy": "2.2.0",
|
||||
"com.unity.collab-proxy": "2.3.1",
|
||||
"com.unity.feature.development": "1.0.1",
|
||||
"com.unity.ide.visualstudio": "2.0.22",
|
||||
"com.unity.inputsystem": "1.6.3",
|
||||
"com.unity.postprocessing": "3.2.2",
|
||||
"com.unity.render-pipelines.universal": "14.0.8",
|
||||
"com.unity.textmeshpro": "3.0.7",
|
||||
"com.unity.inputsystem": "1.7.0",
|
||||
"com.unity.postprocessing": "3.4.0",
|
||||
"com.unity.render-pipelines.universal": "14.0.10",
|
||||
"com.unity.textmeshpro": "3.0.8",
|
||||
"com.unity.timeline": "1.7.6",
|
||||
"com.unity.ugui": "1.0.0",
|
||||
"com.unity.visualscripting": "1.8.0",
|
||||
"com.unity.visualscripting": "1.9.2",
|
||||
"com.unity.modules.ai": "1.0.0",
|
||||
"com.unity.modules.androidjni": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
|
||||
@ -16,11 +16,12 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.burst": {
|
||||
"version": "1.8.7",
|
||||
"version": "1.8.13",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.mathematics": "1.2.1"
|
||||
"com.unity.mathematics": "1.2.1",
|
||||
"com.unity.modules.jsonserialize": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
@ -37,7 +38,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.collab-proxy": {
|
||||
"version": "2.2.0",
|
||||
"version": "2.3.1",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
@ -62,17 +63,17 @@
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.ide.visualstudio": "2.0.18",
|
||||
"com.unity.ide.rider": "3.0.24",
|
||||
"com.unity.ide.visualstudio": "2.0.22",
|
||||
"com.unity.ide.rider": "3.0.28",
|
||||
"com.unity.ide.vscode": "1.2.5",
|
||||
"com.unity.editorcoroutines": "1.0.0",
|
||||
"com.unity.performance.profile-analyzer": "1.2.2",
|
||||
"com.unity.test-framework": "1.1.33",
|
||||
"com.unity.testtools.codecoverage": "1.2.4"
|
||||
"com.unity.testtools.codecoverage": "1.2.5"
|
||||
}
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
"version": "3.0.24",
|
||||
"version": "3.0.28",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -97,7 +98,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.inputsystem": {
|
||||
"version": "1.6.3",
|
||||
"version": "1.7.0",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -120,7 +121,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.postprocessing": {
|
||||
"version": "3.2.2",
|
||||
"version": "3.4.0",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -136,7 +137,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.render-pipelines.core": {
|
||||
"version": "14.0.8",
|
||||
"version": "14.0.10",
|
||||
"depth": 1,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
@ -147,14 +148,23 @@
|
||||
}
|
||||
},
|
||||
"com.unity.render-pipelines.universal": {
|
||||
"version": "14.0.8",
|
||||
"version": "14.0.10",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.mathematics": "1.2.1",
|
||||
"com.unity.burst": "1.8.4",
|
||||
"com.unity.render-pipelines.core": "14.0.8",
|
||||
"com.unity.shadergraph": "14.0.8"
|
||||
"com.unity.burst": "1.8.9",
|
||||
"com.unity.render-pipelines.core": "14.0.10",
|
||||
"com.unity.shadergraph": "14.0.10",
|
||||
"com.unity.render-pipelines.universal-config": "14.0.9"
|
||||
}
|
||||
},
|
||||
"com.unity.render-pipelines.universal-config": {
|
||||
"version": "14.0.9",
|
||||
"depth": 1,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.render-pipelines.core": "14.0.9"
|
||||
}
|
||||
},
|
||||
"com.unity.searcher": {
|
||||
@ -172,11 +182,11 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.shadergraph": {
|
||||
"version": "14.0.8",
|
||||
"version": "14.0.10",
|
||||
"depth": 1,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.render-pipelines.core": "14.0.8",
|
||||
"com.unity.render-pipelines.core": "14.0.10",
|
||||
"com.unity.searcher": "4.9.2"
|
||||
}
|
||||
},
|
||||
@ -192,7 +202,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.testtools.codecoverage": {
|
||||
"version": "1.2.4",
|
||||
"version": "1.2.5",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -202,7 +212,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.textmeshpro": {
|
||||
"version": "3.0.7",
|
||||
"version": "3.0.8",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -232,7 +242,7 @@
|
||||
}
|
||||
},
|
||||
"com.unity.visualscripting": {
|
||||
"version": "1.8.0",
|
||||
"version": "1.9.2",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
m_EditorVersion: 2022.3.5f1
|
||||
m_EditorVersionWithRevision: 2022.3.5f1 (9674261d40ee)
|
||||
m_EditorVersion: 2022.3.23f1
|
||||
m_EditorVersionWithRevision: 2022.3.23f1 (dbb3f7c5b5c6)
|
||||
|
||||
@ -12,5 +12,6 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: de02f9e1d18f588468e474319d09a723, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
shaderVariantLimit: 128
|
||||
customInterpolatorErrorThreshold: 32
|
||||
customInterpolatorWarningThreshold: 16
|
||||
|
||||
Loading…
Reference in New Issue
Block a user