-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
public class Singleton<T> where T : ISingeton
{
private static T mUniqueInstance;
public static bool Exists
{
get { return Singleton<T>.mUniqueInstance != null; }
}
public static T Instance
{
get
{
if (!Exists)
{
// Debug.Log("不存在,创建!");
Singleton<T>.mUniqueInstance = jsimp.Reflection.CreateInstance<T>();
//Activator.CreateInstance<T>();
}
// Debug.Log("创建后" + Singleton<T>.mUniqueInstance);
return Singleton<T>.mUniqueInstance;
}
}
static Singleton()
{
}
public Singleton()
{
if (Exists)
{
throw new InvalidOperationException("can not be instance like this");
}
}
public static void Release()
{
if (Exists)
{
Singleton<T>.mUniqueInstance.Clean();
Singleton<T>.mUniqueInstance = default(T);
}
}
}
public interface ISingeton
{
void Clean();
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels