using UnityEngine;
/* 
Author: Jan Lygnos
Date:   14.06.2019
*/

/// <summary>
/// Generic scene independent singleton implementation.
/// </summary>
/// <typeparam name="T">the class to create a singleton from</typeparam>
public class SingletonDontDestroyOnLoad<T> : MonoBehaviour where T : SingletonDontDestroyOnLoad<T> {

    private static T instance;

    /// <summary>
    /// Accessor to singleton instance.
    /// </summary>
    public static T Instance {
        get => instance;
    }

    protected virtual void Awake() {
        if (!instance) {
            instance = (T)this;
            DontDestroyOnLoad(gameObject);
        } else {
            Destroy(gameObject);
        }
    }
}