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