|
@@ -5,6 +5,7 @@ using UnityEngine;
|
|
using KairoEngine.Core;
|
|
using KairoEngine.Core;
|
|
using KairoEngine.Core.ModuleSystem;
|
|
using KairoEngine.Core.ModuleSystem;
|
|
using Sirenix.OdinInspector;
|
|
using Sirenix.OdinInspector;
|
|
|
|
+using QFSW.MOP2;
|
|
|
|
|
|
namespace KairoEngine.SFX
|
|
namespace KairoEngine.SFX
|
|
{
|
|
{
|
|
@@ -16,7 +17,12 @@ namespace KairoEngine.SFX
|
|
[Tooltip("Use a custom sound emitter prefab or load the default prefab")]
|
|
[Tooltip("Use a custom sound emitter prefab or load the default prefab")]
|
|
[HorizontalGroup("@name/emitter", 0.015f), LabelText("Custom Sound Emitter")] public bool useCustomSoundEmitter;
|
|
[HorizontalGroup("@name/emitter", 0.015f), LabelText("Custom Sound Emitter")] public bool useCustomSoundEmitter;
|
|
[HorizontalGroup("@name/emitter", 0.985f), HideLabel, ShowIf("@useCustomSoundEmitter")] public GameObject soundEmitterPrefab;
|
|
[HorizontalGroup("@name/emitter", 0.985f), HideLabel, ShowIf("@useCustomSoundEmitter")] public GameObject soundEmitterPrefab;
|
|
|
|
+ [FoldoutGroup("@name"), Tooltip("Use the ObjectPool system so that sound emitters can be reused. This results in better overral performance. Requires the Object Pool Module to be installed.")]
|
|
|
|
+ public bool useObjectPooling = false;
|
|
|
|
+ [HorizontalGroup("@name/pool", 0.015f), LabelText("Custom Object Pool"), ShowIf("@useObjectPooling")] public bool useCustomPool;
|
|
|
|
+ [HorizontalGroup("@name/pool", 0.985f), HideLabel, ShowIf("@useCustomPool"), NonSerialized, ShowInInspector] public ObjectPool soundEmitterPool;
|
|
[FoldoutGroup("@name"), Tooltip("Optional sound library asset")] public SFXLibrary soundLibrary;
|
|
[FoldoutGroup("@name"), Tooltip("Optional sound library asset")] public SFXLibrary soundLibrary;
|
|
|
|
+ private SoundController soundController;
|
|
|
|
|
|
public SFXModule(GameConfig config) : base(config)
|
|
public SFXModule(GameConfig config) : base(config)
|
|
{
|
|
{
|
|
@@ -30,7 +36,7 @@ namespace KairoEngine.SFX
|
|
if(!useCustomSoundEmitter) soundEmitterPrefab = Resources.Load("SoundEmmiterPrefab") as GameObject;
|
|
if(!useCustomSoundEmitter) soundEmitterPrefab = Resources.Load("SoundEmmiterPrefab") as GameObject;
|
|
GameObject soundControllerPrefab = Resources.Load("SoundControllerPrefab") as GameObject;
|
|
GameObject soundControllerPrefab = Resources.Load("SoundControllerPrefab") as GameObject;
|
|
GameObject soundControllerObj = GameObject.Instantiate(soundControllerPrefab, parent);
|
|
GameObject soundControllerObj = GameObject.Instantiate(soundControllerPrefab, parent);
|
|
- SoundController soundController = soundControllerObj.GetComponent<SoundController>();
|
|
|
|
|
|
+ soundController = soundControllerObj.GetComponent<SoundController>();
|
|
if(soundController == null)
|
|
if(soundController == null)
|
|
{
|
|
{
|
|
Debug.LogError($"SoundControllerPrefab has no SoundController component", soundControllerObj);
|
|
Debug.LogError($"SoundControllerPrefab has no SoundController component", soundControllerObj);
|
|
@@ -41,6 +47,42 @@ namespace KairoEngine.SFX
|
|
soundControllerObj.name = "SoundController";
|
|
soundControllerObj.name = "SoundController";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public override void Start()
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ if(!useObjectPooling)
|
|
|
|
+ {
|
|
|
|
+ soundController._soundEmitterPool = "";
|
|
|
|
+ SoundController.soundEmitterPool = "";
|
|
|
|
+ soundEmitterPrefab.GetComponent<SoundEmitter>().soundEmitterPrefabPool = "";
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if(soundController == null) return;
|
|
|
|
+ soundController.soundEmitterPrefab = null;
|
|
|
|
+ if(soundEmitterPool == null) soundEmitterPool = Resources.Load("SoundEmitterPool") as ObjectPool;
|
|
|
|
+ if(soundEmitterPool == null)
|
|
|
|
+ {
|
|
|
|
+ Debug.LogError("Missing soundEmitterPool in SFX Module");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if(MasterObjectPooler.Instance == null)
|
|
|
|
+ {
|
|
|
|
+ Debug.LogError("The MasterObjectPooler component is not loaded. Add the Object Pool module in the game config to load it.");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ soundEmitterPrefab.GetComponent<SoundEmitter>().soundEmitterPrefabPool = soundEmitterPool.PoolName;
|
|
|
|
+ MasterObjectPooler.Instance.AddPool(soundEmitterPool.PoolName, soundEmitterPool);
|
|
|
|
+ soundController._soundEmitterPool = soundEmitterPool.PoolName;
|
|
|
|
+ SoundController.soundEmitterPool = soundEmitterPool.PoolName;
|
|
|
|
+ var pool = MasterObjectPooler.Instance.GetPool(soundEmitterPool.PoolName);
|
|
|
|
+ if(pool == null) Debug.LogError("Error configuring SFX pool.");
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ soundController._soundsParent = pool.ObjectParent.gameObject;
|
|
|
|
+ SoundController.soundsParent = pool.ObjectParent.gameObject;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public override void Reset()
|
|
public override void Reset()
|
|
{
|
|
{
|
|
|
|
|
|
@@ -67,11 +109,13 @@ namespace KairoEngine.SFX
|
|
public override void OnBeforeSerialize(ObjectSerializer serializer)
|
|
public override void OnBeforeSerialize(ObjectSerializer serializer)
|
|
{
|
|
{
|
|
if(soundEmitterPrefab != null) serializer.AddGameObject("SFXModule_soundEmitterPrefab", soundEmitterPrefab);
|
|
if(soundEmitterPrefab != null) serializer.AddGameObject("SFXModule_soundEmitterPrefab", soundEmitterPrefab);
|
|
|
|
+ if(soundEmitterPool != null) serializer.AddObject("SFXModule_soundEmitterPool", soundEmitterPool);
|
|
}
|
|
}
|
|
|
|
|
|
public override void OnBeforeDeserialize(ObjectSerializer serializer)
|
|
public override void OnBeforeDeserialize(ObjectSerializer serializer)
|
|
{
|
|
{
|
|
soundEmitterPrefab = serializer.GetGameObject("SFXModule_soundEmitterPrefab");
|
|
soundEmitterPrefab = serializer.GetGameObject("SFXModule_soundEmitterPrefab");
|
|
|
|
+ soundEmitterPool = (ObjectPool)serializer.GetObject("SFXModule_soundEmitterPool");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|