By default, the graph and thus all its Action Tasks are updated in the normal Update loop, but in some cases you might want to use FixedUpdate or even OnGUI. To avoid unnecessary calls by default, there are no FixedUpdate or OnGUI methods to override though. Instead, this can be done by subscribing/unsubscribing a method to the onFixedUpdate or onGUI events found in the MonoManager class.
Following is an example of using OnFixedUpdate in a custom ActionTask:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using NodeCanvas.Framework; using ParadoxNotion.Services; namespace NodeCanvas.Tasks.Actions{ public class FixedUpdateActionTask : ActionTask { protected override void OnExecute(){ MonoManager.current.onFixedUpdate += OnFixedUpdate; } void OnFixedUpdate(){ ///Your FixedUpdate code... EndAction(); } protected override void OnStop(){ MonoManager.current.onFixedUpdate -= OnFixedUpdate; } } } |
Here is an example of using OnGUI:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
using NodeCanvas.Framework; using ParadoxNotion.Services; namespace NodeCanvas.Tasks.Actions{ public class OnGUIActionTask : ActionTask { protected override void OnExecute(){ MonoManager.current.onGUI += OnGUI; } void OnGUI(){ ///Your OnGUI code, like for example... if (UnityEngine.GUILayout.Button("OK")){ EndAction(); } } protected override void OnStop(){ MonoManager.current.onGUI -= OnGUI; } } } |
© Paradox Notion 2014-2024. All rights reserved.