信息发布→ 登录 注册 退出

C#嵌套类的访问方法

发布时间:2026-01-11

点击量:

对于以下数据,如何在运行时通过字符串来得到静态变量UIPath的值。

复制代码 代码如下:
public class GameMainMenu : UIClass
{
    public class JetPack : UIClass
    {
        public static UIPath UIPath = new UIPath("UIPrefabs/GameMainMenu/JetPack/JetPack.prefab");
    }
}

像下面这样即可。
复制代码 代码如下:
BindingFlags flag = BindingFlags.Static | BindingFlags.Public;
Type type = Type.GetType("GameMainMenu+JetPack");
System.Reflection.FieldInfo key = type.GetField("UIPath", flag);
Debug.Log((key.GetValue(null) as UIPath).ToString());

在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!