Add Asset "Behavior Designer"
This commit is contained in:
parent
460b8107cf
commit
c72b97cc61
4
BlueWater/Assets/Behavior Designer.meta
Normal file
4
BlueWater/Assets/Behavior Designer.meta
Normal file
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b303277dfa449d4a93437535228816d
|
||||
DefaultImporter:
|
||||
userData:
|
BIN
BlueWater/Assets/Behavior Designer/Documentation.pdf
Normal file
BIN
BlueWater/Assets/Behavior Designer/Documentation.pdf
Normal file
Binary file not shown.
11
BlueWater/Assets/Behavior Designer/Documentation.pdf.meta
Normal file
11
BlueWater/Assets/Behavior Designer/Documentation.pdf.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4646946da2762db46a08e76a6c42f832
|
||||
DefaultImporter:
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Documentation.pdf
|
||||
uploadId: 598781
|
2
BlueWater/Assets/Behavior Designer/Editor.meta
Normal file
2
BlueWater/Assets/Behavior Designer/Editor.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3aa7d582439bc2f4da8254d1364e0f41
|
Binary file not shown.
@ -0,0 +1,40 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af72b091e5876924c9ab327b2d8de270
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Editor/BehaviorDesigner.Editor.dll
|
||||
uploadId: 598781
|
@ -0,0 +1,11 @@
|
||||
using UnityEditor;
|
||||
using BehaviorDesigner.Runtime;
|
||||
|
||||
namespace BehaviorDesigner.Editor
|
||||
{
|
||||
[CustomEditor(typeof(BehaviorTree))]
|
||||
public class BehaviorTreeInspector : BehaviorInspector
|
||||
{
|
||||
// intentionally left blank
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94693c6931cea70439c26417a1fc0d33
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Editor/BehaviorTreeInspector.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using BehaviorDesigner.Runtime;
|
||||
|
||||
namespace BehaviorDesigner.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ExternalBehaviorTree))]
|
||||
public class ExternalBehaviorTreeInspector : ExternalBehaviorInspector
|
||||
{
|
||||
// intentionally left blank
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f0cb79f53e760c4d950b8c6ade6a242
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Editor/ExternalBehaviorTreeInspector.cs
|
||||
uploadId: 598781
|
44
BlueWater/Assets/Behavior Designer/Editor/GridShader.shader
Normal file
44
BlueWater/Assets/Behavior Designer/Editor/GridShader.shader
Normal file
@ -0,0 +1,44 @@
|
||||
Shader "Hidden/Behavior Designer/Grid" {
|
||||
SubShader {
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
fixed4 frag(v2f_img i) : Color {
|
||||
return fixed4(0.21, 0.21, 0.21, 1);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
fixed4 frag(v2f_img i) : Color {
|
||||
return fixed4(0.33, 0.33, 0.33, 1);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
fixed4 frag(v2f_img i) : Color {
|
||||
return fixed4(0.26, 0.26, 0.26, 1);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
fixed4 frag(v2f_img i) : Color {
|
||||
return fixed4(0.27, 0.27, 0.27, 1);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afbd9f0fb1c22d1409403fdef158479f
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Editor/GridShader.shader
|
||||
uploadId: 598781
|
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 956347559c803f7489f75873ef2715e5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using BehaviorDesigner.Runtime;
|
||||
using BehaviorDesigner.Runtime.ObjectDrawers;
|
||||
|
||||
namespace BehaviorDesigner.Editor.ObjectDrawers
|
||||
{
|
||||
[CustomObjectDrawer(typeof(FloatSliderAttribute))]
|
||||
public class FloatSliderDrawer : ObjectDrawer
|
||||
{
|
||||
public override void OnGUI(GUIContent label)
|
||||
{
|
||||
var floatSliderAttribute = (FloatSliderAttribute)attribute;
|
||||
if (value is SharedFloat) {
|
||||
var sharedFloat = value as SharedFloat;
|
||||
sharedFloat.Value = EditorGUILayout.Slider(label, sharedFloat.Value, floatSliderAttribute.min, floatSliderAttribute.max);
|
||||
} else {
|
||||
value = EditorGUILayout.Slider(label, (float)value, floatSliderAttribute.min, floatSliderAttribute.max);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f0987c6ff37141458ff776277e2b65a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Editor/Object Drawers/FloatSliderDrawer.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using BehaviorDesigner.Runtime;
|
||||
using BehaviorDesigner.Runtime.ObjectDrawers;
|
||||
|
||||
namespace BehaviorDesigner.Editor.ObjectDrawers
|
||||
{
|
||||
[CustomObjectDrawer(typeof(IntSliderAttribute))]
|
||||
public class IntSliderDrawer : ObjectDrawer
|
||||
{
|
||||
public override void OnGUI(GUIContent label)
|
||||
{
|
||||
var intSliderAttribute = (IntSliderAttribute)attribute;
|
||||
if (value is SharedInt) {
|
||||
var sharedFloat = value as SharedInt;
|
||||
sharedFloat.Value = EditorGUILayout.IntSlider(label, sharedFloat.Value, intSliderAttribute.min, intSliderAttribute.max);
|
||||
} else {
|
||||
value = EditorGUILayout.IntSlider(label, (int)value, intSliderAttribute.min, intSliderAttribute.max);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed5dac524fa5f61468bb6ca49a556b3b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Editor/Object Drawers/IntSliderDrawer.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,146 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using BehaviorDesigner.Runtime.Tasks;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using Action = BehaviorDesigner.Runtime.Tasks.Action;
|
||||
|
||||
namespace BehaviorDesigner.Editor.ObjectDrawers
|
||||
{
|
||||
[CustomObjectDrawer(typeof(StackedAction))]
|
||||
public class StackedActionDrawer : ObjectDrawer
|
||||
{
|
||||
private ReorderableList reorderableList;
|
||||
private StackedAction lastStackedAction;
|
||||
|
||||
public override void OnGUI(GUIContent label)
|
||||
{
|
||||
var stackedAction = task as StackedAction;
|
||||
|
||||
stackedAction.comparisonType = (StackedAction.ComparisonType)FieldInspector.DrawField(stackedAction,
|
||||
new GUIContent("Comparison Type", "Specifies if the tasks should be traversed with an AND (Sequence) or an OR (Selector)."),
|
||||
stackedAction.GetType().GetField("comparisonType", BindingFlags.Instance | BindingFlags.Public),
|
||||
stackedAction.comparisonType);
|
||||
|
||||
stackedAction.graphLabel = (bool)FieldInspector.DrawField(stackedAction,
|
||||
new GUIContent("Graph Label", "Should the tasks be labeled within te graph?"),
|
||||
stackedAction.GetType().GetField("graphLabel", BindingFlags.Instance | BindingFlags.Public),
|
||||
stackedAction.graphLabel);
|
||||
|
||||
if (stackedAction.actions == null) {
|
||||
stackedAction.actions = new Action[0];
|
||||
}
|
||||
|
||||
if (reorderableList == null) {
|
||||
reorderableList = new ReorderableList(stackedAction.actions, typeof(Action), true, true, true, true);
|
||||
reorderableList.drawHeaderCallback += (Rect rect) =>
|
||||
{
|
||||
EditorGUI.LabelField(rect, "Actions");
|
||||
};
|
||||
reorderableList.onAddDropdownCallback += OnAddDropdownCallback;
|
||||
reorderableList.drawElementCallback += OnDrawElementCallback;
|
||||
reorderableList.onReorderCallback += OnReorderCallback;
|
||||
reorderableList.onSelectCallback += OnSelectCallback;
|
||||
reorderableList.onCanRemoveCallback += OnCanRemoveCallback;
|
||||
reorderableList.onRemoveCallback += OnRemoveCallback;
|
||||
}
|
||||
if (stackedAction != lastStackedAction) {
|
||||
lastStackedAction = stackedAction;
|
||||
var index = EditorPrefs.GetInt("BehaviorDesigner.StackedAction." + stackedAction.ID, -1);
|
||||
if (index < stackedAction.actions.Length) {
|
||||
reorderableList.index = index;
|
||||
}
|
||||
}
|
||||
if (reorderableList.index == -1 && stackedAction.actions.Length > 0) {
|
||||
reorderableList.index = 0;
|
||||
}
|
||||
reorderableList.DoLayoutList();
|
||||
|
||||
if (reorderableList.index >= 0 && stackedAction.actions != null && reorderableList.index < stackedAction.actions.Length) {
|
||||
var selectedAction = stackedAction.actions[reorderableList.index];
|
||||
EditorGUILayout.LabelField(selectedAction.GetType().Name, BehaviorDesignerUtility.BoldLabelGUIStyle);
|
||||
FieldInspector.DrawFields(selectedAction, selectedAction);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAddDropdownCallback(Rect buttonRect, ReorderableList list)
|
||||
{
|
||||
var addMenu = new GenericMenu();
|
||||
BehaviorDesignerWindow.instance.TaskList.AddTaskTypesToMenu(0, ref addMenu, null, typeof(StackedAction), string.Empty, false, OnAddTask);
|
||||
addMenu.ShowAsContext();
|
||||
}
|
||||
|
||||
private void OnAddTask(object obj)
|
||||
{
|
||||
var stackedAction = task as StackedAction;
|
||||
var actions = stackedAction.actions;
|
||||
Array.Resize(ref actions, actions.Length + 1);
|
||||
var taskType = obj as Type;
|
||||
actions[actions.Length - 1] = Activator.CreateInstance(taskType) as Action;
|
||||
reorderableList.list = stackedAction.actions = actions;
|
||||
reorderableList.index = actions.Length - 1;
|
||||
BehaviorDesignerWindow.instance.SaveBehavior();
|
||||
}
|
||||
|
||||
private void OnDrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
var stackedAction = task as StackedAction;
|
||||
if (stackedAction.actions == null || index >= stackedAction.actions.Length || stackedAction.actions[index] == null) {
|
||||
if (stackedAction.actions != null && index < stackedAction.actions.Length) {
|
||||
var actions = stackedAction.actions;
|
||||
ArrayUtility.RemoveAt(ref actions, index);
|
||||
reorderableList.list = stackedAction.actions = actions;
|
||||
BehaviorDesignerWindow.instance.SaveBehavior();
|
||||
}
|
||||
return;
|
||||
}
|
||||
EditorGUI.LabelField(rect, stackedAction.actions[index].GetType().Name);
|
||||
if (stackedAction.actions[index].NodeData == null || stackedAction.NodeData == null || !Application.isPlaying) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stackedAction.actions[index].NodeData.ExecutionStatus == TaskStatus.Success || stackedAction.actions[index].NodeData.ExecutionStatus == TaskStatus.Failure) {
|
||||
Texture2D texture;
|
||||
if (stackedAction.NodeData.IsReevaluating) {
|
||||
texture = stackedAction.actions[index].NodeData.ExecutionStatus == TaskStatus.Failure ? BehaviorDesignerUtility.ExecutionFailureRepeatTexture : BehaviorDesignerUtility.ExecutionSuccessRepeatTexture;
|
||||
} else {
|
||||
texture = stackedAction.actions[index].NodeData.ExecutionStatus == TaskStatus.Failure ? BehaviorDesignerUtility.ExecutionFailureTexture : BehaviorDesignerUtility.ExecutionSuccessTexture;
|
||||
}
|
||||
rect.x = rect.width + 8;
|
||||
rect.width = rect.height = 16;
|
||||
GUI.DrawTexture(rect, texture);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReorderCallback(ReorderableList list)
|
||||
{
|
||||
var stackedActions = task as StackedAction;
|
||||
stackedActions.actions = (Action[])list.list;
|
||||
BehaviorDesignerWindow.instance.SaveBehavior();
|
||||
}
|
||||
|
||||
private void OnSelectCallback(ReorderableList list)
|
||||
{
|
||||
EditorPrefs.SetInt("BehaviorDesigner.StackedAction." + task.ID, list.index);
|
||||
}
|
||||
|
||||
private bool OnCanRemoveCallback(ReorderableList list)
|
||||
{
|
||||
var stackedActions = task as StackedAction;
|
||||
return stackedActions.actions != null && stackedActions.actions.Length > 0;
|
||||
}
|
||||
|
||||
private void OnRemoveCallback(ReorderableList list)
|
||||
{
|
||||
var stackedAction = task as StackedAction;
|
||||
var actions = stackedAction.actions;
|
||||
ArrayUtility.RemoveAt(ref actions, list.index);
|
||||
reorderableList.list = stackedAction.actions = actions;
|
||||
BehaviorDesignerWindow.instance.SaveBehavior();
|
||||
|
||||
reorderableList.index -= 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dda1c5bd0726be428a9210c793769d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Editor/Object Drawers/StackedActionDrawer.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,144 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using BehaviorDesigner.Runtime.Tasks;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BehaviorDesigner.Editor.ObjectDrawers
|
||||
{
|
||||
[CustomObjectDrawer(typeof(StackedConditional))]
|
||||
public class StackedConditionalDrawer : ObjectDrawer
|
||||
{
|
||||
private ReorderableList reorderableList;
|
||||
private StackedConditional lastStackedConditional;
|
||||
|
||||
public override void OnGUI(GUIContent label)
|
||||
{
|
||||
var stackedConditional = task as StackedConditional;
|
||||
|
||||
stackedConditional.comparisonType = (StackedConditional.ComparisonType)FieldInspector.DrawField(stackedConditional,
|
||||
new GUIContent("Comparison Type", "Specifies if the tasks should be traversed with an AND (Sequence) or an OR (Selector)."),
|
||||
stackedConditional.GetType().GetField("comparisonType", BindingFlags.Instance | BindingFlags.Public),
|
||||
stackedConditional.comparisonType);
|
||||
|
||||
stackedConditional.graphLabel = (bool)FieldInspector.DrawField(stackedConditional,
|
||||
new GUIContent("Graph Label", "Should the tasks be labeled within te graph?"),
|
||||
stackedConditional.GetType().GetField("graphLabel", BindingFlags.Instance | BindingFlags.Public),
|
||||
stackedConditional.graphLabel);
|
||||
|
||||
if (stackedConditional.conditionals == null) {
|
||||
stackedConditional.conditionals = new Conditional[0];
|
||||
}
|
||||
|
||||
if (reorderableList == null) {
|
||||
reorderableList = new ReorderableList(stackedConditional.conditionals, typeof(Conditional), true, true, true, true);
|
||||
reorderableList.drawHeaderCallback += (Rect rect) =>
|
||||
{
|
||||
EditorGUI.LabelField(rect, "Conditionals");
|
||||
};
|
||||
reorderableList.onAddDropdownCallback += OnAddDropdownCallback;
|
||||
reorderableList.drawElementCallback += OnDrawElementCallback;
|
||||
reorderableList.onReorderCallback += OnReorderCallback;
|
||||
reorderableList.onSelectCallback += OnSelectCallback;
|
||||
reorderableList.onCanRemoveCallback += OnCanRemoveCallback;
|
||||
reorderableList.onRemoveCallback += OnRemoveCallback;
|
||||
}
|
||||
if (stackedConditional != lastStackedConditional) {
|
||||
lastStackedConditional = stackedConditional;
|
||||
var index = EditorPrefs.GetInt("BehaviorDesigner.StackedConditional." + stackedConditional.ID, -1);
|
||||
if (index < stackedConditional.conditionals.Length) {
|
||||
reorderableList.index = index;
|
||||
}
|
||||
}
|
||||
if (reorderableList.index == -1 && stackedConditional.conditionals.Length > 0) {
|
||||
reorderableList.index = 0;
|
||||
}
|
||||
reorderableList.DoLayoutList();
|
||||
|
||||
if (reorderableList.index >= 0 && stackedConditional.conditionals != null && reorderableList.index < stackedConditional.conditionals.Length) {
|
||||
var selectedConditional = stackedConditional.conditionals[reorderableList.index];
|
||||
EditorGUILayout.LabelField(selectedConditional.GetType().Name, BehaviorDesignerUtility.BoldLabelGUIStyle);
|
||||
FieldInspector.DrawFields(selectedConditional, selectedConditional);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAddDropdownCallback(Rect buttonRect, ReorderableList list)
|
||||
{
|
||||
var addMenu = new GenericMenu();
|
||||
BehaviorDesignerWindow.instance.TaskList.AddTaskTypesToMenu(2, ref addMenu, null, typeof(StackedConditional), string.Empty, false, OnAddTask);
|
||||
addMenu.ShowAsContext();
|
||||
}
|
||||
|
||||
private void OnAddTask(object obj)
|
||||
{
|
||||
var stackedConditional = task as StackedConditional;
|
||||
var conditionals = stackedConditional.conditionals;
|
||||
Array.Resize(ref conditionals, conditionals.Length + 1);
|
||||
var taskType = obj as Type;
|
||||
conditionals[conditionals.Length - 1] = Activator.CreateInstance(taskType) as Conditional;
|
||||
reorderableList.list = stackedConditional.conditionals = conditionals;
|
||||
reorderableList.index = conditionals.Length - 1;
|
||||
BehaviorDesignerWindow.instance.SaveBehavior();
|
||||
}
|
||||
|
||||
private void OnDrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
var stackedConditional = task as StackedConditional;
|
||||
if (stackedConditional.conditionals == null || index >= stackedConditional.conditionals.Length || stackedConditional.conditionals[index] == null) {
|
||||
if (stackedConditional.conditionals != null && index < stackedConditional.conditionals.Length) {
|
||||
var conditionals = stackedConditional.conditionals;
|
||||
ArrayUtility.RemoveAt(ref conditionals, index);
|
||||
reorderableList.list = stackedConditional.conditionals = conditionals;
|
||||
BehaviorDesignerWindow.instance.SaveBehavior();
|
||||
}
|
||||
return;
|
||||
}
|
||||
EditorGUI.LabelField(rect, stackedConditional.conditionals[index].GetType().Name);
|
||||
if (stackedConditional.conditionals[index].NodeData == null || stackedConditional.NodeData == null || !Application.isPlaying) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stackedConditional.conditionals[index].NodeData.ExecutionStatus == TaskStatus.Success || stackedConditional.conditionals[index].NodeData.ExecutionStatus == TaskStatus.Failure) {
|
||||
Texture2D texture;
|
||||
if (stackedConditional.NodeData.IsReevaluating) {
|
||||
texture = stackedConditional.conditionals[index].NodeData.ExecutionStatus == TaskStatus.Failure ? BehaviorDesignerUtility.ExecutionFailureRepeatTexture : BehaviorDesignerUtility.ExecutionSuccessRepeatTexture;
|
||||
} else {
|
||||
texture = stackedConditional.conditionals[index].NodeData.ExecutionStatus == TaskStatus.Failure ? BehaviorDesignerUtility.ExecutionFailureTexture : BehaviorDesignerUtility.ExecutionSuccessTexture;
|
||||
}
|
||||
rect.x = rect.width + 8;
|
||||
rect.width = rect.height = 16;
|
||||
GUI.DrawTexture(rect, texture);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReorderCallback(ReorderableList list)
|
||||
{
|
||||
var stackedConditionals = task as StackedConditional;
|
||||
stackedConditionals.conditionals = (Conditional[])list.list;
|
||||
BehaviorDesignerWindow.instance.SaveBehavior();
|
||||
}
|
||||
|
||||
private void OnSelectCallback(ReorderableList list)
|
||||
{
|
||||
EditorPrefs.SetInt("BehaviorDesigner.StackedConditional." + task.ID, list.index);
|
||||
}
|
||||
|
||||
private bool OnCanRemoveCallback(ReorderableList list)
|
||||
{
|
||||
var stackedConditionals = task as StackedConditional;
|
||||
return stackedConditionals.conditionals != null && stackedConditionals.conditionals.Length > 0;
|
||||
}
|
||||
|
||||
private void OnRemoveCallback(ReorderableList list)
|
||||
{
|
||||
var stackedConditional = task as StackedConditional;
|
||||
var conditionals = stackedConditional.conditionals;
|
||||
ArrayUtility.RemoveAt(ref conditionals, list.index);
|
||||
reorderableList.list = stackedConditional.conditionals = conditionals;
|
||||
BehaviorDesignerWindow.instance.SaveBehavior();
|
||||
|
||||
reorderableList.index -= 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d12c12988e4c954b81ed7f3cdd0a439
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Editor/Object Drawers/StackedConditionalDrawer.cs
|
||||
uploadId: 598781
|
9
BlueWater/Assets/Behavior Designer/Integrations.meta
Normal file
9
BlueWater/Assets/Behavior Designer/Integrations.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 519776d3d02747548a264d7d32320ab1
|
||||
folderAsset: yes
|
||||
timeCreated: 1536092918
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
BlueWater/Assets/Behavior Designer/Integrations/Readme.pdf
Normal file
BIN
BlueWater/Assets/Behavior Designer/Integrations/Readme.pdf
Normal file
Binary file not shown.
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a43abd9ecc0166043973a4ba6da07bf1
|
||||
DefaultImporter:
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Integrations/Readme.pdf
|
||||
uploadId: 598781
|
Binary file not shown.
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f76522f0ea27769479b1c38979bac10a
|
||||
DefaultImporter:
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime Source Code Location.pdf
|
||||
uploadId: 598781
|
2
BlueWater/Assets/Behavior Designer/Runtime.meta
Normal file
2
BlueWater/Assets/Behavior Designer/Runtime.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33b3095a3727f544dbe47311776edb53
|
Binary file not shown.
@ -0,0 +1,40 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da41a8dd3b5ec434a802d9b5a2a0a777
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/BehaviorDesigner.Runtime.dll
|
||||
uploadId: 598781
|
11
BlueWater/Assets/Behavior Designer/Runtime/BehaviorTree.cs
Normal file
11
BlueWater/Assets/Behavior Designer/Runtime/BehaviorTree.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime
|
||||
{
|
||||
// Wrapper for the Behavior class
|
||||
[AddComponentMenu("Behavior Designer/Behavior Tree")]
|
||||
public class BehaviorTree : Behavior
|
||||
{
|
||||
// intentionally left blank
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d7b55c7ecdb49a4a89fa5e6f9022861
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 5b5f458971c6fd5459c51a7b8079bc3b, type: 3}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/BehaviorTree.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,8 @@
|
||||
namespace BehaviorDesigner.Runtime
|
||||
{
|
||||
[System.Serializable]
|
||||
public class ExternalBehaviorTree : ExternalBehavior
|
||||
{
|
||||
// intentionally left blank
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b23f08d2ae4cba14087c1ed36193d82b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 5b5f458971c6fd5459c51a7b8079bc3b, type: 3}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/ExternalBehaviorTree.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29d0d8866b4fa984bbc7dbf5d988ebcc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
@ -0,0 +1,16 @@
|
||||
using BehaviorDesigner.Runtime.Tasks;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.ObjectDrawers
|
||||
{
|
||||
public class FloatSliderAttribute : ObjectDrawerAttribute
|
||||
{
|
||||
public float min;
|
||||
public float max;
|
||||
|
||||
public FloatSliderAttribute(float min, float max)
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92948bfcff9a1fc48834935ebb0dbdcb
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Object Drawers/FloatSliderAttribute.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,16 @@
|
||||
using BehaviorDesigner.Runtime.Tasks;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.ObjectDrawers
|
||||
{
|
||||
public class IntSliderAttribute : ObjectDrawerAttribute
|
||||
{
|
||||
public int min;
|
||||
public int max;
|
||||
|
||||
public IntSliderAttribute(int min, int max)
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2373bfe29d0e5bc47b88a46226aa6a61
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Object Drawers/IntSliderAttribute.cs
|
||||
uploadId: 598781
|
8
BlueWater/Assets/Behavior Designer/Runtime/Tasks.meta
Normal file
8
BlueWater/Assets/Behavior Designer/Runtime/Tasks.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cd36de769e955742bf9b7cf79fb671f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91c6a439cec3003498369e01301ee57a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
// Wrapper class for the Behavior Reference task. The Behavior Tree Reference task allows you to run another behavior tree within the current behavior tree.
|
||||
// One use for this task is if you have an unit that plays a series of tasks to attack. You may want the unit to attack at different points within
|
||||
// the behavior tree, and you want that attack to always be the same. Instead of copying and pasting the same tasks over and over you can just use
|
||||
// an external behavior and then the tasks are always guaranteed to be the same. This example is demonstrated in the RTS sample project located at
|
||||
// https://www.opsive.com/downloads/?pid=803.
|
||||
[TaskDescription("Behavior Tree Reference allows you to run another behavior tree within the current behavior tree.")]
|
||||
[HelpURL("https://www.opsive.com/support/documentation/behavior-designer/external-behavior-trees/")]
|
||||
[TaskIcon("BehaviorTreeReferenceIcon.png")]
|
||||
public class BehaviorTreeReference : BehaviorReference
|
||||
{
|
||||
// intentionally left blank - subclass of BehaviorReference
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af7b6fcbc7258f34aad1bb82b5b3fdc8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/BehaviorTreeReference.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Returns a TaskStatus of running. Will only stop when interrupted or a conditional abort is triggered.")]
|
||||
[TaskIcon("{SkinColor}IdleIcon.png")]
|
||||
public class Idle : Action
|
||||
{
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 759252a4ffada80419ef06ce1c625246
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/Idle.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Log is a simple task which will output the specified text and return success. It can be used for debugging.")]
|
||||
[TaskIcon("{SkinColor}LogIcon.png")]
|
||||
public class Log : Action
|
||||
{
|
||||
[Tooltip("Text to output to the log")]
|
||||
public SharedString text;
|
||||
[Tooltip("Is this text an error?")]
|
||||
public SharedBool logError;
|
||||
[Tooltip("Should the time be included in the log message?")]
|
||||
public SharedBool logTime;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
// Log the text and return success
|
||||
if (logError.Value) {
|
||||
Debug.LogError(logTime.Value ? string.Format("{0}: {1}", Time.time, text) : text);
|
||||
} else {
|
||||
Debug.Log(logTime.Value ? string.Format("{0}: {1}",Time.time, text) : text);
|
||||
}
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the properties back to their original values
|
||||
text = "";
|
||||
logError = false;
|
||||
logTime = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d53794347878c7c479da37533dce2024
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/Log.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,28 @@
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Perform the actual interruption. This will immediately stop the specified tasks from running and will return success or failure depending on the value of interrupt success.")]
|
||||
[TaskIcon("{SkinColor}PerformInterruptionIcon.png")]
|
||||
public class PerformInterruption : Action
|
||||
{
|
||||
[Tooltip("The list of tasks to interrupt. Can be any number of tasks")]
|
||||
public Interrupt[] interruptTasks;
|
||||
[Tooltip("When we interrupt the task should we return a task status of success?")]
|
||||
public SharedBool interruptSuccess;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
// Loop through all of the tasks and fire an interruption. Once complete return success.
|
||||
for (int i = 0; i < interruptTasks.Length; ++i) {
|
||||
interruptTasks[i].DoInterrupt(interruptSuccess.Value ? TaskStatus.Success : TaskStatus.Failure);
|
||||
}
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the properties back to their original values.
|
||||
interruptTasks = null;
|
||||
interruptSuccess = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72d2d6051b23e86468e2f715f044dad8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/PerformInterruption.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bbf15f7023452341aebe68861a3aabc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Gets the value from the field specified. Returns success if the field was retrieved.")]
|
||||
[TaskCategory("Reflection")]
|
||||
[TaskIcon("{SkinColor}ReflectionIcon.png")]
|
||||
public class GetFieldValue : Action
|
||||
{
|
||||
[Tooltip("The GameObject to get the field on")]
|
||||
public SharedGameObject targetGameObject;
|
||||
[Tooltip("The component to get the field on")]
|
||||
public SharedString componentName;
|
||||
[Tooltip("The name of the field")]
|
||||
public SharedString fieldName;
|
||||
[Tooltip("The value of the field")]
|
||||
[RequiredField]
|
||||
public SharedVariable fieldValue;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (fieldValue == null) {
|
||||
Debug.LogWarning("Unable to get field - field value is null");
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var type = TaskUtility.GetTypeWithinAssembly(componentName.Value);
|
||||
if (type == null) {
|
||||
Debug.LogWarning("Unable to get field - type is null");
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type);
|
||||
if (component == null) {
|
||||
Debug.LogWarning("Unable to get the field with component " + componentName.Value);
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
// If you are receiving a compiler error on the Windows Store platform see this topic:
|
||||
// https://www.opsive.com/support/documentation/behavior-designer/installation/
|
||||
var field = component.GetType().GetField(fieldName.Value);
|
||||
fieldValue.SetValue(field.GetValue(component));
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
targetGameObject = null;
|
||||
componentName = null;
|
||||
fieldName = null;
|
||||
fieldValue = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc317dd7feb2085499edb0d0c4604640
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/Reflection/GetFieldValue.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Gets the value from the property specified. Returns success if the property was retrieved.")]
|
||||
[TaskCategory("Reflection")]
|
||||
[TaskIcon("{SkinColor}ReflectionIcon.png")]
|
||||
public class GetPropertyValue : Action
|
||||
{
|
||||
[Tooltip("The GameObject to get the property of")]
|
||||
public SharedGameObject targetGameObject;
|
||||
[Tooltip("The component to get the property of")]
|
||||
public SharedString componentName;
|
||||
[Tooltip("The name of the property")]
|
||||
public SharedString propertyName;
|
||||
[Tooltip("The value of the property")]
|
||||
[RequiredField]
|
||||
public SharedVariable propertyValue;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (propertyValue == null) {
|
||||
Debug.LogWarning("Unable to get property - property value is null");
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var type = TaskUtility.GetTypeWithinAssembly(componentName.Value);
|
||||
if (type == null) {
|
||||
Debug.LogWarning("Unable to get property - type is null");
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type);
|
||||
if (component == null) {
|
||||
Debug.LogWarning("Unable to get the property with component " + componentName.Value);
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
// If you are receiving a compiler error on the Windows Store platform see this topic:
|
||||
// https://www.opsive.com/support/documentation/behavior-designer/installation/
|
||||
var property = component.GetType().GetProperty(propertyName.Value);
|
||||
propertyValue.SetValue(property.GetValue(component, null));
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
targetGameObject = null;
|
||||
componentName = null;
|
||||
propertyName = null;
|
||||
propertyValue = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dda9c9b7c6ff2ee4f95a2e208cddae64
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/Reflection/GetPropertyValue.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,84 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Invokes the specified method with the specified parameters. Can optionally store the return value. Returns success if the method was invoked.")]
|
||||
[TaskCategory("Reflection")]
|
||||
[TaskIcon("{SkinColor}ReflectionIcon.png")]
|
||||
public class InvokeMethod : Action
|
||||
{
|
||||
[Tooltip("The GameObject to invoke the method on")]
|
||||
public SharedGameObject targetGameObject;
|
||||
[Tooltip("The component to invoke the method on")]
|
||||
public SharedString componentName;
|
||||
[Tooltip("The name of the method")]
|
||||
public SharedString methodName;
|
||||
[Tooltip("The first parameter of the method")]
|
||||
public SharedVariable parameter1;
|
||||
[Tooltip("The second parameter of the method")]
|
||||
public SharedVariable parameter2;
|
||||
[Tooltip("The third parameter of the method")]
|
||||
public SharedVariable parameter3;
|
||||
[Tooltip("The fourth parameter of the method")]
|
||||
public SharedVariable parameter4;
|
||||
[Tooltip("Store the result of the invoke call")]
|
||||
public SharedVariable storeResult;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
var type = TaskUtility.GetTypeWithinAssembly(componentName.Value);
|
||||
if (type == null) {
|
||||
Debug.LogWarning("Unable to invoke - type is null");
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type);
|
||||
if (component == null) {
|
||||
Debug.LogWarning("Unable to invoke method with component " + componentName.Value);
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var parameterList = new List<object>();
|
||||
var parameterTypeList = new List<Type>();
|
||||
SharedVariable sharedVariable = null;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
var parameterField = GetType().GetField("parameter" + (i + 1));
|
||||
if ((sharedVariable = parameterField.GetValue(this) as SharedVariable) != null) {
|
||||
parameterList.Add(sharedVariable.GetValue());
|
||||
parameterTypeList.Add(sharedVariable.GetType().GetProperty("Value").PropertyType);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If you are receiving a compiler error on the Windows Store platform see this topic:
|
||||
// https://www.opsive.com/support/documentation/behavior-designer/installation/
|
||||
var methodInfo = component.GetType().GetMethod(methodName.Value, parameterTypeList.ToArray());
|
||||
|
||||
if (methodInfo == null) {
|
||||
Debug.LogWarning("Unable to invoke method " + methodName.Value + " on component " + componentName.Value);
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var result = methodInfo.Invoke(component, parameterList.ToArray());
|
||||
if (storeResult != null) {
|
||||
storeResult.SetValue(result);
|
||||
}
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
targetGameObject = null;
|
||||
componentName = null;
|
||||
methodName = null;
|
||||
parameter1 = null;
|
||||
parameter2 = null;
|
||||
parameter3 = null;
|
||||
parameter4 = null;
|
||||
storeResult = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 359bd67578f53034ab2eb00e7696d317
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/Reflection/InvokeMethod.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Sets the field to the value specified. Returns success if the field was set.")]
|
||||
[TaskCategory("Reflection")]
|
||||
[TaskIcon("{SkinColor}ReflectionIcon.png")]
|
||||
public class SetFieldValue : Action
|
||||
{
|
||||
[Tooltip("The GameObject to set the field on")]
|
||||
public SharedGameObject targetGameObject;
|
||||
[Tooltip("The component to set the field on")]
|
||||
public SharedString componentName;
|
||||
[Tooltip("The name of the field")]
|
||||
public SharedString fieldName;
|
||||
[Tooltip("The value to set")]
|
||||
public SharedVariable fieldValue;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (fieldValue == null) {
|
||||
Debug.LogWarning("Unable to get field - field value is null");
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var type = TaskUtility.GetTypeWithinAssembly(componentName.Value);
|
||||
if (type == null) {
|
||||
Debug.LogWarning("Unable to set field - type is null");
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type);
|
||||
if (component == null) {
|
||||
Debug.LogWarning("Unable to set the field with component " + componentName.Value);
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
// If you are receiving a compiler error on the Windows Store platform see this topic:
|
||||
// https://www.opsive.com/support/documentation/behavior-designer/installation/
|
||||
var field = component.GetType().GetField(fieldName.Value);
|
||||
field.SetValue(component, fieldValue.GetValue());
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
targetGameObject = null;
|
||||
componentName = null;
|
||||
fieldName = null;
|
||||
fieldValue = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21e389787213ba24ab1a6817def634ae
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/Reflection/SetFieldValue.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Sets the property to the value specified. Returns success if the property was set.")]
|
||||
[TaskCategory("Reflection")]
|
||||
[TaskIcon("{SkinColor}ReflectionIcon.png")]
|
||||
public class SetPropertyValue : Action
|
||||
{
|
||||
[Tooltip("The GameObject to set the property on")]
|
||||
public SharedGameObject targetGameObject;
|
||||
[Tooltip("The component to set the property on")]
|
||||
public SharedString componentName;
|
||||
[Tooltip("The name of the property")]
|
||||
public SharedString propertyName;
|
||||
[Tooltip("The value to set")]
|
||||
public SharedVariable propertyValue;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (propertyValue == null) {
|
||||
Debug.LogWarning("Unable to get field - field value is null");
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var type = TaskUtility.GetTypeWithinAssembly(componentName.Value);
|
||||
if (type == null) {
|
||||
Debug.LogWarning("Unable to set property - type is null");
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
var component = GetDefaultGameObject(targetGameObject.Value).GetComponent(type);
|
||||
if (component == null) {
|
||||
Debug.LogWarning("Unable to set the property with component " + componentName.Value);
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
// If you are receiving a compiler error on the Windows Store platform see this topic:
|
||||
// https://www.opsive.com/support/documentation/behavior-designer/installation/
|
||||
var property = component.GetType().GetProperty(propertyName.Value);
|
||||
property.SetValue(component, propertyValue.GetValue(), null);
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
targetGameObject = null;
|
||||
componentName = null;
|
||||
propertyName = null;
|
||||
propertyValue = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d98b13b7ae4b36b4092b439731466d9b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/Reflection/SetPropertyValue.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Restarts a behavior tree, returns success after it has been restarted.")]
|
||||
[TaskIcon("{SkinColor}RestartBehaviorTreeIcon.png")]
|
||||
public class RestartBehaviorTree : Action
|
||||
{
|
||||
[Tooltip("The GameObject of the behavior tree that should be restarted. If null use the current behavior")]
|
||||
public SharedGameObject behaviorGameObject;
|
||||
[Tooltip("The group of the behavior tree that should be restarted")]
|
||||
public SharedInt group;
|
||||
|
||||
private Behavior behavior;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
var behaviorTrees = GetDefaultGameObject(behaviorGameObject.Value).GetComponents<Behavior>();
|
||||
if (behaviorTrees.Length == 1) {
|
||||
behavior = behaviorTrees[0];
|
||||
} else if (behaviorTrees.Length > 1) {
|
||||
for (int i = 0; i < behaviorTrees.Length; ++i) {
|
||||
if (behaviorTrees[i].Group == group.Value) {
|
||||
behavior = behaviorTrees[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If the group can't be found then use the first behavior tree
|
||||
if (behavior == null) {
|
||||
behavior = behaviorTrees[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (behavior == null) {
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
// Stop the behavior tree
|
||||
behavior.DisableBehavior();
|
||||
// Start the behavior tree back up
|
||||
behavior.EnableBehavior();
|
||||
// Return success
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the properties back to their original values.
|
||||
behavior = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2765e7ece98046542880a1249b87e096
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/RestartBehaviorTree.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,73 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Sends an event to the behavior tree, returns success after sending the event.")]
|
||||
[HelpURL("https://www.opsive.com/support/documentation/behavior-designer/events/")]
|
||||
[TaskIcon("{SkinColor}SendEventIcon.png")]
|
||||
public class SendEvent : Action
|
||||
{
|
||||
[Tooltip("The GameObject of the behavior tree that should have the event sent to it. If null use the current behavior")]
|
||||
public SharedGameObject targetGameObject;
|
||||
[Tooltip("The event to send")]
|
||||
public SharedString eventName;
|
||||
[Tooltip("The group of the behavior tree that the event should be sent to")]
|
||||
public SharedInt group;
|
||||
[Tooltip("Optionally specify a first argument to send")]
|
||||
[SharedRequired]
|
||||
public SharedVariable argument1;
|
||||
[Tooltip("Optionally specify a second argument to send")]
|
||||
[SharedRequired]
|
||||
public SharedVariable argument2;
|
||||
[Tooltip("Optionally specify a third argument to send")]
|
||||
[SharedRequired]
|
||||
public SharedVariable argument3;
|
||||
|
||||
private BehaviorTree behaviorTree;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
var behaviorTrees = GetDefaultGameObject(targetGameObject.Value).GetComponents<BehaviorTree>();
|
||||
if (behaviorTrees.Length == 1) {
|
||||
behaviorTree = behaviorTrees[0];
|
||||
} else if (behaviorTrees.Length > 1) {
|
||||
for (int i = 0; i < behaviorTrees.Length; ++i) {
|
||||
if (behaviorTrees[i].Group == group.Value) {
|
||||
behaviorTree = behaviorTrees[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If the group can't be found then use the first behavior tree
|
||||
if (behaviorTree == null) {
|
||||
behaviorTree = behaviorTrees[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
// Send the event and return success
|
||||
if (argument1 == null || argument1.IsNone) {
|
||||
behaviorTree.SendEvent(eventName.Value);
|
||||
} else {
|
||||
if (argument2 == null || argument2.IsNone) {
|
||||
behaviorTree.SendEvent<object>(eventName.Value, argument1.GetValue());
|
||||
} else {
|
||||
if (argument3 == null || argument3.IsNone) {
|
||||
behaviorTree.SendEvent<object, object>(eventName.Value, argument1.GetValue(), argument2.GetValue());
|
||||
} else {
|
||||
behaviorTree.SendEvent<object, object, object>(eventName.Value, argument1.GetValue(), argument2.GetValue(), argument3.GetValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the properties back to their original values
|
||||
targetGameObject = null;
|
||||
eventName = "";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53b90428a37913c40b6d415ced4e12f9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/SendEvent.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,270 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Allows multiple action tasks to be added to a single node.")]
|
||||
[TaskIcon("{SkinColor}StackedActionIcon.png")]
|
||||
public class StackedAction : Action
|
||||
{
|
||||
[InspectTask]
|
||||
public Action[] actions;
|
||||
public enum ComparisonType
|
||||
{
|
||||
Sequence,
|
||||
Selector
|
||||
}
|
||||
[Tooltip("Specifies if the tasks should be traversed with an AND (Sequence) or an OR (Selector).")]
|
||||
public ComparisonType comparisonType;
|
||||
[Tooltip("Should the tasks be labeled within the graph?")]
|
||||
public bool graphLabel;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
actions[i].GameObject = gameObject;
|
||||
actions[i].Transform = transform;
|
||||
actions[i].Owner = Owner;
|
||||
#if UNITY_EDITOR || DLL_RELEASE || DLL_DEBUG
|
||||
actions[i].NodeData = new NodeData();
|
||||
#endif
|
||||
actions[i].OnAwake();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnStart();
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (actions == null) {
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
var executionStatus = actions[i].OnUpdate();
|
||||
#if UNITY_EDITOR || DLL_RELEASE || DLL_DEBUG
|
||||
actions[i].NodeData.ExecutionStatus = executionStatus;
|
||||
if (actions[i].NodeData.ExecutionStatus == TaskStatus.Running) {
|
||||
Debug.LogWarning("Warning: The action task returned a status of running when action tasks should only return success or failure.");
|
||||
}
|
||||
#endif
|
||||
if (comparisonType == ComparisonType.Sequence && executionStatus == TaskStatus.Failure) {
|
||||
return TaskStatus.Failure;
|
||||
} else if (comparisonType == ComparisonType.Selector && executionStatus == TaskStatus.Success) {
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
return comparisonType == ComparisonType.Sequence ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
|
||||
public override void OnFixedUpdate()
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnFixedUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnLateUpdate()
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnLateUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnTriggerEnter(other);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnTriggerEnter2D(other);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnTriggerExit(other);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnTriggerExit2D(other);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnCollisionEnter(collision);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnCollisionEnter2D(collision);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCollisionExit(Collision collision)
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnCollisionExit(collision);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCollisionExit2D(Collision2D collision)
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnCollisionExit2D(collision);
|
||||
}
|
||||
}
|
||||
|
||||
public override string OnDrawNodeText()
|
||||
{
|
||||
if (actions == null || !graphLabel) {
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var text = string.Empty;
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(text)) {
|
||||
text += "\n";
|
||||
}
|
||||
text += actions[i].GetType().Name;
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
if (actions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actions.Length; ++i) {
|
||||
if (actions[i] == null) {
|
||||
continue;
|
||||
}
|
||||
actions[i].OnReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60f3f340bd02a8a4c84749a903c731da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/StackedAction.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,91 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Start a new behavior tree and return success after it has been started.")]
|
||||
[TaskIcon("{SkinColor}StartBehaviorTreeIcon.png")]
|
||||
public class StartBehaviorTree : Action
|
||||
{
|
||||
[Tooltip("The GameObject of the behavior tree that should be started. If null use the current behavior")]
|
||||
public SharedGameObject behaviorGameObject;
|
||||
[Tooltip("The group of the behavior tree that should be started")]
|
||||
public SharedInt group;
|
||||
[Tooltip("Should this task wait for the behavior tree to complete?")]
|
||||
public SharedBool waitForCompletion = false;
|
||||
[Tooltip("Should the variables be synchronized?")]
|
||||
public SharedBool synchronizeVariables;
|
||||
|
||||
private bool behaviorComplete;
|
||||
private Behavior behavior;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
var behaviorTrees = GetDefaultGameObject(behaviorGameObject.Value).GetComponents<Behavior>();
|
||||
if (behaviorTrees.Length == 1) {
|
||||
behavior = behaviorTrees[0];
|
||||
} else if (behaviorTrees.Length > 1) {
|
||||
for (int i = 0; i < behaviorTrees.Length; ++i) {
|
||||
if (behaviorTrees[i].Group == group.Value) {
|
||||
behavior = behaviorTrees[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If the group can't be found then use the first behavior tree
|
||||
if (behavior == null) {
|
||||
behavior = behaviorTrees[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (behavior != null) {
|
||||
var variables = Owner.GetAllVariables();
|
||||
if (variables != null && synchronizeVariables.Value) {
|
||||
for (int i = 0; i < variables.Count; ++i) {
|
||||
behavior.SetVariableValue(variables[i].Name, variables[i]);
|
||||
}
|
||||
}
|
||||
|
||||
behavior.EnableBehavior();
|
||||
|
||||
if (waitForCompletion.Value) {
|
||||
behaviorComplete = false;
|
||||
behavior.OnBehaviorEnd += BehaviorEnded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (behavior == null) {
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
// Return a status of running if we are waiting for the behavior tree to end and it hasn't ended yet
|
||||
if (waitForCompletion.Value && !behaviorComplete) {
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
private void BehaviorEnded(Behavior behavior)
|
||||
{
|
||||
behaviorComplete = true;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
if (behavior != null && waitForCompletion.Value) {
|
||||
behavior.OnBehaviorEnd -= BehaviorEnded;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the properties back to their original values.
|
||||
behaviorGameObject = null;
|
||||
group = 0;
|
||||
waitForCompletion = false;
|
||||
synchronizeVariables = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc3d67c80371297439385b30f4be506c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/StartBehaviorTree.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Pause or disable a behavior tree and return success after it has been stopped.")]
|
||||
[TaskIcon("{SkinColor}StopBehaviorTreeIcon.png")]
|
||||
public class StopBehaviorTree : Action
|
||||
{
|
||||
[Tooltip("The GameObject of the behavior tree that should be stopped. If null use the current behavior")]
|
||||
public SharedGameObject behaviorGameObject;
|
||||
[Tooltip("The group of the behavior tree that should be stopped")]
|
||||
public SharedInt group;
|
||||
[Tooltip("Should the behavior be paused or completely disabled")]
|
||||
public SharedBool pauseBehavior = false;
|
||||
|
||||
private Behavior behavior;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
var behaviorTrees = GetDefaultGameObject(behaviorGameObject.Value).GetComponents<Behavior>();
|
||||
if (behaviorTrees.Length == 1) {
|
||||
behavior = behaviorTrees[0];
|
||||
} else if (behaviorTrees.Length > 1) {
|
||||
for (int i = 0; i < behaviorTrees.Length; ++i) {
|
||||
if (behaviorTrees[i].Group == group.Value) {
|
||||
behavior = behaviorTrees[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If the group can't be found then use the first behavior tree
|
||||
if (behavior == null) {
|
||||
behavior = behaviorTrees[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (behavior == null) {
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
// Start the behavior and return success.
|
||||
behavior.DisableBehavior(pauseBehavior.Value);
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the properties back to their original values
|
||||
behaviorGameObject = null;
|
||||
group = 0;
|
||||
pauseBehavior = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 130afc7e6aa6e0c4aba29097334aa66b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/StopBehaviorTree.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Wait a specified amount of time. The task will return running until the task is done waiting. It will return success after the wait time has elapsed.")]
|
||||
[TaskIcon("{SkinColor}WaitIcon.png")]
|
||||
public class Wait : Action
|
||||
{
|
||||
[Tooltip("The amount of time to wait")]
|
||||
public SharedFloat waitTime = 1;
|
||||
[Tooltip("Should the wait be randomized?")]
|
||||
public SharedBool randomWait = false;
|
||||
[Tooltip("The minimum wait time if random wait is enabled")]
|
||||
public SharedFloat randomWaitMin = 1;
|
||||
[Tooltip("The maximum wait time if random wait is enabled")]
|
||||
public SharedFloat randomWaitMax = 1;
|
||||
|
||||
// The time to wait
|
||||
private float waitDuration;
|
||||
// The time that the task started to wait.
|
||||
private float startTime;
|
||||
// Remember the time that the task is paused so the time paused doesn't contribute to the wait time.
|
||||
private float pauseTime;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
// Remember the start time.
|
||||
startTime = Time.time;
|
||||
if (randomWait.Value) {
|
||||
waitDuration = Random.Range(randomWaitMin.Value, randomWaitMax.Value);
|
||||
} else {
|
||||
waitDuration = waitTime.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
// The task is done waiting if the time waitDuration has elapsed since the task was started.
|
||||
if (startTime + waitDuration < Time.time) {
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
// Otherwise we are still waiting.
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnPause(bool paused)
|
||||
{
|
||||
if (paused) {
|
||||
// Remember the time that the behavior was paused.
|
||||
pauseTime = Time.time;
|
||||
} else {
|
||||
// Add the difference between Time.time and pauseTime to figure out a new start time.
|
||||
startTime += (Time.time - pauseTime);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the public properties back to their original values
|
||||
waitTime = 1;
|
||||
randomWait = false;
|
||||
randomWaitMin = 1;
|
||||
randomWaitMax = 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67824d2e00531d84db9973773e4426e9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Actions/Wait.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02c91ef526a3f8a41b5df4402d7c783f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,86 @@
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Similar to the sequence task, the parallel task will run each child task until a child task returns failure. " +
|
||||
"The difference is that the parallel task will run all of its children tasks simultaneously versus running each task one at a time. " +
|
||||
"Like the sequence class, the parallel task will return success once all of its children tasks have return success. " +
|
||||
"If one tasks returns failure the parallel task will end all of the child tasks and return failure.")]
|
||||
[TaskIcon("{SkinColor}ParallelIcon.png")]
|
||||
public class Parallel : Composite
|
||||
{
|
||||
// The index of the child that is currently running or is about to run.
|
||||
private int currentChildIndex;
|
||||
// The task status of every child task.
|
||||
private TaskStatus[] executionStatus;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
// Create a new task status array that will hold the execution status of all of the children tasks.
|
||||
executionStatus = new TaskStatus[children.Count];
|
||||
}
|
||||
|
||||
public override void OnChildStarted(int childIndex)
|
||||
{
|
||||
// One of the children has started to run. Increment the child index and set the current task status of that child to running.
|
||||
currentChildIndex++;
|
||||
executionStatus[childIndex] = TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override bool CanRunParallelChildren()
|
||||
{
|
||||
// This task can run parallel children.
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
return currentChildIndex;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// We can continue executing if we have more children that haven't been started yet.
|
||||
return currentChildIndex < children.Count;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(int childIndex, TaskStatus childStatus)
|
||||
{
|
||||
// One of the children has finished running. Set the task status.
|
||||
executionStatus[childIndex] = childStatus;
|
||||
}
|
||||
|
||||
public override TaskStatus OverrideStatus(TaskStatus status)
|
||||
{
|
||||
// Assume all of the children have finished executing. Loop through the execution status of every child and check to see if any tasks are currently running
|
||||
// or failed. If a task is still running then all of the children are not done executing and the parallel task should continue to return a task status of running.
|
||||
// If a task failed then return failure. The Behavior Manager will stop all of the children tasks. If no child task is running or has failed then the parallel
|
||||
// task succeeded and it will return success.
|
||||
bool childrenComplete = true;
|
||||
for (int i = 0; i < executionStatus.Length; ++i) {
|
||||
if (executionStatus[i] == TaskStatus.Running) {
|
||||
childrenComplete = false;
|
||||
} else if (executionStatus[i] == TaskStatus.Failure) {
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
return (childrenComplete ? TaskStatus.Success : TaskStatus.Running);
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Start from the beginning on an abort
|
||||
currentChildIndex = 0;
|
||||
for (int i = 0; i < executionStatus.Length; ++i) {
|
||||
executionStatus[i] = TaskStatus.Inactive;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// Reset the execution status and the child index back to their starting values.
|
||||
for (int i = 0; i < executionStatus.Length; ++i) {
|
||||
executionStatus[i] = TaskStatus.Inactive;
|
||||
}
|
||||
currentChildIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a7063721a0dbc04787bec1b0507f9ae
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/Parallel.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,81 @@
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Similar to the parallel selector task, except the parallel complete task will return the child status as soon as the child returns success or failure." +
|
||||
"The child tasks are executed simultaneously.")]
|
||||
[TaskIcon("{SkinColor}ParallelCompleteIcon.png")]
|
||||
public class ParallelComplete : Composite
|
||||
{
|
||||
// The index of the child that is currently running or is about to run.
|
||||
private int currentChildIndex;
|
||||
// The task status of every child task.
|
||||
private TaskStatus[] executionStatus;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
// Create a new task status array that will hold the execution status of all of the children tasks.
|
||||
executionStatus = new TaskStatus[children.Count];
|
||||
}
|
||||
|
||||
public override void OnChildStarted(int childIndex)
|
||||
{
|
||||
// One of the children has started to run. Increment the child index and set the current task status of that child to running.
|
||||
currentChildIndex++;
|
||||
executionStatus[childIndex] = TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override bool CanRunParallelChildren()
|
||||
{
|
||||
// This task can run parallel children.
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
return currentChildIndex;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// We can continue executing if we have more children that haven't been started yet.
|
||||
return currentChildIndex < children.Count;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(int childIndex, TaskStatus childStatus)
|
||||
{
|
||||
// One of the children has finished running. Set the task status.
|
||||
executionStatus[childIndex] = childStatus;
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Start from the beginning on an abort
|
||||
currentChildIndex = 0;
|
||||
for (int i = 0; i < executionStatus.Length; ++i) {
|
||||
executionStatus[i] = TaskStatus.Inactive;
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OverrideStatus(TaskStatus status)
|
||||
{
|
||||
if (currentChildIndex == 0) {
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
// Return the child task's status as soon as a child task returns success or failure.
|
||||
for (int i = 0; i < currentChildIndex; ++i) {
|
||||
if (executionStatus[i] == TaskStatus.Success || executionStatus[i] == TaskStatus.Failure) {
|
||||
return executionStatus[i];
|
||||
}
|
||||
}
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// Reset the execution status and the child index back to their starting values.
|
||||
for (int i = 0; i < executionStatus.Length; ++i) {
|
||||
executionStatus[i] = TaskStatus.Inactive;
|
||||
}
|
||||
currentChildIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef4b3eb51f6ede04bba3598677fe8531
|
||||
timeCreated: 1487379311
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/ParallelComplete.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,86 @@
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Similar to the selector task, the parallel selector task will return success as soon as a child task returns success. " +
|
||||
"The difference is that the parallel task will run all of its children tasks simultaneously versus running each task one at a time. " +
|
||||
"If one tasks returns success the parallel selector task will end all of the child tasks and return success. " +
|
||||
"If every child task returns failure then the parallel selector task will return failure.")]
|
||||
[TaskIcon("{SkinColor}ParallelSelectorIcon.png")]
|
||||
public class ParallelSelector : Composite
|
||||
{
|
||||
// The index of the child that is currently running or is about to run.
|
||||
private int currentChildIndex;
|
||||
// The task status of every child task.
|
||||
private TaskStatus[] executionStatus;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
// Create a new task status array that will hold the execution status of all of the children tasks.
|
||||
executionStatus = new TaskStatus[children.Count];
|
||||
}
|
||||
|
||||
public override void OnChildStarted(int childIndex)
|
||||
{
|
||||
// One of the children has started to run. Increment the child index and set the current task status of that child to running.
|
||||
currentChildIndex++;
|
||||
executionStatus[childIndex] = TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override bool CanRunParallelChildren()
|
||||
{
|
||||
// This task can run parallel children.
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
return currentChildIndex;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// We can continue executing if we have more children that haven't been started yet.
|
||||
return currentChildIndex < children.Count;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(int childIndex, TaskStatus childStatus)
|
||||
{
|
||||
// One of the children has finished running. Set the task status.
|
||||
executionStatus[childIndex] = childStatus;
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Start from the beginning on an abort
|
||||
currentChildIndex = 0;
|
||||
for (int i = 0; i < executionStatus.Length; ++i) {
|
||||
executionStatus[i] = TaskStatus.Inactive;
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OverrideStatus(TaskStatus status)
|
||||
{
|
||||
// Assume all of the children have finished executing. Loop through the execution status of every child and check to see if any tasks are currently running
|
||||
// or succeeded. If a task is still running then all of the children are not done executing and the parallel selector task should continue to return a task status of running.
|
||||
// If a task succeeded then return success. The Behavior Manager will stop all of the children tasks. If no child task is running or has succeeded then the parallel selector
|
||||
// task failed and it will return failure.
|
||||
bool childrenComplete = true;
|
||||
for (int i = 0; i < executionStatus.Length; ++i) {
|
||||
if (executionStatus[i] == TaskStatus.Running) {
|
||||
childrenComplete = false;
|
||||
} else if (executionStatus[i] == TaskStatus.Success) {
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
return (childrenComplete ? TaskStatus.Failure : TaskStatus.Running);
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// Reset the execution status and the child index back to their starting values.
|
||||
for (int i = 0; i < executionStatus.Length; ++i) {
|
||||
executionStatus[i] = TaskStatus.Inactive;
|
||||
}
|
||||
currentChildIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52e4e27ad95cedb41a3bc2c5f5ed0b54
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/ParallelSelector.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,71 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Similar to the selector task, the priority selector task will return success as soon as a child task returns success. " +
|
||||
"Instead of running the tasks sequentially from left to right within the tree, the priority selector will ask the task what its priority is to determine the order. " +
|
||||
"The higher priority tasks have a higher chance at being run first.")]
|
||||
[TaskIcon("{SkinColor}PrioritySelectorIcon.png")]
|
||||
public class PrioritySelector : Composite
|
||||
{
|
||||
// The index of the child that is currently running or is about to run.
|
||||
private int currentChildIndex = 0;
|
||||
// The task status of every child task.
|
||||
private TaskStatus executionStatus = TaskStatus.Inactive;
|
||||
// The order to run its children in.
|
||||
private List<int> childrenExecutionOrder = new List<int>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
// Make sure the list is empty before we add child indexes to it.
|
||||
childrenExecutionOrder.Clear();
|
||||
|
||||
// Loop through each child task and determine its priority. The higher the priority the lower it goes within the list. The task with the highest
|
||||
// priority will be first in the list and will be executed first.
|
||||
for (int i = 0; i < children.Count; ++i) {
|
||||
float priority = children[i].GetPriority();
|
||||
int insertIndex = childrenExecutionOrder.Count;
|
||||
for (int j = 0; j < childrenExecutionOrder.Count; ++j) {
|
||||
if (children[childrenExecutionOrder[j]].GetPriority() < priority) {
|
||||
insertIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
childrenExecutionOrder.Insert(insertIndex, i);
|
||||
}
|
||||
}
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
// Use the execution order list in order to determine the current child index.
|
||||
return childrenExecutionOrder[currentChildIndex];
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// We can continue to execuate as long as we have children that haven't been executed and no child has returned success.
|
||||
return currentChildIndex < children.Count && executionStatus != TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(TaskStatus childStatus)
|
||||
{
|
||||
// Increase the child index and update the execution status after a child has finished running.
|
||||
currentChildIndex++;
|
||||
executionStatus = childStatus;
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Set the current child index to the index that caused the abort
|
||||
currentChildIndex = childIndex;
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// All of the children have run. Reset the variables back to their starting values.
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
currentChildIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b5aa86ad86e94f41841abd04bd96f2a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/PrioritySelector.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,101 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Similar to the selector task, the random selector task will return success as soon as a child task returns success. " +
|
||||
"The difference is that the random selector class will run its children in a random order. The selector task is deterministic " +
|
||||
"in that it will always run the tasks from left to right within the tree. The random selector task shuffles the child tasks up and then begins " +
|
||||
"execution in a random order. Other than that the random selector class is the same as the selector class. It will continue running tasks " +
|
||||
"until a task completes successfully. If no child tasks return success then it will return failure.")]
|
||||
[TaskIcon("{SkinColor}RandomSelectorIcon.png")]
|
||||
public class RandomSelector : Composite
|
||||
{
|
||||
[Tooltip("Seed the random number generator to make things easier to debug")]
|
||||
public int seed = 0;
|
||||
[Tooltip("Do we want to use the seed?")]
|
||||
public bool useSeed = false;
|
||||
|
||||
// A list of indexes of every child task. This list is used by the Fischer-Yates shuffle algorithm.
|
||||
private List<int> childIndexList = new List<int>();
|
||||
// The random child index execution order.
|
||||
private Stack<int> childrenExecutionOrder = new Stack<int>();
|
||||
// The task status of the last child ran.
|
||||
private TaskStatus executionStatus = TaskStatus.Inactive;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
// If specified, use the seed provided.
|
||||
if (useSeed) {
|
||||
Random.InitState(seed);
|
||||
}
|
||||
|
||||
// Add the index of each child to a list to make the Fischer-Yates shuffle possible.
|
||||
childIndexList.Clear();
|
||||
for (int i = 0; i < children.Count; ++i) {
|
||||
childIndexList.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
// Randomize the indecies
|
||||
ShuffleChilden();
|
||||
}
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
// Peek will return the index at the top of the stack.
|
||||
return childrenExecutionOrder.Peek();
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// Continue exectuion if no task has return success and indexes still exist on the stack.
|
||||
return childrenExecutionOrder.Count > 0 && executionStatus != TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(TaskStatus childStatus)
|
||||
{
|
||||
// Pop the top index from the stack and set the execution status.
|
||||
if (childrenExecutionOrder.Count > 0) {
|
||||
childrenExecutionOrder.Pop();
|
||||
}
|
||||
executionStatus = childStatus;
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Start from the beginning on an abort
|
||||
childrenExecutionOrder.Clear();
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
ShuffleChilden();
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// All of the children have run. Reset the variables back to their starting values.
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
childrenExecutionOrder.Clear();
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the public properties back to their original values
|
||||
seed = 0;
|
||||
useSeed = false;
|
||||
}
|
||||
|
||||
private void ShuffleChilden()
|
||||
{
|
||||
// Use Fischer-Yates shuffle to randomize the child index order.
|
||||
for (int i = childIndexList.Count; i > 0; --i) {
|
||||
int j = Random.Range(0, i);
|
||||
int index = childIndexList[j];
|
||||
childrenExecutionOrder.Push(index);
|
||||
childIndexList[j] = childIndexList[i - 1];
|
||||
childIndexList[i - 1] = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4952cbfc1e77be24b99e34c9acffc2a0
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/RandomSelector.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,102 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Similar to the sequence task, the random sequence task will return success as soon as every child task returns success. " +
|
||||
"The difference is that the random sequence class will run its children in a random order. The sequence task is deterministic " +
|
||||
"in that it will always run the tasks from left to right within the tree. The random sequence task shuffles the child tasks up and then begins " +
|
||||
"execution in a random order. Other than that the random sequence class is the same as the sequence class. It will stop running tasks " +
|
||||
"as soon as a single task ends in failure. On a task failure it will stop executing all of the child tasks and return failure. " +
|
||||
"If no child returns failure then it will return success.")]
|
||||
[TaskIcon("{SkinColor}RandomSequenceIcon.png")]
|
||||
public class RandomSequence : Composite
|
||||
{
|
||||
[Tooltip("Seed the random number generator to make things easier to debug")]
|
||||
public int seed = 0;
|
||||
[Tooltip("Do we want to use the seed?")]
|
||||
public bool useSeed = false;
|
||||
|
||||
// A list of indexes of every child task. This list is used by the Fischer-Yates shuffle algorithm.
|
||||
private List<int> childIndexList = new List<int>();
|
||||
// The random child index execution order.
|
||||
private Stack<int> childrenExecutionOrder = new Stack<int>();
|
||||
// The task status of the last child ran.
|
||||
private TaskStatus executionStatus = TaskStatus.Inactive;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
// If specified, use the seed provided.
|
||||
if (useSeed) {
|
||||
Random.InitState(seed);
|
||||
}
|
||||
|
||||
// Add the index of each child to a list to make the Fischer-Yates shuffle possible.
|
||||
childIndexList.Clear();
|
||||
for (int i = 0; i < children.Count; ++i) {
|
||||
childIndexList.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
// Randomize the indecies
|
||||
ShuffleChilden();
|
||||
}
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
// Peek will return the index at the top of the stack.
|
||||
return childrenExecutionOrder.Peek();
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// Continue exectuion if no task has return failure and indexes still exist on the stack.
|
||||
return childrenExecutionOrder.Count > 0 && executionStatus != TaskStatus.Failure;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(TaskStatus childStatus)
|
||||
{
|
||||
// Pop the top index from the stack and set the execution status.
|
||||
if (childrenExecutionOrder.Count > 0) {
|
||||
childrenExecutionOrder.Pop();
|
||||
}
|
||||
executionStatus = childStatus;
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Start from the beginning on an abort
|
||||
childrenExecutionOrder.Clear();
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
ShuffleChilden();
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// All of the children have run. Reset the variables back to their starting values.
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
childrenExecutionOrder.Clear();
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the public properties back to their original values
|
||||
seed = 0;
|
||||
useSeed = false;
|
||||
}
|
||||
|
||||
private void ShuffleChilden()
|
||||
{
|
||||
// Use Fischer-Yates shuffle to randomize the child index order.
|
||||
for (int i = childIndexList.Count; i > 0; --i) {
|
||||
int j = Random.Range(0, i);
|
||||
int index = childIndexList[j];
|
||||
childrenExecutionOrder.Push(index);
|
||||
childIndexList[j] = childIndexList[i - 1];
|
||||
childIndexList[i - 1] = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11b102c97eb687b4a9ce1473a334c3dd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/RandomSequence.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,45 @@
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("The selector task is similar to an \"or\" operation. It will return success as soon as one of its child tasks return success. " +
|
||||
"If a child task returns failure then it will sequentially run the next task. If no child task returns success then it will return failure.")]
|
||||
[TaskIcon("{SkinColor}SelectorIcon.png")]
|
||||
public class Selector : Composite
|
||||
{
|
||||
// The index of the child that is currently running or is about to run.
|
||||
private int currentChildIndex = 0;
|
||||
// The task status of the last child ran.
|
||||
private TaskStatus executionStatus = TaskStatus.Inactive;
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
return currentChildIndex;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// We can continue to execuate as long as we have children that haven't been executed and no child has returned success.
|
||||
return currentChildIndex < children.Count && executionStatus != TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(TaskStatus childStatus)
|
||||
{
|
||||
// Increase the child index and update the execution status after a child has finished running.
|
||||
currentChildIndex++;
|
||||
executionStatus = childStatus;
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Set the current child index to the index that caused the abort
|
||||
currentChildIndex = childIndex;
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// All of the children have run. Reset the variables back to their starting values.
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
currentChildIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cb8dcec14880a443841212e6b595d4f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/Selector.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,121 @@
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("The selector evaluator is a selector task which reevaluates its children every tick. It will run the lowest priority child which returns a task status of running. " +
|
||||
"This is done each tick. If a higher priority child is running and the next frame a lower priority child wants to run it will interrupt the higher priority child. " +
|
||||
"The selector evaluator will return success as soon as the first child returns success otherwise it will keep trying higher priority children. This task mimics " +
|
||||
"the conditional abort functionality except the child tasks don't always have to be conditional tasks.")]
|
||||
[TaskIcon("{SkinColor}SelectorEvaluatorIcon.png")]
|
||||
public class SelectorEvaluator : Composite
|
||||
{
|
||||
// The index of the child that is currently running or is about to run.
|
||||
private int currentChildIndex = 0;
|
||||
// The task status of the last child ran.
|
||||
private TaskStatus executionStatus = TaskStatus.Inactive;
|
||||
// The index of the child that was running before the tree started to be reevaluated.
|
||||
private int storedCurrentChildIndex = -1;
|
||||
// The task status of the last child ran before the tree started to be reevaluated.
|
||||
private TaskStatus storedExecutionStatus = TaskStatus.Inactive;
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
return currentChildIndex;
|
||||
}
|
||||
|
||||
public override void OnChildStarted(int childIndex)
|
||||
{
|
||||
// The children run sequentially so increment the index and set the status to running.
|
||||
currentChildIndex++;
|
||||
executionStatus = TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// We can continue to execuate as long as we have children that haven't been executed and no child has returned success.
|
||||
if (executionStatus == TaskStatus.Success || executionStatus == TaskStatus.Running) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Used the storedCurrentChildIndex if reevaluating, otherwise the currentChildIndex
|
||||
if (storedCurrentChildIndex != -1) {
|
||||
return currentChildIndex < storedCurrentChildIndex - 1;
|
||||
}
|
||||
return currentChildIndex < children.Count;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(int childIndex, TaskStatus childStatus)
|
||||
{
|
||||
// A disabled task is the equivalent of the task failing for a selector evaluator.
|
||||
if (childStatus == TaskStatus.Inactive && children[childIndex].Disabled) {
|
||||
executionStatus = TaskStatus.Failure;
|
||||
}
|
||||
// The child status will be inactive immediately following an abort from OnReevaluationEnded. The status will be running if the
|
||||
// child task is interrupted. Ignore the status for both of these.
|
||||
if (childStatus != TaskStatus.Inactive && childStatus != TaskStatus.Running) {
|
||||
executionStatus = childStatus;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Set the current child index to the index that caused the abort
|
||||
currentChildIndex = childIndex;
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// All of the children have run. Reset the variables back to their starting values.
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
currentChildIndex = 0;
|
||||
}
|
||||
|
||||
public override TaskStatus OverrideStatus(TaskStatus status)
|
||||
{
|
||||
return executionStatus;
|
||||
}
|
||||
|
||||
// The selector evaluator task is a parallel task to allow the previous child to continue to run while the higher priority task is active. If the
|
||||
// lower priority child can run then OnReevaluationEnded will interrupt the higher priority task.
|
||||
public override bool CanRunParallelChildren()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Can reevaluate to allow the lower priority children the chance to rerun.
|
||||
public override bool CanReevaluate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// The behavior tree wants to start reevaluating the tree.
|
||||
public override bool OnReevaluationStarted()
|
||||
{
|
||||
// Cannot reevaluate if the task hasn't even started yet
|
||||
if (executionStatus == TaskStatus.Inactive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the current index and execution status because it may need to be resumed.
|
||||
storedCurrentChildIndex = currentChildIndex;
|
||||
storedExecutionStatus = executionStatus;
|
||||
currentChildIndex = 0;
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reevaluation has ended. Determine if a task should be interrupted or resumed from the last index.
|
||||
public override void OnReevaluationEnded(TaskStatus status)
|
||||
{
|
||||
// Interrupt the currently running index if a lower priority child returns a status of running or success.
|
||||
if (executionStatus != TaskStatus.Failure && executionStatus != TaskStatus.Inactive) {
|
||||
BehaviorManager.instance.Interrupt(Owner, children[storedCurrentChildIndex - 1], this, TaskStatus.Inactive);
|
||||
} else {
|
||||
// The lower priority children returned the same status so resume with the current child
|
||||
currentChildIndex = storedCurrentChildIndex;
|
||||
executionStatus = storedExecutionStatus;
|
||||
}
|
||||
storedCurrentChildIndex = -1;
|
||||
storedExecutionStatus = TaskStatus.Inactive;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15b5d0aafd7d4f04f8332d33705ebd63
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/SelectorEvaluator.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,45 @@
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("The sequence task is similar to an \"and\" operation. It will return failure as soon as one of its child tasks return failure. " +
|
||||
"If a child task returns success then it will sequentially run the next task. If all child tasks return success then it will return success.")]
|
||||
[TaskIcon("{SkinColor}SequenceIcon.png")]
|
||||
public class Sequence : Composite
|
||||
{
|
||||
// The index of the child that is currently running or is about to run.
|
||||
private int currentChildIndex = 0;
|
||||
// The task status of the last child ran.
|
||||
private TaskStatus executionStatus = TaskStatus.Inactive;
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
return currentChildIndex;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// We can continue to execuate as long as we have children that haven't been executed and no child has returned failure.
|
||||
return currentChildIndex < children.Count && executionStatus != TaskStatus.Failure;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(TaskStatus childStatus)
|
||||
{
|
||||
// Increase the child index and update the execution status after a child has finished running.
|
||||
currentChildIndex++;
|
||||
executionStatus = childStatus;
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Set the current child index to the index that caused the abort
|
||||
currentChildIndex = childIndex;
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// All of the children have run. Reset the variables back to their starting values.
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
currentChildIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7226608b64066c40a656d7260249fce
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/Sequence.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,149 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("The utility selector task evaluates the child tasks using Utility Theory AI. The child task can override the GetUtility method and return the utility value " +
|
||||
"at that particular time. The task with the highest utility value will be selected and the existing running task will be aborted. The utility selector " +
|
||||
"task reevaluates its children every tick.")]
|
||||
[TaskIcon("{SkinColor}UtilitySelectorIcon.png")]
|
||||
public class UtilitySelector : Composite
|
||||
{
|
||||
// The index of the child that is currently running or is about to run.
|
||||
private int currentChildIndex = 0;
|
||||
// The highest utility value
|
||||
private float highestUtility;
|
||||
// The task status of the last child ran.
|
||||
private TaskStatus executionStatus = TaskStatus.Inactive;
|
||||
// Is the task being reevaluated?
|
||||
private bool reevaluating;
|
||||
// A list of children that can execute.
|
||||
private List<int> availableChildren = new List<int>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
highestUtility = float.MinValue;
|
||||
|
||||
// Loop through each child task and determine its utility. The task with the highest utility will run first.
|
||||
availableChildren.Clear();
|
||||
for (int i = 0; i < children.Count; ++i) {
|
||||
float utility = children[i].GetUtility();
|
||||
if (utility > highestUtility) {
|
||||
highestUtility = utility;
|
||||
currentChildIndex = i;
|
||||
}
|
||||
availableChildren.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
public override int CurrentChildIndex()
|
||||
{
|
||||
// The currentChildIndex is the task with the highest utility.
|
||||
return currentChildIndex;
|
||||
}
|
||||
|
||||
public override void OnChildStarted(int childIndex)
|
||||
{
|
||||
// The child has started - set the execution status.
|
||||
executionStatus = TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
// Continue to execute new tasks until a task returns success or there are no more children left. If reevaluating then return false
|
||||
// immediately because each task doesn't need to be reevaluted.
|
||||
if (executionStatus == TaskStatus.Success || executionStatus == TaskStatus.Running || reevaluating) {
|
||||
return false;
|
||||
}
|
||||
return availableChildren.Count > 0;
|
||||
}
|
||||
|
||||
public override void OnChildExecuted(int childIndex, TaskStatus childStatus)
|
||||
{
|
||||
// The child status will be inactive immediately following an abort from OnReevaluationEnded. The status will be running if the
|
||||
// child task is interrupted. Ignore the status for both of these.
|
||||
if (childStatus != TaskStatus.Inactive && childStatus != TaskStatus.Running) {
|
||||
executionStatus = childStatus;
|
||||
// If the execution status is failure then a new task needs to be selected. Remove the current task from the available children
|
||||
// and select the next highest utility child.
|
||||
if (executionStatus == TaskStatus.Failure) {
|
||||
availableChildren.Remove(childIndex);
|
||||
|
||||
highestUtility = float.MinValue;
|
||||
for (int i = 0; i < availableChildren.Count; ++i) {
|
||||
float utility = children[availableChildren[i]].GetUtility();
|
||||
if (utility > highestUtility) {
|
||||
highestUtility = utility;
|
||||
currentChildIndex = availableChildren[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnConditionalAbort(int childIndex)
|
||||
{
|
||||
// Set the current child index to the index that caused the abort
|
||||
currentChildIndex = childIndex;
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// All of the children have run. Reset the variables back to their starting values.
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
currentChildIndex = 0;
|
||||
}
|
||||
|
||||
public override TaskStatus OverrideStatus(TaskStatus status)
|
||||
{
|
||||
return executionStatus;
|
||||
}
|
||||
|
||||
// The utility selector task is a parallel task to allow the task utility to be reevaluated. The higest utility task will always run.
|
||||
public override bool CanRunParallelChildren()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Can reevaluate to allow the task utilities to be rerun.
|
||||
public override bool CanReevaluate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// The behavior tree wants to start reevaluating the tree.
|
||||
public override bool OnReevaluationStarted()
|
||||
{
|
||||
// Cannot reevaluate if the task hasn't even started yet
|
||||
if (executionStatus == TaskStatus.Inactive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
reevaluating = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Determine if a task with a higher utility exists.
|
||||
public override void OnReevaluationEnded(TaskStatus status)
|
||||
{
|
||||
reevaluating = false;
|
||||
|
||||
// Loop through all of the available children and pick the task with the highest utility.
|
||||
int prevChildIndex = currentChildIndex;
|
||||
highestUtility = float.MinValue;
|
||||
for (int i = 0; i < availableChildren.Count; ++i) {
|
||||
float utility = children[availableChildren[i]].GetUtility();
|
||||
if (utility > highestUtility) {
|
||||
highestUtility = utility;
|
||||
currentChildIndex = availableChildren[i];
|
||||
}
|
||||
}
|
||||
|
||||
// If the index is different then the current child task should be aborted and the higher utility task should be run.
|
||||
if (prevChildIndex != currentChildIndex) {
|
||||
BehaviorManager.instance.Interrupt(Owner, children[prevChildIndex], this, TaskStatus.Failure);
|
||||
executionStatus = TaskStatus.Inactive;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c21b01ca0aa9004fa3a76c9d596eeb1
|
||||
timeCreated: 1465679373
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Composites/UtilitySelector.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd959be462adfbc4a8878260547827cb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,113 @@
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Returns success as soon as the event specified by eventName has been received.")]
|
||||
[TaskIcon("{SkinColor}HasReceivedEventIcon.png")]
|
||||
public class HasReceivedEvent : Conditional
|
||||
{
|
||||
[Tooltip("The name of the event to receive")]
|
||||
public SharedString eventName = "";
|
||||
[Tooltip("Optionally store the first sent argument")]
|
||||
[SharedRequired]
|
||||
public SharedVariable storedValue1;
|
||||
[Tooltip("Optionally store the second sent argument")]
|
||||
[SharedRequired]
|
||||
public SharedVariable storedValue2;
|
||||
[Tooltip("Optionally store the third sent argument")]
|
||||
[SharedRequired]
|
||||
public SharedVariable storedValue3;
|
||||
|
||||
private bool eventReceived = false;
|
||||
private bool registered = false;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
// Let the behavior tree know that we are interested in receiving the event specified
|
||||
if (!registered) {
|
||||
Owner.RegisterEvent(eventName.Value, ReceivedEvent);
|
||||
Owner.RegisterEvent<object>(eventName.Value, ReceivedEvent);
|
||||
Owner.RegisterEvent<object, object>(eventName.Value, ReceivedEvent);
|
||||
Owner.RegisterEvent<object, object, object>(eventName.Value, ReceivedEvent);
|
||||
registered = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
return eventReceived ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
if (eventReceived) {
|
||||
Owner.UnregisterEvent(eventName.Value, ReceivedEvent);
|
||||
Owner.UnregisterEvent<object>(eventName.Value, ReceivedEvent);
|
||||
Owner.UnregisterEvent<object, object>(eventName.Value, ReceivedEvent);
|
||||
Owner.UnregisterEvent<object, object, object>(eventName.Value, ReceivedEvent);
|
||||
registered = false;
|
||||
}
|
||||
eventReceived = false;
|
||||
}
|
||||
|
||||
private void ReceivedEvent()
|
||||
{
|
||||
eventReceived = true;
|
||||
}
|
||||
|
||||
private void ReceivedEvent(object arg1)
|
||||
{
|
||||
ReceivedEvent();
|
||||
|
||||
if (storedValue1 != null && !storedValue1.IsNone) {
|
||||
storedValue1.SetValue(arg1);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReceivedEvent(object arg1, object arg2)
|
||||
{
|
||||
ReceivedEvent();
|
||||
|
||||
if (storedValue1 != null && !storedValue1.IsNone) {
|
||||
storedValue1.SetValue(arg1);
|
||||
}
|
||||
|
||||
if (storedValue2 != null && !storedValue2.IsNone) {
|
||||
storedValue2.SetValue(arg2);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReceivedEvent(object arg1, object arg2, object arg3)
|
||||
{
|
||||
ReceivedEvent();
|
||||
|
||||
if (storedValue1 != null && !storedValue1.IsNone) {
|
||||
storedValue1.SetValue(arg1);
|
||||
}
|
||||
|
||||
if (storedValue2 != null && !storedValue2.IsNone) {
|
||||
storedValue2.SetValue(arg2);
|
||||
}
|
||||
|
||||
if (storedValue3 != null && !storedValue3.IsNone) {
|
||||
storedValue3.SetValue(arg3);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnBehaviorComplete()
|
||||
{
|
||||
// Stop receiving the event when the behavior tree is complete
|
||||
Owner.UnregisterEvent(eventName.Value, ReceivedEvent);
|
||||
Owner.UnregisterEvent<object>(eventName.Value, ReceivedEvent);
|
||||
Owner.UnregisterEvent<object, object>(eventName.Value, ReceivedEvent);
|
||||
Owner.UnregisterEvent<object, object, object>(eventName.Value, ReceivedEvent);
|
||||
|
||||
eventReceived = false;
|
||||
registered = false;
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
// Reset the properties back to their original values
|
||||
eventName = "";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c0c7f545b074cb48bd552b038ede7af
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Conditionals/HasReceivedEvent.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5b2388776cf10a438e7a4357267c555
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Returns success when a collision starts. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
|
||||
[TaskCategory("Physics")]
|
||||
public class HasEnteredCollision : Conditional
|
||||
{
|
||||
[Tooltip("The tag of the GameObject to check for a collision against")]
|
||||
public SharedString tag = "";
|
||||
[Tooltip("The object that started the collision")]
|
||||
public SharedGameObject collidedGameObject;
|
||||
|
||||
private bool enteredCollision = false;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
return enteredCollision ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
enteredCollision = false;
|
||||
}
|
||||
|
||||
public override void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tag.Value) || collision.gameObject.CompareTag(tag.Value)) {
|
||||
collidedGameObject.Value = collision.gameObject;
|
||||
enteredCollision = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
tag = "";
|
||||
collidedGameObject = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1841a802d7ceda449423f001897ecae
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Conditionals/Physics/HasEnteredCollision.cs
|
||||
uploadId: 598781
|
@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BehaviorDesigner.Runtime.Tasks
|
||||
{
|
||||
[TaskDescription("Returns success when a 2D collision starts. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
|
||||
[TaskCategory("Physics")]
|
||||
public class HasEnteredCollision2D : Conditional
|
||||
{
|
||||
[Tooltip("The tag of the GameObject to check for a collision against")]
|
||||
public SharedString tag = "";
|
||||
[Tooltip("The object that started the collision")]
|
||||
public SharedGameObject collidedGameObject;
|
||||
|
||||
private bool enteredCollision = false;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
return enteredCollision ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
enteredCollision = false;
|
||||
}
|
||||
|
||||
public override void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tag.Value) || collision.gameObject.CompareTag(tag.Value)) {
|
||||
collidedGameObject.Value = collision.gameObject;
|
||||
enteredCollision = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnReset()
|
||||
{
|
||||
tag = "";
|
||||
collidedGameObject = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ac128198630a2d4b9fee93cc9a1f8fd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 15277
|
||||
packageName: Behavior Designer - Behavior Trees for Everyone
|
||||
packageVersion: 1.7.7p1
|
||||
assetPath: Assets/Behavior Designer/Runtime/Tasks/Conditionals/Physics/HasEnteredCollision2D.cs
|
||||
uploadId: 598781
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user