我希望能够在构造派生对象时自动调用特定方法,但是我想不出怎么做.以下代码说明.另一个答案是OnLoad,但我在Mac上为Unity做这个,OnLoad似乎不支持我的平台.有什么建议?
public class Parent {
public Parent ()
{
// A. Stuff to do before child constructor code runs
DoThisAutomaticallyAfterConstruction();
}
public void DoThisAutomaticallyAfterConstruction()
{
// C. In this example, this will run after A, before B. I want it to run ABC
}
}
public class Child : Parent {
public Child () : base()
{
// B. Stuff to do here after parent constructor code runs
}
}
Run Code Online (Sandbox Code Playgroud) 我在Unity中编程,使用Action事件来保存一堆其他Action委托,以便将非Monobehaviour对象挂钩到Update()系统中.我希望能够将操作的名称打印到调试控制台,但使用类似于:
Delegate[] actions = updateActions.GetInvocationList();
foreach ( Delegate del in actions ) {
Debug.Log( del.ToString() );
}
Run Code Online (Sandbox Code Playgroud)
...只返回"System.Action".我也试过(del as Action).ToString()没有运气.