WKLib 0.2.3
A modding library for White Knuckle
Loading...
Searching...
No Matches
MonoSingleton.cs
Go to the documentation of this file.
1using UnityEngine;
2
3namespace WKLib.Core.Classes;
4
5[DefaultExecutionOrder(-200)]
6internal abstract class MonoSingleton : MonoBehaviour { }
7
8internal abstract class MonoSingleton<T> : MonoSingleton where T : MonoSingleton<T>
9{
10 private static T instance = null;
11
12 public static T Instance
13 {
14 get => instance;
15 set => instance = value;
16 }
17
18 public virtual void Awake()
19 {
20 if (Instance && Instance != this)
21 {
22 Destroy(this);
23 }
24 else
25 {
26 Instance = (T)this;
27 }
28 }
29
30 public virtual void OnEnable()
31 {
32 Instance = (T)this;
33 }
34}