The IKhom Sound System is an efficient sound management solution that supports object pooling. This system helps manage audio playback with minimal overhead, ensuring optimal performance for your Unity projects.
- Object pooling for sound emitters
- Configurable sound data with looping and mixer group support
- Easy-to-use API for sound management
- Random pitch adjustment for sound variations
- Logging for debugging and performance monitoring
To install the package, follow these steps:
- Open your Unity project.
- Open
Window > Package Manager
. - Click on the
+
button in the top left corner and selectAdd package from git URL...
. - Enter the following URL:
https://github.com/zloivan/sound-system.git
and clickAdd
.
- Add the
SoundManager
prefab to your scene. - Configure the
SoundManager
in the Inspector, setting the pool capacity and maximum pool size. - Get reference to SoundManager where you want to use sounds (inject or wrap it to singleton).
- Use provided Builder class to Play sounds, you need to provide it with SoundData instance
You can find that example in optional Samples.
Here is a basic example of how to use the SoundManager
and SoundEmitter
:
using UnityEngine;
using Utilities.SoundService.Runtime;
using Utilities.SoundService.Runtime.data;
public class SoundUserExample : MonoBehaviour
{
[SerializeField]
private SoundData _soundData;
[SerializeField]
private SoundData _ambient;
[SerializeField]
private SoundManager _soundManager;
[SerializeField]
private float _fireRate;
private double _lastFireTime;
private void Start()
{
_soundManager.CreateSound()
.WithSoundData(_ambient)
.Play();
}
private void Update()
{
if (!Input.GetKey(KeyCode.Space))
return;
if (!(Time.time > _lastFireTime + _fireRate))
return;
_lastFireTime = Time.time;
Fire();
}
private void Fire()
{
_soundManager.CreateSound()
.WithSoundData(_soundData)
.WithRandomPitch()
.Play();
}
}
To enable logs for this system, add new defined symbols in PlayerSettings.Other.Scripting Define Symbols
add DEBUG_SOUND_SERVICE
For detailed documentation and examples, please refer to the official documentation.
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes or improvements.