创建和继承单例基类

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PoolMar : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

public class Student <T> where T:new()  
{
    public static T instance;

    public static T MyStudent() 
    {
        if (instance == null)
        {
            instance = new T();
        }

        return instance;
    }
}

public class Student1 :Student<Student1>
{

}

 

posted @ 2020-07-11 11:40  青梨  阅读(180)  评论(0编辑  收藏  举报