严格来说正常的游戏逻辑里不应该调用Editor目录下的类和方法,因为其中的代码并不会包括在最终的游戏包中。但在开发阶段为了方便调试,我们可能在游戏启动前想要先执行一段预代码来预处理数据,这个时候就只能用反射来实现了。
//Call method to generate data binding code before starting the game. Assembly assembly = Assembly.Load(new AssemblyName("Assembly-CSharp-Editor")); Type type = assembly.GetType("ClassName"); object obj = Activator.CreateInstance(type); MethodInfo methodInfo = type.GetMethod("MethodName"); methodInfo.Invoke(obj, null);