Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Godot;
- public abstract class SingletonAutoLoad<T> : Node where T : Node
- {
- private static T instance;
- public static T Instance => instance;
- public override void _Ready()
- {
- if (instance != null)
- {
- GD.PrintErr("SingletonManager: " + typeof(T).Name + " already exists!");
- return;
- }
- instance = this as T;
- AfterInit();
- }
- public virtual void AfterInit()
- {
- }
- }
- public class ConcreteAutoLoadThing: SingletonAutoLoad<ConcreteAutoLoadThing>
- {
- public override void AfterInit()
- {
- // my ready logic without touching the singleton initialization
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement