Unity 打印继承基类的子类名字

窗口基类

public class WindowRoot:MonoBehaviour
{
    private string currentClassName;

    public WindowRoot()
    {
        currentClassName = this.GetType().Name;
    }

    public virtual void InitWindow()
    {
        Debug.Log("初始化"+currentClassName+"...");
    }
}

继承的子类

public class A : WindowRoot
{
    // Start is called before the first frame update
    void Start()
    {
        InitWindow();
    }

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

打印 (初始化A...)

猜你喜欢

转载自blog.csdn.net/qq1084327456/article/details/128128482