using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//创建泛型单例
//在unity中所有类型的组件都基于基类Component基类,所以定义泛型范围为Component
public class Singleton<T> : MonoBehaviour where T : Component
{
public static T Instance { get; private set; }
protected virtual void Awake()
{
Instance = this as T;
//切换场景是否销毁
//DontDestroyOnLoad(this);
}
}
Unity 创建简单泛型单例
最新推荐文章于 2024-08-30 06:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)