嵌套类的访问

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

1 public class GameMainMenu : UIClass
2 {
3     public class JetPack : UIClass
4     {
5         public static UIPath UIPath = new UIPath("UIPrefabs/GameMainMenu/JetPack/JetPack.prefab");
6     }
7 }

像下面这样即可。

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());

 

相关文章:

  • 2021-09-24
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-12-29
猜你喜欢
  • 2021-07-20
  • 2021-06-12
  • 2022-12-23
  • 2021-05-15
  • 2021-12-27
  • 2022-12-23
相关资源
相似解决方案