first commit

This commit is contained in:
Chris
2025-03-12 14:22:16 -04:00
commit 0ad0c01249
1999 changed files with 189708 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
///<summary> Base class for BehaviourTree Composite nodes.</summary>
abstract public class BTComposite : BTNode
{
public override string name { get { return base.name.ToUpper(); } }
sealed public override int maxOutConnections { get { return -1; } }
sealed public override Alignment2x2 commentsAlignment { get { return Alignment2x2.Right; } }
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override UnityEditor.GenericMenu OnContextMenu(UnityEditor.GenericMenu menu) {
menu = base.OnContextMenu(menu);
menu = EditorUtils.GetTypeSelectionMenu(typeof(BTComposite), (t) => { this.ReplaceWith(t); }, menu, "Replace");
menu.AddItem(new GUIContent("Convert to SubTree"), false, () => { this.ConvertToSubTree(); });
if ( outConnections.Count > 0 ) {
menu.AddItem(new GUIContent("Duplicate Branch"), false, () => { this.DuplicateBranch(graph); });
menu.AddItem(new GUIContent("Delete Branch"), false, () => { this.DeleteBranch(); });
}
return menu;
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 2e93e7cbdaad6ba44b9dc279b92d4aa1
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/BTComposite.cs
uploadId: 704937

View File

@@ -0,0 +1,43 @@
using ParadoxNotion;
using NodeCanvas.Framework;
using System.Linq;
namespace NodeCanvas.BehaviourTrees
{
///<summary> Base class for BehaviourTree Decorator nodes.</summary>
abstract public class BTDecorator : BTNode
{
sealed public override int maxOutConnections { get { return 1; } }
sealed public override Alignment2x2 commentsAlignment { get { return Alignment2x2.Right; } }
///<summary>The decorated connection element</summary>
protected Connection decoratedConnection {
get { return outConnections.Count > 0 ? outConnections[0] : null; }
}
///<summary>The decorated node element</summary>
protected Node decoratedNode {
get
{
var c = decoratedConnection;
return c != null ? c.targetNode : null;
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override UnityEditor.GenericMenu OnContextMenu(UnityEditor.GenericMenu menu) {
menu = base.OnContextMenu(menu);
menu = ParadoxNotion.Design.EditorUtils.GetTypeSelectionMenu(typeof(BTDecorator), (t) => { this.ReplaceWith(t); }, menu, "Replace");
return menu;
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: db739e985051c1649a1542c75a5c0c35
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/BTDecorator.cs
uploadId: 704937

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: c91f78ceede3d6f4083926a34147bd51
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,84 @@
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Category("Composites")]
[Description("Quick way to execute the left or the right child, based on a Condition Task.")]
[ParadoxNotion.Design.Icon("Condition")]
[Color("b3ff7f")]
public class BinarySelector : BTNode, ITaskAssignable<ConditionTask>
{
[Tooltip("If true, the condition will be re-evaluated per frame.")]
public bool dynamic;
[SerializeField]
private ConditionTask _condition;
private int succeedIndex;
public override int maxOutConnections { get { return 2; } }
public override Alignment2x2 commentsAlignment { get { return Alignment2x2.Right; } }
public override string name {
get { return base.name.ToUpper(); }
}
public Task task {
get { return condition; }
set { condition = (ConditionTask)value; }
}
private ConditionTask condition {
get { return _condition; }
set { _condition = value; }
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( condition == null || outConnections.Count < 2 ) {
return Status.Optional;
}
if ( status == Status.Resting ) {
condition.Enable(agent, blackboard);
}
if ( dynamic || status == Status.Resting ) {
var lastIndex = succeedIndex;
succeedIndex = condition.Check(agent, blackboard) ? 0 : 1;
if ( succeedIndex != lastIndex ) {
outConnections[lastIndex].Reset();
}
}
return outConnections[succeedIndex].Execute(agent, blackboard);
}
protected override void OnReset() {
if ( condition != null ) { condition.Disable(); }
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
public override string GetConnectionInfo(int i) {
return i == 0 ? "TRUE" : "FALSE";
}
protected override void OnNodeGUI() {
if ( dynamic ) {
GUILayout.Label("<b>DYNAMIC</b>");
}
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 48e71e5905e9e394e83cbdce71c91feb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Composites/BinarySelector.cs
uploadId: 704937

View File

@@ -0,0 +1,48 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Category("Composites")]
[Description("Works like a normal Selector, but when a child returns Success, that child will be moved to the end.\nAs a result, previously Failed children will always be checked first and recently Successful children last.")]
[ParadoxNotion.Design.Icon("FlipSelector")]
[Color("b3ff7f")]
public class FlipSelector : BTComposite
{
private int current;
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
for ( var i = current; i < outConnections.Count; i++ ) {
status = outConnections[i].Execute(agent, blackboard);
if ( status == Status.Running ) {
current = i;
return Status.Running;
}
if ( status == Status.Success ) {
SendToBack(i);
return Status.Success;
}
}
return Status.Failure;
}
void SendToBack(int i) {
var c = outConnections[i];
outConnections.RemoveAt(i);
outConnections.Add(c);
}
protected override void OnReset() {
current = 0;
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: dcf40bac689367f4ba07b1a75299e628
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Composites/FlipSelector.cs
uploadId: 704937

View File

@@ -0,0 +1,123 @@
using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Parallel", 8)]
[Category("Composites")]
[Description("Executes all children simultaneously and return Success or Failure depending on the selected Policy.")]
[ParadoxNotion.Design.Icon("Parallel")]
[Color("ff64cb")]
public class Parallel : BTComposite
{
public enum ParallelPolicy
{
FirstFailure,
FirstSuccess,
FirstSuccessOrFailure
}
[Tooltip("The policy determines when the Parallel node will end and return its Status.")]
public ParallelPolicy policy = ParallelPolicy.FirstFailure;
[Name("Repeat"), Tooltip("If true, finished children are repeated until the Policy set is met, or until all children have had a chance to finish at least once.")]
public bool dynamic;
private bool[] finishedConnections;
private int finishedConnectionsCount;
public override void OnGraphStarted() {
finishedConnections = new bool[outConnections.Count];
finishedConnectionsCount = 0;
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
var defferedStatus = Status.Resting;
for ( var i = 0; i < outConnections.Count; i++ ) {
var connection = outConnections[i];
var isConnectionFinished = finishedConnections[i] == true;
if ( !dynamic && isConnectionFinished ) {
continue;
}
if ( connection.status != Status.Running && isConnectionFinished ) {
connection.Reset();
}
status = connection.Execute(agent, blackboard);
if ( defferedStatus == Status.Resting ) {
if ( status == Status.Failure && ( policy == ParallelPolicy.FirstFailure || policy == ParallelPolicy.FirstSuccessOrFailure ) ) {
defferedStatus = Status.Failure;
}
if ( status == Status.Success && ( policy == ParallelPolicy.FirstSuccess || policy == ParallelPolicy.FirstSuccessOrFailure ) ) {
defferedStatus = Status.Success;
}
}
if ( status != Status.Running && !isConnectionFinished ) {
finishedConnections[i] = true;
finishedConnectionsCount++;
}
}
if ( defferedStatus != Status.Resting ) {
ResetRunning();
status = defferedStatus;
return defferedStatus;
}
if ( finishedConnectionsCount == outConnections.Count ) {
ResetRunning();
switch ( policy ) {
case ParallelPolicy.FirstFailure:
return Status.Success;
case ParallelPolicy.FirstSuccess:
return Status.Failure;
}
}
return Status.Running;
}
protected override void OnReset() {
for ( var i = 0; i < finishedConnections.Length; i++ ) { finishedConnections[i] = false; }
finishedConnectionsCount = 0;
}
void ResetRunning() {
for ( var i = 0; i < outConnections.Count; i++ ) {
if ( outConnections[i].status == Status.Running ) {
outConnections[i].Reset();
}
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
public override string GetConnectionInfo(int i) {
if ( dynamic && status == Status.Running ) {
return finishedConnections[i] ? "Repeating" : null;
}
return null;
}
protected override void OnNodeGUI() {
GUILayout.Label(( dynamic ? "<b>REPEAT</b>\n" : "" ) + policy.ToString().SplitCamelCase());
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 20bb0006fe2ddc941b3bddd6e00a1321
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Composites/Parallel.cs
uploadId: 704937

View File

@@ -0,0 +1,205 @@
using System.Collections.Generic;
using System.Linq;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using ParadoxNotion.Serialization.FullSerializer;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
///----------------------------------------------------------------------------------------------
class PrioritySelector_0 : BTComposite
{
[SerializeField] public List<BBParameter<float>> priorities = null;
}
///----------------------------------------------------------------------------------------------
[Category("Composites")]
[Description("Used for Utility AI, the Priority Selector executes the child with the highest utility weight. If it fails, the Priority Selector will continue with the next highest utility weight child until one Succeeds, or until all Fail (similar to how a normal Selector does).\n\nEach child branch represents a desire, where each desire has one or more consideration which are all averaged.\nConsiderations are a pair of input value and curve, which together produce the consideration utility weight.\n\nIf Dynamic option is enabled, will continously evaluate utility weights and execute the child with the highest one regardless of what status the children return.")]
[ParadoxNotion.Design.Icon("Priority")]
[Color("b3ff7f")]
[fsMigrateVersions(typeof(PrioritySelector_0))]
public class PrioritySelector : BTComposite, IMigratable<PrioritySelector_0>
{
///----------------------------------------------------------------------------------------------
void IMigratable<PrioritySelector_0>.Migrate(PrioritySelector_0 model) {
this.desires = new List<Desire>();
foreach ( var priority in model.priorities ) {
var desire = new Desire();
this.desires.Add(desire);
var consideration = desire.AddConsideration(graphBlackboard);
consideration.input = priority;
}
}
///----------------------------------------------------------------------------------------------
[System.Serializable]
public class Desire
{
[ParadoxNotion.Serialization.FullSerializer.fsIgnoreInBuild]
public string name;
[ParadoxNotion.Serialization.FullSerializer.fsIgnoreInBuild]
public bool foldout;
public List<Consideration> considerations = new List<Consideration>();
public Consideration AddConsideration(IBlackboard bb) {
var result = new Consideration(bb);
considerations.Add(result);
return result;
}
public void RemoveConsideration(Consideration consideration) { considerations.Remove(consideration); }
public float GetCompoundUtility() {
float total = 0;
for ( var i = 0; i < considerations.Count; i++ ) {
total += considerations[i].utility;
}
return total / considerations.Count;
}
}
[System.Serializable]
public class Consideration
{
public BBParameter<float> input;
public BBParameter<AnimationCurve> function;
public float utility => function.value != null ? function.value.Evaluate(input.value) : input.value;
public Consideration(IBlackboard blackboard) {
input = new BBParameter<float> { value = 1f, bb = blackboard };
function = new BBParameter<AnimationCurve> { bb = blackboard };
}
}
///----------------------------------------------------------------------------------------------
[Tooltip("If enabled, will continously evaluate utility weights and execute the child with the highest one accordingly. In this mode child return status does not matter.")]
public bool dynamic;
[AutoSortWithChildrenConnections]
public List<Desire> desires;
private Connection[] orderedConnections;
private int current = 0;
public override void OnChildConnected(int index) {
if ( desires == null ) { desires = new List<Desire>(); }
if ( desires.Count < outConnections.Count ) { desires.Insert(index, new Desire()); }
}
public override void OnChildDisconnected(int index) { desires.RemoveAt(index); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( dynamic ) {
var highestPriority = float.NegativeInfinity;
var best = 0;
for ( var i = 0; i < outConnections.Count; i++ ) {
var priority = desires[i].GetCompoundUtility();
if ( priority > highestPriority ) {
highestPriority = priority;
best = i;
}
}
if ( best != current ) {
outConnections[current].Reset();
current = best;
}
return outConnections[current].Execute(agent, blackboard);
}
///----------------------------------------------------------------------------------------------
if ( status == Status.Resting ) {
orderedConnections = outConnections.OrderBy(c => desires[outConnections.IndexOf(c)].GetCompoundUtility()).ToArray();
}
for ( var i = orderedConnections.Length; i-- > 0; ) {
status = orderedConnections[i].Execute(agent, blackboard);
if ( status == Status.Success ) {
return Status.Success;
}
if ( status == Status.Running ) {
current = i;
return Status.Running;
}
}
return Status.Failure;
}
protected override void OnReset() { current = 0; }
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
//..
public override string GetConnectionInfo(int i) {
var desire = desires[i];
var desireName = string.IsNullOrEmpty(desire.name) ? "DESIRE " + i.ToString() : desire.name;
var result = desireName.ToUpper() + "\n";
for ( var j = 0; j < desire.considerations.Count; j++ ) {
result += desire.considerations[j].input.ToString() + " (" + desire.considerations[j].utility.ToString("0.00") + ")" + "\n";
}
return result += string.Format("<b>Avg.</b> ({0})", desire.GetCompoundUtility().ToString("0.00"));
}
//..
public override void OnConnectionInspectorGUI(int i) {
var desire = desires[i];
var optionsB = new EditorUtils.ReorderableListOptions();
optionsB.allowAdd = false;
optionsB.allowRemove = true;
EditorUtils.ReorderableList(desire.considerations, optionsB, (j, pickedB) =>
{
var consideration = desire.considerations[j];
GUILayout.BeginVertical("box");
consideration.input = (BBParameter<float>)NodeCanvas.Editor.BBParameterEditor.ParameterField("Input", consideration.input, true);
consideration.function = (BBParameter<AnimationCurve>)NodeCanvas.Editor.BBParameterEditor.ParameterField("Curve", consideration.function);
GUILayout.EndVertical();
});
if ( GUILayout.Button("Add Consideration") ) { desire.AddConsideration(graphBlackboard); }
EditorUtils.Separator();
}
protected override void OnNodeGUI() {
if ( dynamic ) { GUILayout.Label("<b>DYNAMIC</b>"); }
}
//..
protected override void OnNodeInspectorGUI() {
if ( outConnections.Count == 0 ) {
GUILayout.Label("Make some connections first");
return;
}
dynamic = UnityEditor.EditorGUILayout.Toggle(new GUIContent("Dynamic", "If enabled, will continously evaluate utility weights and execute the child with the highest one accordingly. In this mode child return status does not matter."), dynamic);
EditorUtils.Separator();
EditorUtils.CoolLabel("Desires");
var optionsA = new EditorUtils.ReorderableListOptions();
optionsA.allowAdd = false;
optionsA.allowRemove = false;
EditorUtils.ReorderableList(desires, optionsA, (i, pickedA) =>
{
var desire = desires[i];
var desireName = string.IsNullOrEmpty(desire.name) ? "DESIRE " + i.ToString() : desire.name;
desire.foldout = UnityEditor.EditorGUILayout.Foldout(desire.foldout, new GUIContent(desireName));
if ( desire.foldout ) {
desire.name = UnityEditor.EditorGUILayout.TextField(" Friendly Name", desire.name);
OnConnectionInspectorGUI(i);
}
});
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 39f51e3aa06f96c4399b79d7656917c6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Composites/PrioritySelector.cs
uploadId: 704937

View File

@@ -0,0 +1,133 @@
using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Category("Composites")]
[Description("Selects a child to execute based on its chance to be selected and returns Success if the child returns Success, otherwise picks another child.\nReturns Failure if all children return Failure, or a direct 'Failure Chance' is introduced.")]
[ParadoxNotion.Design.Icon("ProbabilitySelector")]
[Color("b3ff7f")]
public class ProbabilitySelector : BTComposite
{
[AutoSortWithChildrenConnections, Tooltip("The weights of the children.")]
public List<BBParameter<float>> childWeights;
[Tooltip("A chance for the node to fail immediately.")]
public BBParameter<float> failChance;
private bool[] indexFailed;
private float[] tmpWeights;
private float tmpFailWeight;
private float tmpTotal;
private float tmpDice;
public override void OnChildConnected(int index) {
if ( childWeights == null ) { childWeights = new List<BBParameter<float>>(); }
if ( childWeights.Count < outConnections.Count ) {
childWeights.Insert(index, new BBParameter<float> { value = 1, bb = graphBlackboard });
}
}
public override void OnChildDisconnected(int index) {
childWeights.RemoveAt(index);
}
public override void OnGraphStarted() { OnReset(); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( status == Status.Resting ) {
tmpDice = Random.value;
tmpFailWeight = failChance.value;
tmpTotal = tmpFailWeight;
for ( var i = 0; i < childWeights.Count; i++ ) {
var childWeight = childWeights[i].value;
tmpTotal += childWeight;
tmpWeights[i] = childWeight;
}
}
var prob = tmpFailWeight / tmpTotal;
if ( tmpDice < prob ) {
return Status.Failure;
}
for ( var i = 0; i < outConnections.Count; i++ ) {
if ( indexFailed[i] ) {
continue;
}
prob += tmpWeights[i] / tmpTotal;
if ( tmpDice <= prob ) {
status = outConnections[i].Execute(agent, blackboard);
if ( status == Status.Success || status == Status.Running ) {
return status;
}
if ( status == Status.Failure ) {
indexFailed[i] = true;
tmpTotal -= tmpWeights[i];
return Status.Running;
}
}
}
return Status.Failure;
}
protected override void OnReset() {
tmpWeights = new float[outConnections.Count];
indexFailed = new bool[outConnections.Count];
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
float GetTotal() {
var total = failChance.value;
for ( var i = 0; i < childWeights.Count; i++ ) {
total += childWeights[i].value;
}
return total;
}
public override string GetConnectionInfo(int i) {
return Mathf.Round(( childWeights[i].value / GetTotal() ) * 100) + "%";
}
public override void OnConnectionInspectorGUI(int i) {
NodeCanvas.Editor.BBParameterEditor.ParameterField("Weight", childWeights[i]);
}
protected override void OnNodeInspectorGUI() {
if ( outConnections.Count == 0 ) {
GUILayout.Label("Make some connections first");
return;
}
var total = GetTotal();
for ( var i = 0; i < childWeights.Count; i++ ) {
GUILayout.BeginHorizontal();
childWeights[i] = (BBParameter<float>)NodeCanvas.Editor.BBParameterEditor.ParameterField("Weight", childWeights[i]);
GUILayout.Label(Mathf.Round(( childWeights[i].value / total ) * 100) + "%", GUILayout.Width(38));
GUILayout.EndHorizontal();
}
GUILayout.Space(5);
GUILayout.BeginHorizontal();
failChance = (BBParameter<float>)NodeCanvas.Editor.BBParameterEditor.ParameterField("Direct Failure Chance", failChance);
GUILayout.Label(Mathf.Round(( failChance.value / total ) * 100) + "%", GUILayout.Width(38));
GUILayout.EndHorizontal();
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 23428d321072cac43b4e9c02610e96d6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Composites/ProbabilitySelector.cs
uploadId: 704937

View File

@@ -0,0 +1,82 @@
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Selector", 9)]
[Category("Composites")]
[Description("Executes its childrfen in order and returns Failure if all children return Failure. As soon as a child returns Success, the Selector will stop and return Success as well.")]
[ParadoxNotion.Design.Icon("Selector")]
[Color("b3ff7f")]
public class Selector : BTComposite
{
[Tooltip("If true, then higher priority children are re-evaluated per frame and if either returns Success, then the Selector will immediately stop and return Success as well.")]
public bool dynamic;
[Tooltip("If true, the children order of execution is shuffled each time the Selector resets.")]
public bool random;
private int lastRunningNodeIndex;
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
for ( var i = dynamic ? 0 : lastRunningNodeIndex; i < outConnections.Count; i++ ) {
status = outConnections[i].Execute(agent, blackboard);
switch ( status ) {
case Status.Running:
if ( dynamic && i < lastRunningNodeIndex ) {
for ( var j = i + 1; j <= lastRunningNodeIndex; j++ ) {
outConnections[j].Reset();
}
}
lastRunningNodeIndex = i;
return Status.Running;
case Status.Success:
if ( dynamic && i < lastRunningNodeIndex ) {
for ( var j = i + 1; j <= lastRunningNodeIndex; j++ ) {
outConnections[j].Reset();
}
}
return Status.Success;
}
}
return Status.Failure;
}
protected override void OnReset() {
lastRunningNodeIndex = 0;
if ( random ) { outConnections = outConnections.Shuffle(); }
}
public override void OnChildDisconnected(int index) {
if ( index != 0 && index == lastRunningNodeIndex ) {
lastRunningNodeIndex--;
}
}
public override void OnGraphStarted() { OnReset(); }
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
if ( dynamic ) { GUILayout.Label("<b>DYNAMIC</b>"); }
if ( random ) { GUILayout.Label("<b>RANDOM</b>"); }
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: aa1c35ff60b06c74cb9102cc2babf462
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Composites/Selector.cs
uploadId: 704937

View File

@@ -0,0 +1,80 @@
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Sequencer", 10)]
[Category("Composites")]
[Description("Executes its children in order and returns Success if all children return Success. As soon as a child returns Failure, the Sequencer will stop and return Failure as well.")]
[ParadoxNotion.Design.Icon("Sequencer")]
[Color("bf7fff")]
public class Sequencer : BTComposite
{
[Tooltip("If true, then higher priority children are re-evaluated per frame and if either returns Failure, then the Sequencer will immediately stop and return Failure as well.")]
public bool dynamic;
[Tooltip("If true, the children order of execution is shuffled each time the Sequencer resets.")]
public bool random;
private int lastRunningNodeIndex = 0;
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
for ( var i = dynamic ? 0 : lastRunningNodeIndex; i < outConnections.Count; i++ ) {
status = outConnections[i].Execute(agent, blackboard);
switch ( status ) {
case Status.Running:
if ( dynamic && i < lastRunningNodeIndex ) {
for ( var j = i + 1; j <= lastRunningNodeIndex; j++ ) {
outConnections[j].Reset();
}
}
lastRunningNodeIndex = i;
return Status.Running;
case Status.Failure:
if ( dynamic && i < lastRunningNodeIndex ) {
for ( var j = i + 1; j <= lastRunningNodeIndex; j++ ) {
outConnections[j].Reset();
}
}
return Status.Failure;
}
}
return Status.Success;
}
protected override void OnReset() {
lastRunningNodeIndex = 0;
if ( random ) { outConnections = outConnections.Shuffle(); }
}
public override void OnChildDisconnected(int index) {
if ( index != 0 && index == lastRunningNodeIndex ) {
lastRunningNodeIndex--;
}
}
public override void OnGraphStarted() { OnReset(); }
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
if ( dynamic ) { GUILayout.Label("<b>DYNAMIC</b>"); }
if ( random ) { GUILayout.Label("<b>RANDOM</b>"); }
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: bafebe0850f5ea84eb87e77c674123e8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Composites/Sequencer.cs
uploadId: 704937

View File

@@ -0,0 +1,32 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Step Sequencer")]
[Category("Composites")]
[Description("In comparison to a normal Sequencer which executes all its children until one fails, Step Sequencer executes its children one-by-one per Step Sequencer execution. The executed child status is returned regardless of Success or Failure.")]
[ParadoxNotion.Design.Icon("StepIterator")]
[Color("bf7fff")]
public class StepIterator : BTComposite
{
private int current;
public override void OnGraphStarted() {
current = 0;
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
current = current % outConnections.Count;
return outConnections[current].Execute(agent, blackboard);
}
protected override void OnReset() {
current++;
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 1beecc40e55bf82488985475900341fe
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Composites/StepIterator.cs
uploadId: 704937

View File

@@ -0,0 +1,137 @@
using System.Collections.Generic;
using NodeCanvas.Framework;
using NodeCanvas.Framework.Internal;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Category("Composites")]
[Description("Executes one child based on the provided int or enum case and returns its status.")]
[ParadoxNotion.Design.Icon("IndexSwitcher")]
[Color("b3ff7f")]
public class Switch : BTComposite
{
public enum CaseSelectionMode
{
IndexBased = 0,
EnumBased = 1
}
public enum OutOfRangeMode
{
ReturnFailure,
LoopIndex
}
[Tooltip("If true and the 'case' change while a child is running, that child will immediately be interrupted and the new child will be executed.")]
public bool dynamic;
[Tooltip("The selection mode used.")]
public CaseSelectionMode selectionMode = CaseSelectionMode.IndexBased;
[ShowIf("selectionMode", 0)]
public BBParameter<int> intCase;
[ShowIf("selectionMode", 0)]
public OutOfRangeMode outOfRangeMode = OutOfRangeMode.LoopIndex;
[ShowIf("selectionMode", 1), BlackboardOnly]
public BBObjectParameter enumCase = new BBObjectParameter(typeof(System.Enum));
private Dictionary<int, int> enumCasePairing;
private int current;
private int runningIndex;
public override void OnGraphStarted() {
if ( selectionMode == CaseSelectionMode.EnumBased ) {
var enumValue = enumCase.value;
if ( enumValue != null ) {
enumCasePairing = new Dictionary<int, int>();
var enumValues = System.Enum.GetValues(enumValue.GetType());
for ( var i = 0; i < enumValues.Length; i++ ) {
enumCasePairing[(int)enumValues.GetValue(i)] = i;
}
}
}
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( outConnections.Count == 0 ) {
return Status.Optional;
}
if ( status == Status.Resting || dynamic ) {
if ( selectionMode == CaseSelectionMode.IndexBased ) {
current = intCase.value;
if ( outOfRangeMode == OutOfRangeMode.LoopIndex ) {
current = Mathf.Abs(current) % outConnections.Count;
}
} else {
current = enumCasePairing[(int)enumCase.value];
}
if ( runningIndex != current ) {
outConnections[runningIndex].Reset();
}
if ( current < 0 || current >= outConnections.Count ) {
return Status.Failure;
}
}
status = outConnections[current].Execute(agent, blackboard);
if ( status == Status.Running ) {
runningIndex = current;
}
return status;
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
public override string GetConnectionInfo(int i) {
if ( selectionMode == CaseSelectionMode.EnumBased ) {
if ( enumCase.value == null ) {
return "Null Enum".FormatError();
}
var enumNames = System.Enum.GetNames(enumCase.value.GetType());
if ( i >= enumNames.Length ) {
return "Never".FormatError();
}
return enumNames[i];
}
return i.ToString();
}
protected override void OnNodeGUI() {
if ( dynamic ) {
GUILayout.Label("<b>DYNAMIC</b>");
}
GUILayout.Label(selectionMode == CaseSelectionMode.IndexBased ? ( "Current = " + intCase.ToString() ) : enumCase.ToString());
}
protected override void OnNodeInspectorGUI() {
base.OnNodeInspectorGUI();
if ( selectionMode == CaseSelectionMode.EnumBased ) {
if ( enumCase.value != null ) {
GUILayout.BeginVertical("box");
foreach ( var s in System.Enum.GetNames(enumCase.value.GetType()) ) {
GUILayout.Label(s);
}
GUILayout.EndVertical();
}
}
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: d3c9285b12215614d98d6497ad391e78
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Composites/Switch.cs
uploadId: 704937

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: ad02d7f1f3402ef4083d1af9260f390e
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,88 @@
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Conditional")]
[Category("Decorators")]
[Description("Executes and returns the child status only if the condition is true. Returns Failure if the condition is false.")]
[ParadoxNotion.Design.Icon("Accessor")]
public class ConditionalEvaluator : BTDecorator, ITaskAssignable<ConditionTask>
{
[Name("Dynamic"), Tooltip("If enabled, the condition is re-evaluated per frame and the child is aborted if the condition becomes false.")]
public bool isDynamic;
[Tooltip("The status that will be returned if the assigned condition is or becomes false.")]
public CompactStatus conditionFailReturn = CompactStatus.Failure;
[SerializeField]
private ConditionTask _condition;
private bool accessed;
public Task task {
get { return condition; }
set { condition = (ConditionTask)value; }
}
private ConditionTask condition {
get { return _condition; }
set { _condition = value; }
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
if ( condition == null ) {
return decoratedConnection.Execute(agent, blackboard);
}
if ( status == Status.Resting ) {
condition.Enable(agent, blackboard);
}
if ( isDynamic ) {
if ( condition.Check(agent, blackboard) ) {
return decoratedConnection.Execute(agent, blackboard);
}
decoratedConnection.Reset();
return (Status)conditionFailReturn;
} else {
if ( status != Status.Running ) {
accessed = condition.Check(agent, blackboard);
}
return accessed ? decoratedConnection.Execute(agent, blackboard) : (Status)conditionFailReturn;
}
}
protected override void OnReset() {
if ( condition != null ) { condition.Disable(); }
accessed = false;
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
if ( isDynamic ) { GUILayout.Label("<b>DYNAMIC</b>"); }
}
protected override void OnNodeInspectorGUI() {
base.OnNodeInspectorGUI();
EditorUtils.Separator();
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 77a4b51944584ae429faf6c94c84bc6c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/ConditionalEvaluator.cs
uploadId: 704937

View File

@@ -0,0 +1,119 @@
using System.Collections;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Filter")]
[Category("Decorators")]
[Description("Filters the access of its child either a specific number of times, or every specific amount of time.")]
[ParadoxNotion.Design.Icon("Filter")]
public class Filter : BTDecorator
{
public enum FilterMode
{
LimitNumberOfTimes = 0,
CoolDown = 1
}
public enum Policy
{
SuccessOrFailure,
SuccessOnly,
FailureOnly
}
[Tooltip("The mode to use.")]
public FilterMode filterMode = FilterMode.CoolDown;
[ShowIf("filterMode", 0)]
[Name("Max Times"), Tooltip("The max ammount of times to allow the child to execute until the tree is completely restarted.")]
public BBParameter<int> maxCount = 1;
[ShowIf("filterMode", 0)]
[Name("Increase Count When"), Tooltip("Only increase count if the selected status is returned from the child.")]
public Policy policy = Policy.SuccessOrFailure;
[ShowIf("filterMode", 1), Tooltip("The time to disallow execution for.")]
public BBParameter<float> coolDownTime = 5f;
[Name("Optional When Filtered"), Tooltip("If enabled, the Filter Decorator will return an Optional status when it is filtered. Otherwise it will return Failure.")]
public bool inactiveWhenLimited = true;
private int executedCount;
private float currentTime;
public override void OnGraphStoped() {
executedCount = 0;
currentTime = 0;
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
switch ( filterMode ) {
case FilterMode.CoolDown:
if ( currentTime > 0 ) {
return inactiveWhenLimited ? Status.Optional : Status.Failure;
}
status = decoratedConnection.Execute(agent, blackboard);
if ( status == Status.Success || status == Status.Failure ) {
StartCoroutine(Cooldown());
}
break;
case FilterMode.LimitNumberOfTimes:
if ( executedCount >= maxCount.value ) {
return inactiveWhenLimited ? Status.Optional : Status.Failure;
}
status = decoratedConnection.Execute(agent, blackboard);
if
(
( status == Status.Success && policy == Policy.SuccessOnly ) ||
( status == Status.Failure && policy == Policy.FailureOnly ) ||
( ( status == Status.Success || status == Status.Failure ) && policy == Policy.SuccessOrFailure )
) {
executedCount += 1;
}
break;
}
return status;
}
IEnumerator Cooldown() {
currentTime = coolDownTime.value;
while ( currentTime > 0 ) {
yield return null;
currentTime -= Time.deltaTime;
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
if ( filterMode == FilterMode.CoolDown ) {
GUILayout.Space(25);
var pRect = new Rect(5, GUILayoutUtility.GetLastRect().y, rect.width - 10, 20);
UnityEditor.EditorGUI.ProgressBar(pRect, currentTime / coolDownTime.value, currentTime > 0 ? "Cooling..." : "Cooled");
} else
if ( filterMode == FilterMode.LimitNumberOfTimes ) {
GUILayout.Label(executedCount + " / " + maxCount.value + " Accessed Times");
}
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: fb5ec2484dff28347b4302b59cdb3139
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Filter.cs
uploadId: 704937

View File

@@ -0,0 +1,97 @@
using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Guard")]
[Category("Decorators")]
[ParadoxNotion.Design.Icon("Shield")]
[Description("Protects the decorated child from running if another Guard with the same token is already guarding (Running) that token.\nGuarding is global for all of the agent Behaviour Trees.")]
public class Guard : BTDecorator
{
public enum GuardMode
{
ReturnFailure,
WaitUntilReleased
}
[Tooltip("A unique Token to use for guarding.")]
public BBParameter<string> token;
[Tooltip("What to return in case the token is already guarded by another Guard.")]
public GuardMode ifGuarded = GuardMode.ReturnFailure;
private bool isGuarding;
private static readonly Dictionary<GameObject, List<Guard>> guards = new Dictionary<GameObject, List<Guard>>();
private static List<Guard> AgentGuards(Component agent) { return guards[agent.gameObject]; }
public override void OnGraphStarted() {
SetGuards(graphAgent);
}
public override void OnGraphStoped() {
foreach ( var runningGraph in Graph.runningGraphs ) {
if ( runningGraph.agent != null && runningGraph.agent.gameObject == this.graphAgent.gameObject ) {
return;
}
}
guards.Remove(graphAgent.gameObject);
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
if ( agent != graphAgent ) {
SetGuards(agent);
}
for ( var i = 0; i < AgentGuards(agent).Count; i++ ) {
var guard = AgentGuards(agent)[i];
if ( guard != this && guard.isGuarding && guard.token.value == this.token.value ) {
return ifGuarded == GuardMode.ReturnFailure ? Status.Failure : Status.Running;
}
}
status = decoratedConnection.Execute(agent, blackboard);
if ( status == Status.Running ) {
isGuarding = true;
return Status.Running;
}
isGuarding = false;
return status;
}
protected override void OnReset() {
isGuarding = false;
}
void SetGuards(Component guardAgent) {
if ( !guards.ContainsKey(guardAgent.gameObject) ) {
guards[guardAgent.gameObject] = new List<Guard>();
}
if ( !AgentGuards(guardAgent).Contains(this) && !string.IsNullOrEmpty(token.value) ) {
AgentGuards(guardAgent).Add(this);
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
GUILayout.Label(string.Format("<b>' {0} '</b>", string.IsNullOrEmpty(token.value) ? "NONE" : token.value));
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 19fc82817a5cfd94f99129e7f7a6f879
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Guard.cs
uploadId: 704937

View File

@@ -0,0 +1,58 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Interrupt")]
[Category("Decorators")]
[Description("Executes and returns the child status. If the condition is or becomes true, the child is interrupted and returns Failure.")]
[ParadoxNotion.Design.Icon("Interruptor")]
public class Interruptor : BTDecorator, ITaskAssignable<ConditionTask>
{
[SerializeField]
private ConditionTask _condition;
public ConditionTask condition {
get { return _condition; }
set { _condition = value; }
}
public Task task {
get { return condition; }
set { condition = (ConditionTask)value; }
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
if ( condition == null ) {
return decoratedConnection.Execute(agent, blackboard);
}
if ( status == Status.Resting ) {
condition.Enable(agent, blackboard);
}
if ( condition.Check(agent, blackboard) == false ) {
return decoratedConnection.Execute(agent, blackboard);
}
if ( decoratedConnection.status == Status.Running ) {
decoratedConnection.Reset();
}
return Status.Failure;
}
protected override void OnReset() {
if ( condition != null ) { condition.Disable(); }
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 02d64e844d954b94d94268d941ad3768
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Interruptor.cs
uploadId: 704937

View File

@@ -0,0 +1,33 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Invert")]
[Category("Decorators")]
[Description("Inverts Success to Failure and Failure to Success.")]
[ParadoxNotion.Design.Icon("Remap")]
public class Inverter : BTDecorator
{
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null )
return Status.Optional;
status = decoratedConnection.Execute(agent, blackboard);
switch ( status ) {
case Status.Success:
return Status.Failure;
case Status.Failure:
return Status.Success;
}
return status;
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: fc5ca97b632c2a34a954b8e8937b1726
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Inverter.cs
uploadId: 704937

View File

@@ -0,0 +1,126 @@
using System.Collections;
using NodeCanvas.Framework;
using NodeCanvas.Framework.Internal;
using ParadoxNotion.Design;
using ParadoxNotion;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Iterate")]
[Category("Decorators")]
[Description("Iterates a list and executes its child once for each element in that list. Keeps iterating until the Termination Policy is met or until the whole list is iterated, in which case the last iteration child status is returned.")]
[ParadoxNotion.Design.Icon("List")]
public class Iterator : BTDecorator
{
public enum TerminationConditions
{
None,
FirstSuccess,
FirstFailure
}
[RequiredField]
[BlackboardOnly]
[Tooltip("The list to iterate.")]
public BBParameter<IList> targetList;
[BlackboardOnly]
[Name("Current Element")]
[Tooltip("Store the currently iterated list element in a variable.")]
public BBObjectParameter current;
[BlackboardOnly]
[Name("Current Index")]
[Tooltip("Store the currently iterated list index in a variable.")]
public BBParameter<int> storeIndex;
[Name("Termination Policy"), Tooltip("The condition for when to terminate the iteration and return status.")]
public TerminationConditions terminationCondition = TerminationConditions.None;
[Tooltip("The maximum allowed iterations. Leave at -1 to iterate the whole list.")]
public BBParameter<int> maxIteration = -1;
[Tooltip("Should the iteration start from the begining after the Iterator node resets?")]
public bool resetIndex = true;
private int currentIndex;
private IList list => targetList != null ? targetList.value : null;
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
if ( list == null || list.Count == 0 ) {
return Status.Failure;
}
for ( var i = currentIndex; i < list.Count; i++ ) {
current.value = list[i];
storeIndex.value = i;
status = decoratedConnection.Execute(agent, blackboard);
if ( status == Status.Success && terminationCondition == TerminationConditions.FirstSuccess ) {
return Status.Success;
}
if ( status == Status.Failure && terminationCondition == TerminationConditions.FirstFailure ) {
return Status.Failure;
}
if ( status == Status.Running ) {
currentIndex = i;
return Status.Running;
}
if ( currentIndex == list.Count - 1 || currentIndex == maxIteration.value - 1 ) {
if ( resetIndex ) { currentIndex = 0; }
return status;
}
decoratedConnection.Reset();
currentIndex++;
}
return Status.Running;
}
protected override void OnReset() {
if ( resetIndex ) { currentIndex = 0; }
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
GUILayout.Label("For Each\t" + current + "\nIn\t" + targetList, Styles.leftLabel);
if ( terminationCondition != TerminationConditions.None ) {
GUILayout.Label("Break on " + terminationCondition.ToString());
}
if ( Application.isPlaying ) {
GUILayout.Label("Index: " + currentIndex.ToString() + " / " + ( list != null && list.Count != 0 ? ( list.Count - 1 ).ToString() : "?" ));
}
}
protected override void OnNodeInspectorGUI() {
DrawDefaultInspector();
var argType = targetList.refType != null ? targetList.refType.GetEnumerableElementType() : null;
if ( current.varType != argType ) { current.SetType(argType); }
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 3255184fe8922814dbb5260dc3bd07dc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Iterator.cs
uploadId: 704937

View File

@@ -0,0 +1,21 @@
using UnityEngine;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
namespace NodeCanvas.BehaviourTrees
{
[Name("Merge", -1)]
[Description("Merge can accept multiple input connections and thus possible to re-use leaf nodes from multiple parents. Please note that this is experimental and can result in unexpected behaviour.")]
[Category("Decorators")]
public class Merge : BTDecorator
{
public override int maxInConnections => -1;
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( status != Status.Running ) { decoratedConnection.Reset(); }
return decoratedConnection.Execute(agent, blackboard);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 586c7107d4ae1b346bf183aa14da0a85
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Merge.cs
uploadId: 704937

View File

@@ -0,0 +1,94 @@
using UnityEngine;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
namespace NodeCanvas.BehaviourTrees
{
[Category("Decorators")]
[ParadoxNotion.Design.Icon("Eye")]
[Description("Monitors the decorated child for a returned Status and executes an Action when that is the case.\nThe final Status returned to the parent can either be the original decorated child Status, or the new decorator Action Status.")]
public class Monitor : BTDecorator, ITaskAssignable<ActionTask>
{
public enum MonitorMode
{
Failure = 0,
Success = 1,
AnyStatus = 10,
}
public enum ReturnStatusMode
{
OriginalDecoratedChildStatus,
NewDecoratorActionStatus,
}
[Name("Monitor"), Tooltip("The Status to monitor for.")]
public MonitorMode monitorMode;
[Name("Return"), Tooltip("The Status to return after (and if) the Action is executed.")]
public ReturnStatusMode returnMode;
private Status decoratorActionStatus;
[SerializeField]
private ActionTask _action;
public ActionTask action {
get { return _action; }
set { _action = value; }
}
public Task task {
get { return action; }
set { action = (ActionTask)value; }
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
var newChildStatus = decoratedConnection.Execute(agent, blackboard);
if ( action == null ) {
return newChildStatus;
}
if ( status != newChildStatus ) {
var execute = false;
execute |= newChildStatus == Status.Success && monitorMode == MonitorMode.Success;
execute |= newChildStatus == Status.Failure && monitorMode == MonitorMode.Failure;
execute |= monitorMode == MonitorMode.AnyStatus && newChildStatus != Status.Running;
if ( execute ) {
decoratorActionStatus = action.Execute(agent, blackboard);
if ( decoratorActionStatus == Status.Running ) {
return Status.Running;
}
}
}
return returnMode == ReturnStatusMode.NewDecoratorActionStatus && decoratorActionStatus != Status.Resting ? decoratorActionStatus : newChildStatus;
}
protected override void OnReset() {
if ( action != null ) {
action.EndAction(null);
decoratorActionStatus = Status.Resting;
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
GUILayout.Label(string.Format("<b>[On {0}]</b>", monitorMode.ToString()));
}
#endif
///---------------------------------------UNITY EDITOR-------------------------------------------
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: bcfd9a49dcd36a945980913e16ded47c
timeCreated: 1495927811
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Monitor.cs
uploadId: 704937

View File

@@ -0,0 +1,30 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Optional")]
[Category("Decorators")]
[Description("Executes the decorated child as normal and returns an Optional status, thus making it optional to the parent node in regards to what status is returned.\nThis has the same effect as disabling the node, but instead it executes normaly.")]
[ParadoxNotion.Design.Icon("UpwardsArrow")]
public class Optional : BTDecorator
{
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
if ( status == Status.Resting ) {
decoratedConnection.Reset();
}
status = decoratedConnection.Execute(agent, blackboard);
return status == Status.Running ? Status.Running : Status.Optional;
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 118d0d2c1e83b3140be8151b09bb0bbc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Optional.cs
uploadId: 704937

View File

@@ -0,0 +1,58 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Remap")]
[Category("Decorators")]
[Description("Remaps the child status to another status. Used to either invert the child's return status or to always return a specific status.")]
[ParadoxNotion.Design.Icon("Remap")]
public class Remapper : BTDecorator
{
public enum RemapStatus
{
Failure = 0,
Success = 1,
}
public RemapStatus successRemap = RemapStatus.Success;
public RemapStatus failureRemap = RemapStatus.Failure;
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
status = decoratedConnection.Execute(agent, blackboard);
switch ( status ) {
case Status.Success:
return (Status)successRemap;
case Status.Failure:
return (Status)failureRemap;
}
return status;
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
if ( (int)successRemap != (int)Status.Success )
GUILayout.Label("Success → " + successRemap);
if ( (int)failureRemap != (int)Status.Failure )
GUILayout.Label("Failure → " + failureRemap);
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: b95e7194b7b2eb24fab03071e0cebf33
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Remapper.cs
uploadId: 704937

View File

@@ -0,0 +1,105 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Repeat")]
[Category("Decorators")]
[Description("Repeats the child either x times or until it returns the specified status, or forever.")]
[ParadoxNotion.Design.Icon("Repeat")]
public class Repeater : BTDecorator
{
public enum RepeaterMode
{
RepeatTimes = 0,
RepeatUntil = 1,
RepeatForever = 2
}
public enum RepeatUntilStatus
{
Failure = 0,
Success = 1
}
public RepeaterMode repeaterMode = RepeaterMode.RepeatTimes;
[ShowIf("repeaterMode", 0)]
public BBParameter<int> repeatTimes = 1;
[ShowIf("repeaterMode", 1)]
public RepeatUntilStatus repeatUntilStatus = RepeatUntilStatus.Success;
private int currentIteration = 1;
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
if ( decoratedConnection.status != Status.Running ) {
decoratedConnection.Reset();
}
status = decoratedConnection.Execute(agent, blackboard);
switch ( status ) {
case Status.Resting:
return Status.Running;
case Status.Running:
return Status.Running;
}
switch ( repeaterMode ) {
case RepeaterMode.RepeatTimes:
if ( currentIteration >= repeatTimes.value ) {
return status;
}
currentIteration++;
break;
case RepeaterMode.RepeatUntil:
if ( (int)status == (int)repeatUntilStatus ) {
return status;
}
break;
}
return Status.Running;
}
protected override void OnReset() {
currentIteration = 1;
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
if ( repeaterMode == RepeaterMode.RepeatTimes ) {
GUILayout.Label(repeatTimes + " Times");
if ( Application.isPlaying )
GUILayout.Label("Iteration: " + currentIteration.ToString());
} else if ( repeaterMode == RepeaterMode.RepeatUntil ) {
GUILayout.Label("Until " + repeatUntilStatus);
} else {
GUILayout.Label("Repeat Forever");
}
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: d74567d471af51f46a176cd123b68d72
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Repeater.cs
uploadId: 704937

View File

@@ -0,0 +1,41 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Override Agent")]
[Category("Decorators")]
[Description("Set another Agent for the rest of the Tree dynamicaly from this point and on. All nodes under this will be executed with the new agent. You can also use this decorator to revert back to the original graph agent.")]
[ParadoxNotion.Design.Icon("Agent")]
public class Setter : BTDecorator
{
[Tooltip("If enabled, will revert back to the original graph agent.")]
public bool revertToOriginal;
[ShowIf("revertToOriginal", 0), Tooltip("The new agent to use.")]
public BBParameter<GameObject> newAgent;
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
agent = revertToOriginal ? graphAgent : newAgent.value.transform;
return decoratedConnection.Execute(agent, blackboard);
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
GUILayout.Label(string.Format("Agent = {0}", revertToOriginal ? "Original" : newAgent.ToString()));
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: f79712c85c72df64cb10e3dc32389aaa
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Setter.cs
uploadId: 704937

View File

@@ -0,0 +1,50 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Category("Decorators")]
[Description("Interupts decorated child node and returns Failure if the child node is still Running after the timeout period.")]
[ParadoxNotion.Design.Icon("Timeout")]
public class Timeout : BTDecorator
{
[Tooltip("The timeout period in seconds.")]
public BBParameter<float> timeout = 1;
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
return Status.Optional;
}
status = decoratedConnection.Execute(agent, blackboard);
if ( status == Status.Running ) {
if ( elapsedTime >= timeout.value ) {
decoratedConnection.Reset();
return Status.Failure;
}
}
return status;
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeGUI() {
GUILayout.Space(25);
var pRect = new Rect(5, GUILayoutUtility.GetLastRect().y, rect.width - 10, 20);
var t = 1 - ( elapsedTime / timeout.value );
UnityEditor.EditorGUI.ProgressBar(pRect, t, elapsedTime > 0 ? string.Format("({0})", elapsedTime.ToString("0.0")) : "Ready");
}
#endif
///----------------------------------------------------------------------------------------------
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 117e6954834de844b80b3610a29e4867
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/Timeout.cs
uploadId: 704937

View File

@@ -0,0 +1,65 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Category("Decorators")]
[Description("Returns Running until the assigned condition becomes true, after which the decorated child is executed.")]
[ParadoxNotion.Design.Icon("Halt")]
public class WaitUntil : BTDecorator, ITaskAssignable<ConditionTask>
{
[SerializeField]
private ConditionTask _condition;
private bool accessed;
public Task task {
get { return condition; }
set { condition = (ConditionTask)value; }
}
private ConditionTask condition {
get { return _condition; }
set { _condition = value; }
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( decoratedConnection == null ) {
//this part is so that Wait node can be used as a leaf too, by user request
if ( condition != null ) {
if ( status == Status.Resting ) {
condition.Enable(agent, blackboard);
}
return condition.Check(agent, blackboard) ? Status.Success : Status.Running;
}
//-----
return Status.Optional;
}
if ( condition == null ) {
return decoratedConnection.Execute(agent, blackboard);
}
if ( status == Status.Resting ) {
condition.Enable(agent, blackboard);
}
if ( accessed ) return decoratedConnection.Execute(agent, blackboard);
if ( condition.Check(agent, blackboard) ) {
accessed = true;
}
return accessed ? decoratedConnection.Execute(agent, blackboard) : Status.Running;
}
protected override void OnReset() {
if ( condition != null ) { condition.Disable(); }
accessed = false;
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 1523063433aecea4cb4f75728ac09886
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Decorators/WaitUntil.cs
uploadId: 704937

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 07733885d919a884faf9690060c0d1d7
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,58 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Action")]
[Description("Executes an action and returns Success or Failure when the action is finished.\nReturns Running until the action is finished.")]
[ParadoxNotion.Design.Icon("Action")]
// [Color("ff6d53")]
public class ActionNode : BTNode, ITaskAssignable<ActionTask>
{
[SerializeField]
private ActionTask _action;
public Task task {
get { return action; }
set { action = (ActionTask)value; }
}
public ActionTask action {
get { return _action; }
set { _action = value; }
}
public override string name {
get { return base.name.ToUpper(); }
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( action == null ) {
return Status.Optional;
}
if ( status == Status.Resting || status == Status.Running ) {
return action.Execute(agent, blackboard);
}
return status;
}
protected override void OnReset() {
if ( action != null ) {
action.EndAction(null);
}
}
public override void OnGraphPaused() {
if ( action != null ) {
action.Pause();
}
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 4363f6a82c42c2f4db123b8c19215466
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Leafs/ActionNode.cs
uploadId: 704937

View File

@@ -0,0 +1,49 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Condition")]
[Description("Checks a condition and returns Success or Failure.")]
[ParadoxNotion.Design.Icon("Condition")]
// [Color("ff6d53")]
public class ConditionNode : BTNode, ITaskAssignable<ConditionTask>
{
[SerializeField]
private ConditionTask _condition;
public Task task {
get { return condition; }
set { condition = (ConditionTask)value; }
}
public ConditionTask condition {
get { return _condition; }
set { _condition = value; }
}
public override string name {
get { return base.name.ToUpper(); }
}
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( condition == null ) {
return Status.Optional;
}
if ( status == Status.Resting ) {
condition.Enable(agent, blackboard);
}
return condition.Check(agent, blackboard) ? Status.Success : Status.Failure;
}
protected override void OnReset() {
if ( condition != null ) { condition.Disable(); }
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: ebacb7ee0473cac4a9a9de550ee34c08
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Leafs/ConditionNode.cs
uploadId: 704937

View File

@@ -0,0 +1,55 @@
using NodeCanvas.DialogueTrees;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Sub Dialogue")]
[Description("Executes a sub Dialogue Tree. Returns Running while the sub Dialogue Tree is active. You can Finish the Dialogue Tree with the 'Finish' node and return Success or Failure.")]
[ParadoxNotion.Design.Icon("Dialogue")]
[DropReferenceType(typeof(DialogueTree))]
public class NestedDT : BTNodeNested<DialogueTree>
{
[SerializeField, ExposeField, Name("Sub Tree")]
private BBParameter<DialogueTree> _nestedDialogueTree = null;
public override DialogueTree subGraph { get { return _nestedDialogueTree.value; } set { _nestedDialogueTree.value = value; } }
public override BBParameter subGraphParameter => _nestedDialogueTree;
//
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( subGraph == null || subGraph.primeNode == null ) {
return Status.Optional;
}
if ( status == Status.Resting ) {
status = Status.Running;
this.TryStartSubGraph(agent, OnDLGFinished);
}
if ( status == Status.Running ) {
currentInstance.UpdateGraph(this.graph.deltaTime);
}
return status;
}
void OnDLGFinished(bool success) {
if ( status == Status.Running ) {
status = success ? Status.Success : Status.Failure;
}
}
protected override void OnReset() {
if ( currentInstance != null ) {
currentInstance.Stop();
}
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: d1bc8dfa829907d4587851859ad68a5b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Leafs/NestedDT.cs
uploadId: 704937

View File

@@ -0,0 +1,83 @@
using System.Linq;
using NodeCanvas.Framework;
using NodeCanvas.StateMachines;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Sub FSM")]
[Description("Executes a sub FSM. Returns Running while the sub FSM is active. If a Success or Failure State is selected, then it will return Success or Failure as soon as the Nested FSM enters that state at which point the sub FSM will also be stoped. If the sub FSM ends otherwise, this node will return Success.")]
[ParadoxNotion.Design.Icon("FSM")]
[DropReferenceType(typeof(FSM))]
public class NestedFSM : BTNodeNested<FSM>
{
[SerializeField, ExposeField, Name("Sub FSM")]
private BBParameter<FSM> _nestedFSM = null;
[HideInInspector] public string successState;
[HideInInspector] public string failureState;
public override FSM subGraph { get { return _nestedFSM.value; } set { _nestedFSM.value = value; } }
public override BBParameter subGraphParameter => _nestedFSM;
///----------------------------------------------------------------------------------------------
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( subGraph == null || subGraph.primeNode == null ) {
return Status.Optional;
}
if ( status == Status.Resting ) {
status = Status.Running;
this.TryStartSubGraph(agent, OnFSMFinish);
}
if ( status == Status.Running ) {
currentInstance.UpdateGraph(this.graph.deltaTime);
}
if ( !string.IsNullOrEmpty(successState) && currentInstance.currentStateName == successState ) {
currentInstance.Stop(true);
return Status.Success;
}
if ( !string.IsNullOrEmpty(failureState) && currentInstance.currentStateName == failureState ) {
currentInstance.Stop(false);
return Status.Failure;
}
return status;
}
void OnFSMFinish(bool success) {
if ( status == Status.Running ) {
status = success ? Status.Success : Status.Failure;
}
}
protected override void OnReset() {
if ( currentInstance != null ) {
currentInstance.Stop();
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeInspectorGUI() {
base.OnNodeInspectorGUI();
if ( subGraph != null ) {
successState = EditorUtils.Popup<string>("Success State", successState, subGraph.GetStateNames());
failureState = EditorUtils.Popup<string>("Failure State", failureState, subGraph.GetStateNames());
}
}
#endif
///----------------------------------------------------------------------------------------------
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 029908fbea5cdb44eb8daab6ea1ce96d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Leafs/NestedFSM.cs
uploadId: 704937

View File

@@ -0,0 +1,49 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Name("Sub Tree")]
[Description("Executes a sub Behaviour Tree. The status of the root node in the SubTree will be returned.")]
[ParadoxNotion.Design.Icon("BT")]
[DropReferenceType(typeof(BehaviourTree))]
public class SubTree : BTNodeNested<BehaviourTree>
{
[SerializeField, ExposeField]
private BBParameter<BehaviourTree> _subTree = null;
public override BehaviourTree subGraph { get { return _subTree.value; } set { _subTree.value = value; } }
public override BBParameter subGraphParameter => _subTree;
///----------------------------------------------------------------------------------------------
protected override Status OnExecute(Component agent, IBlackboard blackboard) {
if ( subGraph == null || subGraph.primeNode == null ) {
return Status.Optional;
}
if ( status == Status.Resting ) {
this.TryStartSubGraph(agent);
}
currentInstance.UpdateGraph(this.graph.deltaTime);
if ( currentInstance.repeat && currentInstance.rootStatus != Status.Running ) {
this.TryReadAndUnbindMappedVariables();
}
return currentInstance.rootStatus;
}
protected override void OnReset() {
if ( currentInstance != null ) {
currentInstance.Stop();
}
}
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 81a47db377388e443b24ae90ce6a83c8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/Nodes/Leafs/SubTree.cs
uploadId: 704937