Forums › 💬 NodeCanvas › ⚙️ Support › Various questions › Reply To: Various questions
Hello,
To answer your questions:
1. If the MoveTo function in your npc is an IEnumerator, you can use ExecuteFunction to execute it as a coroutine, without the need to write a custom task.
Regarding your custom task code, it is correct although it can be improved. For example, within a Task, you always have access to the agent with the inherited ‘agent’ property. The ‘agent’ property returns a Component type. When using the [AgentType] attribute like you have done here, that Component is certain to be of the type you specified. So you already have a reference of BALA and you don’t really need to also use [GetFromAgent], although it’s certainly possible.
Furthermore you can use BBVariables instead of normal variables, if you want to be allowed to assign the variables from the Blackboard. Here is the improved code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
using UnityEngine; using NodeCanvas.Variables; namespace NodeCanvas.Actions{ [Category("Simian Squared")] [AgentType(typeof(Bala))] public class MoveTo:ActionTask { //use BBTransform to allow dynamic change of the variable through the blackboard public BBTransform target; public float speed = 1; //agent is certaint to be of the type provided by the [AgentType] attribute private Bala npc { get {return (Bala)agent;} } protected override void OnExecute() { npc.MoveTo(target, speed); } protected override void OnUpdate() { if (!npc.processing) { EndAction(true); } } } } |
Also dont worry about get component since that is done only in initialize and is cached.
2. You can Start/Resume, Stop, Pause a behaviour with relative functions that are in the BehaviourTreeOwner class.
Please take a look here: http://nodecanvas.com/documentation/node-systems/behaviour-trees/control/
3. You can either use Nested DialogueTrees, or use this action to make a DialogueActor say something without the need of creating a nested dialogue tree.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
using UnityEngine; using NodeCanvas.DialogueTrees; namespace NodeCanvas.Actions{ [AgentType(typeof(DialogueActor))] [Category("Dialogue")] [Description("Makes a Dialogue Actor talk. You can use variable names in square brackets to make the text more dynamicneg [varName]")] public class SayDialogue : ActionTask { public Statement statement = new Statement("this is a dialogue text"); protected override string info{ get { var displayText = statement.text.Length > 20? statement.text.Substring(0, 20) + "..." : statement.text; return "' <i>" + displayText + "</i> '"; } } protected override void OnExecute(){ (agent as DialogueActor).Say(statement.BlackboardReplace(blackboard), EndAction); } protected override void OnStop(){ (agent as DialogueActor).StopTalking(); } //////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI(){ statement.text = UnityEditor.EditorGUILayout.TextArea(statement.text, GUILayout.Height(80)); statement.audio = UnityEditor.EditorGUILayout.ObjectField("Audio", statement.audio, typeof(AudioClip), true) as AudioClip; statement.meta = UnityEditor.EditorGUILayout.TextField("Meta", statement.meta); } #endif } } |
Is this what you mean?
Cheers
