mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-23 12:33:02 +00:00
39 lines
824 B
C#
39 lines
824 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace SanAndreasUnity.Utilities
|
|
{
|
|
public class StartupSingleton<T> : MonoBehaviour
|
|
where T : StartupSingleton<T>
|
|
{
|
|
public static T Singleton { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (Singleton != null)
|
|
{
|
|
throw new Exception($"Awake() method called twice for singleton of type {this.GetType().Name}");
|
|
}
|
|
|
|
Singleton = (T) this;
|
|
|
|
this.OnSingletonAwake();
|
|
}
|
|
|
|
protected virtual void OnSingletonAwake()
|
|
{
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (this != Singleton)
|
|
return;
|
|
|
|
this.OnSingletonStart();
|
|
}
|
|
|
|
protected virtual void OnSingletonStart()
|
|
{
|
|
}
|
|
}
|
|
}
|