NodeCanvas uses a lot of generics and you also have the ability to create and use generic action and condition Tasks, which make things much more reusable without the need to write countless of tasks doing the same thing.
This works well with the fact that BBParameter is also a generic type. With that in mind, the following is the code of the included SetVariable<T> action task.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
using NodeCanvas.Framework; using ParadoxNotion.Design; namespace NodeCanvas.Tasks.Actions{ [Category("✫ Blackboard")] public class SetVariable<T> : ActionTask { [RequiredField, BlackboardOnly] public BBParameter<T> valueA; public BBParameter<T> valueB; protected override string info{ get {return valueA + " = " + valueB;} } protected override void OnExecute(){ valueA.value = valueB.value; EndAction(); } } } |
Then, in the editor when you are to select an ActionTask, the generic task will be shown as a category where you will be able to select the type of T. Some things to keep in mind:
Finally here is another example code from the included AddElementToList<T> action task.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
using System.Collections.Generic; using NodeCanvas.Framework; using ParadoxNotion.Design; namespace NodeCanvas.Tasks.Actions{ [Category("✫ Blackboard/Lists")] public class AddElementToList<T> : ActionTask { [RequiredField, BlackboardOnly] public BBParameter<List<T>> targetList; public BBParameter<T> targetElement; protected override void OnExecute(){ targetList.value.Add(targetElement.value); EndAction(); } } } |
© Paradox Notion 2014-2024. All rights reserved.