MonoBehaviour
Unity 3D エンジンを複製しようとしています。私は Linux で monodevelop を使用しており、ほとんどのテストは Windows で行われますUnity 3D engine editor
。
詳細については、ここMonoBehaviour.Update
で読むことができます
Update
10ミリ秒ごとに継承するすべてのタイプでメソッドを呼び出したいですMonoBehavior
。
これが私がスタートでやっている方法です
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");
}
}