欢迎光临散文网 会员登陆 & 注册

Unity - 单例模式实现

2022-07-21 20:54 作者:尘风一枚  | 我要投稿

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Singleton<T> : MonoBehaviour where T : Singleton<T>

{

public static T Instance { get; private set; }


private void Awake()

{

if (Instance == null)

{

Instance = (T) this;

DontDestroyOnLoad(gameObject);

}

else

{

Destroy(gameObject);

}

}

}

Unity - 单例模式实现的评论 (共 条)

分享到微博请遵守国家法律