41 lines
1.1 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;
public InputRouter InputRouter => inputRouter;
[SerializeField] private BGM bgm;
[SerializeField] private SFX sfx;
[SerializeField] private InputRouter inputRouter;
private void Awake()
{
// enforce singleton
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
// survive scene reloads
DontDestroyOnLoad(gameObject);
}
}
}