返回

NodeCanvasAPI

自定义Action

需要继承ActionTask;

ActionTask方法的实现:

  1. public Component agent {get;} 这就是将要采取行动的代理

  2. public IBlackboard blackboard {get;} 如果需要,你可以用这个黑板来手动读写变量。

  3. public float elapsedTime {get;} 这是动作正在运行的时间(以秒为单位)。

  4. virtual protected string OnInit() 只在第一次执行操作时调用,在执行其他操作之前调用。

  5. virtual protected void OnExecute() 在执行操作时调用一次。

  6. virtual protected void OnUpdate() 在动作运行时调用每一帧。

  7. virtual protected void OnStop() 当动作因任何原因停止时调用。 不是因为您调用了EndAction,就是因为这个操作被中断了。

  8. virtual protected void OnPause() 当动作暂停时调用,只有当动作仍在运行时调用,而行为图暂停时调用。

  9. protected void SendEvent(string) 向行为图发送一个事件。将其与CheckEvent条件一起使用。

  10. protected void SendEvent(string, T) 与上面类似,但是在事件中发送一个值。

  11. protected Coroutine StartCoroutine(IEnumerator) 你可以像平常一样在action任务中使用协同程序。

  12. public void EndAction(bool) 你必须这样做才能结束行动。你可以在任何地方调用它, 虽然通常是在OnExecute或OnUpdate中完成

基类Node实现API

  1. Status OnExecute(Component agent, IBlackboard blackboard) 覆盖定义节点功能。用于启动图的代理和黑板传递
  2. OnReset() 当节点被重新设置时调用。例如:OnGraphStart,树遍历后,中断时,OnGraphEnd等…
  3. OnParentConnected(int connectionIndex) 在输入连接连接时调用
  4. OnParentDisconnected(int connectionIndex) 在输入连接断开之前调用
  5. OnChildConnected(int connectionIndex) 在输出连接连接时调用
  6. OnChildDisconnected(int connectionIndex) 在输出连接断开之前调用
  7. OnGraphStarted() 在父图启动时调用。用于初始化值或其他。
  8. OnGraphStoped() 当父图停止时调用。
  9. OnGraphPaused() 在父图暂停时调用。
  10. OnGraphUnpaused() 当父图未暂停时调用。