using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonoSingleton <T> : MonoBehaviour where T : MonoSingleton <T> {

	#region variables
	private static T _instance;
	#endregion


	#region getters and setters
	public static T Instance {
		get {
			return _instance;
		}
		set {
			_instance = value;
		}
	}
	#endregion


	#region events
	void Awake () {

		if (_instance == null) {
			Instance = this as T;
		} else {
			DestroyImmediate (this.gameObject);
		}

		AwakeEx ();

	}

	void OnDestroy () {

		OnDestroyEx ();
		Instance = null;
		
	}
	#endregion


	#region Methods
	protected virtual void AwakeEx () { }

	protected virtual void OnDestroyEx () { }
	#endregion
	
}
