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