Tekkaman

导航

 

嵌套类的访问

对于以下数据,如何在运行时通过字符串来得到静态变量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());

 

posted on 2015-03-13 15:34  Tekkaman  阅读(465)  评论(0编辑  收藏  举报