SanAndreasUnity/Assets/Scripts/Utilities/StartupSingleton.cs

17 lines
510 B
C#
Raw Normal View History

using UnityEngine.SceneManagement;
namespace SanAndreasUnity.Utilities
2021-09-06 22:04:15 +00:00
{
2022-01-21 00:35:36 +00:00
public class StartupSingleton<T> : SingletonComponent<T>
2021-09-06 22:04:15 +00:00
where T : StartupSingleton<T>
{
protected override void OnSingletonAwakeValidate()
{
Scene activeScene = SceneManager.GetActiveScene();
if (!activeScene.IsValid() || activeScene.buildIndex != 0)
throw new System.Exception("Startup singleton can only be initialized in startup scene");
}
2021-09-06 22:04:15 +00:00
}
}