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,9 @@
fileFormatVersion: 2
guid: 21af63cb2c48a3b4f829ae3b353031b9
folderAsset: yes
timeCreated: 1538758966
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,79 @@
#if UNITY_EDITOR
using UnityEditor;
using ParadoxNotion.Design;
using NodeCanvas.Framework;
namespace NodeCanvas.Editor
{
public static class Commands
{
///----------------------------------------------------------------------------------------------
[UnityEditor.InitializeOnLoadMethod]
public static void SetNodeCanvasDefine() {
DefinesManager.SetDefineActiveForCurrentTargetGroup("NODECANVAS", true);
}
///----------------------------------------------------------------------------------------------
[MenuItem("Assets/Create/ParadoxNotion/NodeCanvas/New Task")]
[MenuItem("Tools/ParadoxNotion/NodeCanvas/Create/New Task", false, 90)]
public static void ShowTaskWizard() {
TaskWizardWindow.ShowWindow();
}
///----------------------------------------------------------------------------------------------
[MenuItem("Tools/ParadoxNotion/NodeCanvas/Create/Global Scene Blackboard", false, 10)]
public static void CreateGlobalSceneBlackboard() {
Selection.activeObject = GlobalBlackboard.Create();
}
[MenuItem("Tools/ParadoxNotion/NodeCanvas/Preferred Types Editor")]
public static void ShowPrefTypes() {
TypePrefsEditorWindow.ShowWindow();
}
[MenuItem("Tools/ParadoxNotion/NodeCanvas/Graph Console")]
public static void OpenConsole() {
GraphConsole.ShowWindow();
}
[MenuItem("Tools/ParadoxNotion/NodeCanvas/Graph Explorer")]
public static void OpenExplorer() {
GraphExplorer.ShowWindow();
}
[MenuItem("Tools/ParadoxNotion/NodeCanvas/Graph Refactor")]
public static void OpenRefactor() {
GraphRefactor.ShowWindow();
}
[MenuItem("Tools/ParadoxNotion/NodeCanvas/Active Owners Overview")]
public static void OpenOwnersOverview() {
ActiveOwnersOverview.ShowWindow();
}
[MenuItem("Tools/ParadoxNotion/NodeCanvas/External Inspector Panel")]
public static void ShowExternalInspector() {
ExternalInspectorWindow.ShowWindow();
}
///----------------------------------------------------------------------------------------------
[MenuItem("Tools/ParadoxNotion/NodeCanvas/Welcome Window")]
public static void ShowWelcome() {
WelcomeWindow.ShowWindow(typeof(NodeCanvas.BehaviourTrees.BehaviourTree));
}
[MenuItem("Tools/ParadoxNotion/NodeCanvas/Website...")]
public static void VisitWebsite() {
Help.BrowseURL("https://nodecanvas.paradoxnotion.com");
}
}
}
#endif

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 97bfc0240961cfa46965bb2a0b5cd48c
timeCreated: 1462124021
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/Editor/Commands.cs
uploadId: 704937

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 83195f27791c80849984b2dfe458acea
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
#if UNITY_EDITOR
using ParadoxNotion.Design;
using UnityEngine;
using NodeCanvas.DialogueTrees;
namespace NodeCanvas.Editor
{
///<summary>A drawer for dialogue tree statements</summary>
public class StatementDrawer : ObjectDrawer<Statement>
{
public override Statement OnGUI(GUIContent content, Statement instance) {
if ( instance == null ) { instance = new Statement("..."); }
instance.text = UnityEditor.EditorGUILayout.TextArea(instance.text, Styles.wrapTextArea, GUILayout.Height(100));
instance.audio = UnityEditor.EditorGUILayout.ObjectField("Audio File", instance.audio, typeof(AudioClip), false) as AudioClip;
instance.meta = UnityEditor.EditorGUILayout.TextField("Metadata", instance.meta);
return instance;
}
}
}
#endif

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 0bfe262bb61820c468a50914a8a115fa
timeCreated: 1514571230
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/Editor/Drawers/StatementDrawer.cs
uploadId: 704937

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 03b4f67804ea6004ca5a0d6d3c2fa242
folderAsset: yes
timeCreated: 1538791284
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
namespace NodeCanvas.Editor
{
[CustomEditor(typeof(ActionListPlayer))]
public class ActionListPlayerInspector : UnityEditor.Editor
{
private ActionListPlayer list {
get { return (ActionListPlayer)target; }
}
public override void OnInspectorGUI() {
GUI.skin.label.richText = true;
GUILayout.Space(10);
list.playOnAwake = EditorGUILayout.Toggle("Play On Awake", list.playOnAwake);
list.blackboard = (Blackboard)EditorGUILayout.ObjectField("Target Blackboard", (Blackboard)list.blackboard, typeof(Blackboard), true);
TaskEditor.TaskFieldSingle(list.actionList, null, false);
EditorUtils.EndOfInspector();
if ( Event.current.isMouse || list.actionList.isRunning ) {
Repaint();
}
}
}
}
#endif

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: fbf729746d7bc944680ce1f47ea78b92
timeCreated: 1435079900
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/Editor/Inspectors/ActionListPlayerInspector.cs
uploadId: 704937

