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 创建简单泛型单例
最新推荐文章于 2025-03-18 21:51:36 发布