泛型单例

来源:互联网 发布:js除法取整不四舍五入 编辑:程序博客网 时间:2024/06/02 05:03
using System.Collections;using System.Collections.Generic;using UnityEngine;public class MonoSlingleton<T> : MonoBehaviour    where T : Component{    private static T t;    public static T insitance    {        get        {            if (t == null)                t = GameObject.FindObjectOfType                    (typeof(T)) as T;            if (t == null)            {                GameObject go = new GameObject();                t = go.AddComponent<T>();                go.name = t.name;                DontDestroyOnLoad(go);            }            return t;        }    }    public virtual void Init()    {    }}
原创粉丝点击