Singleton.cs 875 B

123456789101112131415161718192021222324
  1. #if UNITY_EDITOR
  2. namespace O3DWB
  3. {
  4. public abstract class Singleton<DataType> where DataType : Singleton<DataType>, new()
  5. {
  6. #region Private Static Variables
  7. /// <summary>
  8. /// The singleton instance.
  9. /// </summary>
  10. /// <remarks>
  11. /// Note: This assumes that the derived class must always have a public parameterless constructor.
  12. /// This implies that the client code can create instances of the derived classes. We could
  13. /// solve this using reflection, but in order to keep things simple and clean, we will avoid
  14. /// doing that.
  15. /// </remarks>
  16. private static DataType _instance = new DataType();
  17. #endregion
  18. #region Public Static Properties
  19. public static DataType Instance { get { return _instance; } }
  20. #endregion
  21. }
  22. }
  23. #endif