当前位置:网站首页>Unity MonoSingleton
Unity MonoSingleton
2022-06-11 04:21:00 【Sea moon】
using UnityEngine;
public class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
{
private static T instance;
public static T Instance
{
get
{
if (instance == null)
{
// Find existing instances
instance = (T)FindObjectOfType(typeof(T));
// If there is no instance , Create
if (instance == null)
{
// You need to create a GameObject , Then mount the singleton component to the game object
var singletonObject = new GameObject();
instance = singletonObject.AddComponent<T>();
singletonObject.name = typeof(T).ToString() + " (Singleton)";
// Let the instance not be destroyed when switching scenes
DontDestroyOnLoad(singletonObject);
}
}
return instance;
}
}
}边栏推荐
- Eth Of Erc20 And Erc721
- JVM(1):介绍、结构、运行和生命周期
- 数据类型的转换和条件控制语句
- JVM(4):类的主动使用与被动使用、运行时数据区域内部结构、JVM线程说明、PC寄存器
- Guanghetong launched a new generation of 3GPP R16 industrial 5g module fg160 engineering sample
- Guanghetong 5g module fg650-cn and fm650-cn series are produced in full scale, accelerating the efficient implementation of 5g UWB applications
- Vulkan-官方示例解读-Shadows(光栅化)
- 数字电影的KDM是什么?
- June 10, 2022: Captain Shu crosses a sweet potato field from north to South (m long from north to South and N wide from east to West). The sweet potato field is divided into 1x1 squares. He can start
- JVM (6): slot variable slot, operand stack, code trace, stack top cache technology
猜你喜欢

The live broadcast helped Hangzhou e-commerce Unicorn impact the listing, and the ledger system restructured the new pattern of e-commerce transactions

Esp32 development -lvgl uses internal and external fonts

MySQL stored procedure

JVM (4): active and passive use of classes, internal structure of runtime data area, JVM thread description, PC register

Guanghetong LTE Cat4 module l716 is upgraded to provide affordable and universal wireless applications for the IOT industry

Guanghetong successfully won the bidding for China Unicom Yanfei CAT1 customized module with the largest share

Product milestones in May 2022

It's 2022. When will the "module freedom" be realized?

七个好用的装饰器

A Security Analysis Of Browser Extensions
随机推荐
Safe and borderless, Guanghe tongdai 5g module +ai intelligent security solution shines at CPSE Expo
Feature selection algorithm based on bare bones particleswarm optimization
Market prospect analysis and Research Report of beam combiner in 2022
[server data recovery] data recovery case of RAID5 crash of buddy storage
Vulkan official example interpretation raytracing
A Security Analysis Of Browser Extensions
Market prospect analysis and Research Report of single photon counting detector in 2022
Red team shooting range with three-layer protection
JVM(1):介绍、结构、运行和生命周期
Eth Transfer
从初代播种到落地生花,5G商用三周年“催生万物”
Product milestones in May 2022
你知道MallBook分账与银行分账的区别吗?
Esp32 development -lvgl display picture
2022-06-10:薯队长从北向南穿过一片红薯地(南北长M,东西宽N),红薯地被划分为1x1的方格, 他可以从北边的任何一个格子出发,到达南边的任何一个格子, 但每一步只能走到东南、正南、西南方向的
【CustomView】Glide+BitmapTransformation 图片上下边框波浪处理(WaveTransformation)
使用工具类按一定规则读取Excel文件
The future has come and the 5g advanced era has begun
游戏数学: 计算屏幕点中的平面上的点(上帝视角)
JVM (1): introduction, structure, operation and lifecycle