我正在尝试复制MonoBehaviour
Unity 3D 引擎。我在 Linux 上使用 monodevelop,大多数测试将在 Windows 中完成Unity 3D engine editor
。
更多关于MonoBehaviour.Update
可以在这里阅读
我想在每 10 毫秒Update
继承的所有类型上调用该方法。MonoBehavior
这就是我对 Start 的处理方式
using System;
using System.Reflection;
public class MonoBehaviour{
public static void Main (){
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in types) {
if (type.IsSubclassOf(typeof(MonoBehaviour))){
System.Reflection.MethodInfo mInfo = type.GetMethod ("Start", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null); // it is run 2 times
if (mInfo != null) {
ConstructorInfo ctor = type.GetConstructor (new Type[] { });
if (ctor != null) {
object inst = ctor.Invoke (new object[] { });
mInfo.Invoke (inst, new object[] { });
}
}
}
}
}
}
class example : MonoBehaviour{
void Start(){
// this works perfectly
Console.WriteLine ("HelloWorld");
}
void Update(){
// I want this to be run every 10 ms
Console.WriteLine ("HelloinUpdate");
}
}