60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Reflection;
|
|||
|
using UnityEngine;
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD> <20><>ҪĿ<D2AA><C4BF><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
/// <typeparam name="T"></typeparam>
|
|||
|
public abstract class BaseManager<T> where T:class//,new()
|
|||
|
{
|
|||
|
private static T instance;
|
|||
|
|
|||
|
//<2F>жϵ<D0B6><CFB5><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD> <20>Ƿ<EFBFBD>Ϊnull
|
|||
|
protected bool InstanceisNull => instance == null;
|
|||
|
|
|||
|
//<2F><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
|
|||
|
protected static readonly object lockObj = new object();
|
|||
|
|
|||
|
//<2F><><EFBFBD>Եķ<D4B5>ʽ
|
|||
|
public static T Instance
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if(instance == null)
|
|||
|
{
|
|||
|
lock (lockObj)
|
|||
|
{
|
|||
|
if (instance == null)
|
|||
|
{
|
|||
|
//instance = new T();
|
|||
|
//<2F><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>˽<EFBFBD>еĹ<D0B5><C4B9>캯<EFBFBD><ECBAAF> <20><><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>
|
|||
|
Type type = typeof(T);
|
|||
|
ConstructorInfo info = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic,
|
|||
|
null,
|
|||
|
Type.EmptyTypes,
|
|||
|
null);
|
|||
|
if (info != null)
|
|||
|
instance = info.Invoke(null) as T;
|
|||
|
else
|
|||
|
Debug.LogError("û<>еõ<D0B5><C3B5><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ι<DEB2><CEB9>캯<EFBFBD><ECBAAF>");
|
|||
|
|
|||
|
//instance = Activator.CreateInstance(typeof(T), true) as T;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return instance;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>ʽ
|
|||
|
//public static T GetInstance()
|
|||
|
//{
|
|||
|
// if (instance == null)
|
|||
|
// instance = new T();
|
|||
|
// return instance;
|
|||
|
//}
|
|||
|
}
|