﻿using UnityEngine;

namespace Toast.SmartDownloader.Example
{
    public abstract class MonoSingleton<ThisType> : MonoBehaviour where ThisType : MonoBehaviour
    {
        protected static MonoBehaviour _instance;
        public static ThisType Instance { get { return (ThisType)_instance; } }

        protected virtual void Awake()
        {
            if (_instance == null)
            {
                _instance = this;
            }
            else
            {
                Debug.LogErrorFormat("Already assigned a instance");
            }

            OnAwake();
        }

        protected abstract void OnAwake();
    }
}