12345678910111213141516171819202122232425262728293031 |
- using System;
- namespace XRTool.Util
- {
- /// <summary>
- /// 基本的单例,不依附Unity
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public abstract class Singleton<T> where T :class, new()
- {
- private static T instance;
- private static readonly object syslock = new object();
- public static T Instance
- {
- get
- {
- //线程安全锁
- if (instance == null)
- {
- lock (syslock)
- {
- if (instance == null)
- {
- instance = new T();
- }
- }
- }
- return instance;
- }
- }
- }
- }
|