View File

@@ -0,0 +1,31 @@
#if UNITY_EDITOR
using NodeCanvas.BehaviourTrees;
using ParadoxNotion;
using UnityEditor;
using UnityEngine;
namespace NodeCanvas.Editor
{
[CustomEditor(typeof(BehaviourTreeOwner))]
public class BehaviourTreeOwnerInspector : GraphOwnerInspector
{
private BehaviourTreeOwner owner {
get { return target as BehaviourTreeOwner; }
}
protected override void OnPreExtraGraphOptions() {
ParadoxNotion.Design.EditorUtils.Separator();
owner.repeat = EditorGUILayout.Toggle("Repeat", owner.repeat);
if ( owner.repeat ) {
GUI.color = Color.white.WithAlpha(owner.updateInterval > 0 ? 1 : 0.5f);
owner.updateInterval = EditorGUILayout.FloatField("Update Interval", owner.updateInterval);
GUI.color = Color.white;
}
}
}
}
#endif

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 2c0a6b566c1d2e24eab536c326773e7d
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/Editor/Inspectors/BehaviourTreeOwnerInspector.cs
uploadId: 704937

View File

@@ -0,0 +1,23 @@
#if UNITY_EDITOR
using NodeCanvas.DialogueTrees;
using UnityEditor;
namespace NodeCanvas.Editor
{
[CustomEditor(typeof(DialogueTreeController))]
public class DialogueTreeControllerInspector : GraphOwnerInspector
{
private DialogueTreeController controller {
get { return target as DialogueTreeController; }
}
protected override void OnPostExtraGraphOptions() {
if ( controller.graph != null ) { DialogueTreeInspector.ShowActorParameters((DialogueTree)controller.graph); }
}
}
}
#endif

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 7500d819cd85a144097dbf09c905400c
timeCreated: 1478952843
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/Editor/Inspectors/DialogueTreeControllerInspector.cs
uploadId: 704937

View File

