using UnityEngine; using System; using System.Collections; using System.Collections.Generic; namespace AssetBundleMaster.Common { public abstract class Singleton where T : Singleton, new() { protected static T _instance; // instance reference public static bool Inited = false; /// /// Implict Create and get instance /// public static T Instance { get { return Create(); } } #region Interfaces // abstract method protected virtual void Initialize() { } protected virtual void UnInitialize() { } #endregion #region Main Funcs /// /// Explict Create and get instance /// /// public static T Create() { if (_instance == null) { _instance = new T(); _instance.InternalCreat(); } return _instance; } /// /// call uninit and release instance /// public static void Destroy() { if (_instance != null) { _instance.UnInitialize(); _instance = null; Inited = false; } } #endregion #region Help Funcs /// /// Internal Create /// private void InternalCreat() { if (_instance != null) { _instance.Initialize(); // must implement Inited = true; } } #endregion } }