You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
982 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HJDFrameWork
{
public class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>, new()
{
static T instance;
public static T Instance
{
get
{
if (instance == null)
{
GameObject go = new GameObject(typeof(T).Name);
instance = go.AddComponent<T>();
if (GameObject.Find("InstanceGroup") != null)
{
go.transform.SetParent(GameObject.Find("InstanceGroup").transform);
}
else
{
GameObject pearent = new GameObject("InstanceGroup");
go.transform.SetParent(pearent.transform);
}
}
return instance;
}
}
}
}