Jeremy Smitherman 1523485fe2 feat/state (#2)
Reviewed-on: #2
Co-authored-by: Jeremy Smitherman <Jeremysmitherman@gmail.com>
Co-committed-by: Jeremy Smitherman <Jeremysmitherman@gmail.com>
2026-04-24 18:57:06 +00:00

39 lines
1.0 KiB
C#

using UnityEngine;
namespace Management
{
/// <summary>
/// Global access pattern for services.
/// If you need a component or some data that needs to be used in many places, here's a good spot.
/// </summary>
public class Services : MonoBehaviour
{
// Enforce singleton pattern
public static Services Instance { get; private set; }
// BGM service for playing/changing background music.
public BGM BGM => bgm;
// SFX service to serve as single spot SFX plays from.
public SFX SFX => sfx;
[SerializeField] private BGM bgm;
[SerializeField] private SFX sfx;
private void Awake()
{
// enforce singleton
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
// survive scene reloads
DontDestroyOnLoad(gameObject);
}
}
}