@@ -0,0 +1,84 @@
#if UNITY_EDITOR
using System.Linq;
using NodeCanvas.DialogueTrees;
using ParadoxNotion.Design;
using UnityEditor;
using UnityEngine;
namespace NodeCanvas.Editor
{
[CustomEditor(typeof(DialogueTree))]
public class DialogueTreeInspector : GraphInspector
{
private DialogueTree dialogue {
get { return target as DialogueTree; }
}
public override void OnInspectorGUI() {
base.OnInspectorGUI();
ShowActorParameters(dialogue);
EditorUtils.EndOfInspector();
if ( GUI.changed ) { UndoUtility.SetDirty(dialogue); }
}
//static because it's also used from DialogueTreeController
public static void ShowActorParameters(DialogueTree dialogue) {
EditorUtils.CoolLabel("Dialogue Actor Parameters");
EditorGUILayout.HelpBox("Enter the Key-Value pair for Dialogue Actors involved in the Dialogue.\nThe reference Object must be an IDialogueActor or have an IDialogueActor component.\nReferencing a Dialogue Actor is optional.", MessageType.Info);
GUILayout.BeginVertical(GUI.skin.box);
if ( GUILayout.Button("Add Actor Parameter") ) {
UndoUtility.RecordObject(dialogue, "New Actor Parameter");
dialogue.actorParameters.Add(new DialogueTree.ActorParameter("actor parameter name"));
UndoUtility.SetDirty(dialogue);
}
EditorGUILayout.LabelField(DialogueTree.INSTIGATOR_NAME + " --> Replaced by the Actor starting the Dialogue");
var options = new EditorUtils.ReorderableListOptions();
options.allowAdd = false;
options.allowRemove = true;
options.unityObjectContext = dialogue;
EditorUtils.ReorderableList(dialogue.actorParameters, options, (i, picked) =>
{
var reference = dialogue.actorParameters[i];
GUILayout.BeginHorizontal();
if ( dialogue.actorParameters.Where(r => r != reference).Select(r => r.name).Contains(reference.name) ) {
GUI.backgroundColor = Color.red;
}
var newRefName = EditorGUILayout.DelayedTextField(reference.name);
if ( newRefName != reference.name ) {
UndoUtility.RecordObject(dialogue, "Actor Parameter Name Change");
reference.name = newRefName;
UndoUtility.SetDirty(dialogue);
}
GUI.backgroundColor = Color.white;
var newReference = (Object)EditorGUILayout.ObjectField(reference.actor as Object, typeof(Object), true);
if ( !ReferenceEquals(newReference, reference.actor) ) {
UndoUtility.RecordObject(dialogue, "Actor Assignment");
//all this jazz because ObjectField does not work with interfaces...
if ( newReference == null ) {
reference.actor = null;
} else {
if ( newReference is Component ) { newReference = ( newReference as Component ).GetComponent(typeof(IDialogueActor)); }
if ( newReference is GameObject ) { newReference = ( newReference as GameObject ).GetComponent(typeof(IDialogueActor)); }
if ( newReference is IDialogueActor ) {
reference.actor = (IDialogueActor)newReference;
} else { ParadoxNotion.Services.Logger.LogWarning("Object is not an IDialogueActor and none of the components attached is an IDialogueActor either."); }
}
UndoUtility.SetDirty(dialogue);
}
GUILayout.EndHorizontal();
});
GUILayout.EndVertical();
}
}
}
#endif

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 8eb93d789c99f9740a5607b35373ba73
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/Editor/Inspectors/DialogueTreeInspector.cs
uploadId: 704937

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4b96917df5b826b42aca7c0146350c6c
folderAsset: yes
timeCreated: 1538756895
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 041e18f0c8aec704cb1d5550618b04c5
folderAsset: yes
timeCreated: 1435255793
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,119 @@
using UnityEngine;
using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion.Serialization;
namespace NodeCanvas
{
[AddComponentMenu("NodeCanvas/Standalone Action List (Bonus)")]
public class ActionListPlayer : MonoBehaviour, ITaskSystem, ISerializationCallbackReceiver
{
public bool playOnAwake;
[SerializeField] private string _serializedList;
[SerializeField] private List<UnityEngine.Object> _objectReferences;
[SerializeField] private Blackboard _blackboard;
[System.NonSerialized]
private ActionList _actionList;
private float timeStarted;
void ISerializationCallbackReceiver.OnBeforeSerialize() {
// if ( ParadoxNotion.Services.Threader.applicationIsPlaying ) { return; }
_objectReferences = new List<UnityEngine.Object>();
_serializedList = JSONSerializer.Serialize(typeof(ActionList), _actionList, _objectReferences);
}
void ISerializationCallbackReceiver.OnAfterDeserialize() {
_actionList = JSONSerializer.Deserialize<ActionList>(_serializedList, _objectReferences);
if ( _actionList == null ) _actionList = (ActionList)Task.Create(typeof(ActionList), this);
}
///----------------------------------------------------------------------------------------------
public ActionList actionList => _actionList;
public float elapsedTime => Time.time - timeStarted;
public float deltaTime => Time.deltaTime;
Object ITaskSystem.contextObject => this;
Component ITaskSystem.agent => this;
public IBlackboard blackboard {
get { return _blackboard; }
set
{
if ( !ReferenceEquals(_blackboard, value) ) {
_blackboard = (Blackboard)(object)value;
UpdateTasksOwner();
}
}
}
///----------------------------------------------------------------------------------------------
public static ActionListPlayer Create() {
return new GameObject("ActionList").AddComponent<ActionListPlayer>();
}
protected void Awake() {
UpdateTasksOwner();
if ( playOnAwake ) {
Play();
}
}
public void UpdateTasksOwner() {
actionList.SetOwnerSystem(this);
foreach ( var a in actionList.actions ) {
a.SetOwnerSystem(this);
BBParameter.SetBBFields(a, blackboard);
}
}
void ITaskSystem.SendEvent(string name, object value, object sender) {
ParadoxNotion.Services.Logger.LogWarning("Sending events to standalone action lists has no effect", LogTag.EXECUTION, this);
}
void ITaskSystem.SendEvent<T>(string name, T value, object sender) {
ParadoxNotion.Services.Logger.LogWarning("Sending events to standalone action lists has no effect", LogTag.EXECUTION, this);
}
[ContextMenu("Play")]
public void Play() { Play(this, this.blackboard, null); }
public void Play(System.Action<Status> OnFinish) { Play(this, this.blackboard, OnFinish); }
public void Play(Component agent, IBlackboard blackboard, System.Action<Status> OnFinish) {
if ( Application.isPlaying ) {
timeStarted = Time.time;
actionList.ExecuteIndependent(agent, blackboard, OnFinish);
}
}
public Status Execute() { return actionList.Execute(this, blackboard); }
public Status Execute(Component agent) { return actionList.Execute(agent, blackboard); }
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
[UnityEditor.MenuItem("Tools/ParadoxNotion/NodeCanvas/Create/Standalone Action List", false, 3)]
static void CreateActionListPlayer() {
UnityEditor.Selection.activeObject = Create();
}
void Reset() {
var bb = GetComponent<Blackboard>();
_blackboard = bb != null ? bb : gameObject.AddComponent<Blackboard>();
_actionList = (ActionList)Task.Create(typeof(ActionList), this);
}
void OnValidate() {
if ( !Application.isPlaying && !UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode ) {
UpdateTasksOwner();
}
}
#endif
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 771e8d04ad23ec04ca6178c3be664c99
timeCreated: 1435079338
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/ActionListPlayer/ActionListPlayer.cs
uploadId: 704937

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3e4c919d6c8ace54abe33fbe755d92f0
folderAsset: yes
timeCreated: 1448983354
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
using NodeCanvas.Framework;
namespace NodeCanvas.BehaviourTrees
{
///<summary>The connection object for BehaviourTree nodes</summary>
public class BTConnection : Connection
{
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: a30540c2f2ef9254686deec5ba838b26
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/BTConnection.cs
uploadId: 704937

View File

@@ -0,0 +1,52 @@
using ParadoxNotion;
using NodeCanvas.Framework;
namespace NodeCanvas.BehaviourTrees
{
///<summary> Super Base class for BehaviourTree nodes that can live within a BehaviourTree Graph.</summary>
abstract public class BTNode : Node
{
sealed public override System.Type outConnectionType { get { return typeof(BTConnection); } }
sealed public override bool allowAsPrime { get { return true; } }
sealed public override bool canSelfConnect { get { return false; } }
public override Alignment2x2 commentsAlignment { get { return Alignment2x2.Bottom; } }
public override Alignment2x2 iconAlignment { get { return Alignment2x2.Default; } }
public override int maxInConnections { get { return 1; } }
public override int maxOutConnections { get { return 0; } }
///<summary>Add a child node to this node connected to the specified child index</summary>
public T AddChild<T>(int childIndex) where T : BTNode {
if ( outConnections.Count >= maxOutConnections && maxOutConnections != -1 ) {
return null;
}
var child = graph.AddNode<T>();
graph.ConnectNodes(this, child, childIndex);
return child;
}
///<summary>Add a child node to this node connected last</summary>
public T AddChild<T>() where T : BTNode {
if ( outConnections.Count >= maxOutConnections && maxOutConnections != -1 ) {
return null;
}
var child = graph.AddNode<T>();
graph.ConnectNodes(this, child);
return child;
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override UnityEditor.GenericMenu OnContextMenu(UnityEditor.GenericMenu menu) {
menu.AddItem(new UnityEngine.GUIContent("Breakpoint"), isBreakpoint, () => { isBreakpoint = !isBreakpoint; });
return ParadoxNotion.Design.EditorUtils.GetTypeSelectionMenu(typeof(BTDecorator), (t) => { this.DecorateWith(t); }, menu, "Decorate");
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 36c47b59831d8804eb0ff34bcb2622a7
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/BTNode.cs
uploadId: 704937

View File

@@ -0,0 +1,26 @@
using System.Collections.Generic;
using NodeCanvas.Framework;
using NodeCanvas.Framework.Internal;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
[Category("SubGraphs")]
[Color("ffe4e1")]
abstract public class BTNodeNested<T> : BTNode, IGraphAssignable<T> where T : Graph
{
[SerializeField] private List<BBMappingParameter> _variablesMap;
abstract public T subGraph { get; set; }
abstract public BBParameter subGraphParameter { get; }
public T currentInstance { get; set; }
public Dictionary<Graph, Graph> instances { get; set; }
public List<BBMappingParameter> variablesMap { get { return _variablesMap; } set { _variablesMap = value; } }
Graph IGraphAssignable.subGraph { get { return subGraph; } set { subGraph = (T)value; } }
Graph IGraphAssignable.currentInstance { get { return currentInstance; } set { currentInstance = (T)value; } }
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 446133630245ab947a1bef9bbc5d5aa3
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/BTNodeNested.cs
uploadId: 704937

View File

@@ -0,0 +1,115 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
///<summary> BehaviourTrees are used to create advanced AI and logic based on simple rules.</summary>
[GraphInfo(
packageName = "NodeCanvas",
docsURL = "https://nodecanvas.paradoxnotion.com/documentation/",
resourcesURL = "https://nodecanvas.paradoxnotion.com/downloads/",
forumsURL = "https://nodecanvas.paradoxnotion.com/forums-page/"
)]
[CreateAssetMenu(menuName = "ParadoxNotion/NodeCanvas/Behaviour Tree Asset")]
public class BehaviourTree : Graph
{
///----------------------------------------------------------------------------------------------
[System.Serializable]
class DerivedSerializationData
{
public bool repeat;
public float updateInterval;
}
public override object OnDerivedDataSerialization() {
var data = new DerivedSerializationData();
data.repeat = this.repeat;
data.updateInterval = this.updateInterval;
return data;
}
public override void OnDerivedDataDeserialization(object data) {
if ( data is DerivedSerializationData ) {
this.repeat = ( (DerivedSerializationData)data ).repeat;
this.updateInterval = ( (DerivedSerializationData)data ).updateInterval;
}
}
///----------------------------------------------------------------------------------------------
///<summary>Should the tree repeat forever?</summary>
[System.NonSerialized] public bool repeat = true;
///<summary>The frequency in seconds for the tree to repeat if set to repeat.</summary>
[System.NonSerialized] public float updateInterval = 0;
///<summary>Raised when the root status of the behaviour is changed</summary>
public static event System.Action<BehaviourTree, Status> onRootStatusChanged;
private float intervalCounter;
private Status _rootStatus = Status.Resting;
///<summary>The last status of the root node</summary>
public Status rootStatus {
get { return _rootStatus; }
private set
{
if ( _rootStatus != value ) {
_rootStatus = value;
if ( onRootStatusChanged != null ) {
onRootStatusChanged(this, value);
}
}
}
}
///----------------------------------------------------------------------------------------------
public override System.Type baseNodeType => typeof(BTNode);
public override bool requiresAgent => true;
public override bool requiresPrimeNode => true;
public override bool isTree => true;
public override bool allowBlackboardOverrides => true;
sealed public override bool canAcceptVariableDrops => false;
public override ParadoxNotion.PlanarDirection flowDirection => ParadoxNotion.PlanarDirection.Vertical;
///----------------------------------------------------------------------------------------------
protected override void OnGraphStarted() {
intervalCounter = updateInterval;
rootStatus = primeNode.status;
}
protected override void OnGraphUpdate() {
if ( intervalCounter >= updateInterval ) {
intervalCounter = 0;
if ( Tick(agent, blackboard) != Status.Running && !repeat ) {
Stop(rootStatus == Status.Success);
}
}
if ( updateInterval > 0 ) {
intervalCounter += Time.deltaTime;
}
}
///<summary>Tick the tree once for the provided agent and with the provided blackboard</summary>
Status Tick(Component agent, IBlackboard blackboard) {
if ( rootStatus != Status.Running ) { primeNode.Reset(); }
return rootStatus = primeNode.Execute(agent, blackboard);
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
[UnityEditor.MenuItem("Tools/ParadoxNotion/NodeCanvas/Create/Behaviour Tree Asset", false, 0)]
static void Editor_CreateGraph() {
var newGraph = EditorUtils.CreateAsset<BehaviourTree>();
UnityEditor.Selection.activeObject = newGraph;
}
#endif
}
}

View File

@@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: 7a686a47eee2fa44cb0a34b5d86e4d5e
labels:
- AI
- behaviourtree
- visualscripting
- behaviour
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/BehaviourTree.cs
uploadId: 704937

View File

@@ -0,0 +1,148 @@
#if UNITY_EDITOR
using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using System.Linq;
namespace NodeCanvas.BehaviourTrees
{
public static class BehaviourTreeExtensions
{
///<summary>Replace the node with another</summary>
public static Node ReplaceWith(this Node node, System.Type t) {
var newNode = node.graph.AddNode(t, node.position);
foreach ( var c in node.inConnections.ToArray() ) {
c.SetTargetNode(newNode);
}
foreach ( var c in node.outConnections.ToArray() ) {
c.SetSourceNode(newNode);
}
if ( node.graph.primeNode == node ) {
node.graph.primeNode = newNode;
}
if ( node is ITaskAssignable && newNode is ITaskAssignable ) {
var assignableNode = node as ITaskAssignable;
var assignableNewNode = newNode as ITaskAssignable;
try { assignableNewNode.task = assignableNode.task; }
catch { /* cant assign */ }
}
node.graph.RemoveNode(node);
return newNode;
}
///<summary>Create a new SubTree out of the branch of the provided root node</summary>
public static BehaviourTree ConvertToSubTree(this BTNode root) {
if ( !UnityEditor.EditorUtility.DisplayDialog("Convert to SubTree", "This will create a new SubTree out of this branch.\nAre you sure?", "Yes", "No!") ) {
return null;
}
var newBT = EditorUtils.CreateAsset<BehaviourTree>();
if ( newBT == null ) {
return null;
}
var subTreeNode = root.graph.AddNode<SubTree>(root.position);
subTreeNode.subGraph = newBT;
for ( var i = 0; i < root.inConnections.Count; i++ ) {
root.inConnections[i].SetTargetNode(subTreeNode);
}
root.inConnections.Clear();
newBT.primeNode = DuplicateBranch(root, newBT);
DeleteBranch(root);
UnityEditor.AssetDatabase.SaveAssets();
return newBT;
}
///<summary>Delete the whole branch of provided root node along with the root node</summary>
public static void DeleteBranch(this BTNode root) {
var graph = root.graph;
foreach ( var node in root.GetAllChildNodesRecursively(true).ToArray() ) {
graph.RemoveNode(node);
}
}
///<summary>Duplicate a node along with all children hierarchy</summary>
public static Node DuplicateBranch(this BTNode root, Graph targetGraph) {
if ( targetGraph == null ) {
return null;
}
var newNode = root.Duplicate(targetGraph);
var dupConnections = new List<Connection>();
for ( var i = 0; i < root.outConnections.Count; i++ ) {
dupConnections.Add(root.outConnections[i].Duplicate(newNode, DuplicateBranch((BTNode)root.outConnections[i].targetNode, targetGraph)));
}
newNode.outConnections.Clear();
foreach ( var c in dupConnections ) {
newNode.outConnections.Add(c);
}
return newNode;
}
///<summary>Decorates BT node with decorator type</summary>
public static Node DecorateWith(this BTNode node, System.Type t) {
var newNode = node.graph.AddNode(t, node.position + new UnityEngine.Vector2(0, -80));
if ( node.inConnections.Count == 0 ) {
node.graph.ConnectNodes(newNode, node);
} else {
var parent = node.inConnections[0].sourceNode;
var parentConnection = node.inConnections[0];
var index = parent.outConnections.IndexOf(parentConnection);
node.graph.RemoveConnection(parentConnection);
node.graph.ConnectNodes(newNode, node);
node.graph.ConnectNodes(parent, newNode, index);
NodeCanvas.Editor.GraphEditorUtility.activeElement = newNode;
}
return newNode;
}
///<summary>Fetch all child nodes of the node recursively, optionaly including this. In other words, this fetches the whole branch.</summary>
public static List<BTNode> GetAllChildNodesRecursively(this BTNode root, bool includeThis) {
var childList = new List<BTNode>();
if ( includeThis ) {
childList.Add(root);
}
foreach ( BTNode child in root.outConnections.Select(c => c.targetNode) ) {
childList.AddRange(child.GetAllChildNodesRecursively(true));
}
return childList;
}
///<summary>Fetch all child nodes of this node with their depth in regards to this node. So, first level children will have a depth of 1 while second level a depth of 2</summary>
public static Dictionary<BTNode, int> GetAllChildNodesWithDepthRecursively(this BTNode root, bool includeThis, int startIndex) {
var childList = new Dictionary<BTNode, int>();
if ( includeThis ) {
childList[root] = startIndex;
}
foreach ( BTNode child in root.outConnections.Select(c => c.targetNode) ) {
foreach ( var pair in child.GetAllChildNodesWithDepthRecursively(true, startIndex + 1) ) {
childList[pair.Key] = pair.Value;
}
}
return childList;
}
}
}
#endif

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 274b815aabe24fb4cb3b2db61d263a82
timeCreated: 1511235461
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/BehaviourTreeExtensions.cs
uploadId: 704937

View File

@@ -0,0 +1,42 @@
using NodeCanvas.Framework;
using UnityEngine;
namespace NodeCanvas.BehaviourTrees
{
///<summary> Use this component on a game object to behave based on a BehaviourTree.</summary>
[AddComponentMenu("NodeCanvas/Behaviour Tree Owner")]
public class BehaviourTreeOwner : GraphOwner<BehaviourTree>
{
///<summary>Should the assigned BT reset and re-execute after a cycle? Sets the BehaviourTree's repeat</summary>
public bool repeat {
get { return behaviour != null ? behaviour.repeat : true; }
set { if ( behaviour != null ) behaviour.repeat = value; }
}
///<summary>The interval in seconds to update the BT. 0 for every frame. Sets the BehaviourTree's updateInterval</summary>
public float updateInterval {
get { return behaviour != null ? behaviour.updateInterval : 0; }
set { if ( behaviour != null ) behaviour.updateInterval = value; }
}
///<summary>The last status of the assigned Behaviour Tree's root node (aka Start Node)</summary>
public Status rootStatus {
get { return behaviour != null ? behaviour.rootStatus : Status.Resting; }
}
///<summary>Ticks the assigned Behaviour Tree for this owner agent and returns it's root status</summary>
public Status Tick() {
if ( behaviour == null ) {
ParadoxNotion.Services.Logger.LogWarning("There is no Behaviour Tree assigned", LogTag.EXECUTION, gameObject);
return Status.Resting;
}
UpdateBehaviour();
return behaviour.rootStatus;
}
}
}

View File

@@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: aad115aca74ce3c4891b3f6de0b4aae8
labels:
- AI
- behaviourtree
- visualscripting
- behaviour
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: b5eeec78a0081094cb8dfeb83808d762, type: 3}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Modules/BehaviourTrees/BehaviourTreeOwner.cs
uploadId: 704937

View File

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

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

View File

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

View File

@@ -0,0 +1,11 @@
using NodeCanvas.Framework;
namespace NodeCanvas.DialogueTrees
{
public class DTConnection : Connection
{
}
}

View File

@@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: f681a39730ae5674fb66c8f78d455170
labels:
- Node
- visualscripting
- dialogue
- Graph
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/DialogueTrees/DTConnection.cs
uploadId: 704937

View File

@@ -0,0 +1,90 @@
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.DialogueTrees
{
///<summary> Base class for DialogueTree nodes that can live within a DialogueTree Graph.</summary>
abstract public class DTNode : Node
{
[SerializeField] private string _actorName = DialogueTree.INSTIGATOR_NAME;
[SerializeField] private string _actorParameterID;
public override string name {
get
{
if ( requireActorSelection ) {
if ( DLGTree.definedActorParameterNames.Contains(actorName) ) {
return string.Format("{0}", actorName);
}
return string.Format("<color=#d63e3e>* {0} *</color>", _actorName);
}
return base.name;
}
}
virtual public bool requireActorSelection { get { return true; } }
public override int maxInConnections { get { return -1; } }
public override int maxOutConnections { get { return 1; } }
sealed public override System.Type outConnectionType { get { return typeof(DTConnection); } }
sealed public override bool allowAsPrime { get { return true; } }
sealed public override bool canSelfConnect { get { return false; } }
sealed public override Alignment2x2 commentsAlignment { get { return Alignment2x2.Right; } }
sealed public override Alignment2x2 iconAlignment { get { return Alignment2x2.Bottom; } }
protected DialogueTree DLGTree {
get { return (DialogueTree)graph; }
}
///<summary>The key name actor parameter to be used for this node</summary>
public string actorName {
get
{
var result = DLGTree.GetParameterByID(_actorParameterID);
return result != null ? result.name : _actorName;
}
private set
{
if ( _actorName != value && !string.IsNullOrEmpty(value) ) {
_actorName = value;
var param = DLGTree.GetParameterByName(value);
_actorParameterID = param != null ? param.ID : null;
}
}
}
///<summary>The DialogueActor that will execute the node</summary>
public IDialogueActor finalActor {
get
{
var result = DLGTree.GetActorReferenceByID(_actorParameterID);
return result != null ? result : DLGTree.GetActorReferenceByName(_actorName);
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnNodeInspectorGUI() {
if ( requireActorSelection ) {
GUI.backgroundColor = Colors.lightBlue;
actorName = EditorUtils.Popup<string>(actorName, DLGTree.definedActorParameterNames);
GUI.backgroundColor = Color.white;
}
base.OnNodeInspectorGUI();
}
protected override UnityEditor.GenericMenu OnContextMenu(UnityEditor.GenericMenu menu) {
menu.AddItem(new GUIContent("Breakpoint"), isBreakpoint, () => { isBreakpoint = !isBreakpoint; });
return menu;
}
#endif
}
}

Some files were not shown because too many files have changed in this diff Show More