-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.BTs.Trees.Editors { | ||
[CustomPropertyDrawer(typeof(BehaviorTree))] | ||
public class BehaviorTreeDrawer : PropertyDrawer { | ||
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) { | ||
EditorGUI.BeginProperty(position, label, property); | ||
|
||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); | ||
GUI.enabled = Application.isPlaying; | ||
if (GUI.Button(position, "View Tree")) { | ||
var tree = fieldInfo.GetValue(property.serializedObject.targetObject) as IBehaviorTree; | ||
BehaviorTreeWindow.ShowTree(tree, property.displayName); | ||
} | ||
GUI.enabled = true; | ||
|
||
EditorGUI.EndProperty(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.BTs.Trees.Editors { | ||
public class BehaviorTreeWindow : EditorWindow { | ||
private BehaviorTreePrinter _printer; | ||
private string _name; | ||
|
||
public static void ShowTree (IBehaviorTree tree, string name) { | ||
var window = GetWindow(typeof(BehaviorTreeWindow)) as BehaviorTreeWindow; | ||
window.SetTree(tree, name); | ||
} | ||
|
||
private void SetTree (IBehaviorTree tree, string name) { | ||
_printer = new BehaviorTreePrinter(tree); | ||
_name = name; | ||
} | ||
|
||
private void OnGUI () { | ||
GUILayout.Label($"Behavior Tree: {_name}", EditorStyles.boldLabel); | ||
_printer?.Print(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace CleverCrow.Fluid.BTs.Trees.Editors { | ||
public class BehaviorTreePrinter { | ||
private readonly PrintNode _root; | ||
|
||
public BehaviorTreePrinter (IBehaviorTree tree) { | ||
_root = new PrintNode(tree.Root); | ||
} | ||
|
||
public void Print () { | ||
_root.Print(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections.Generic; | ||
using CleverCrow.Fluid.BTs.TaskParents; | ||
using CleverCrow.Fluid.BTs.Tasks; | ||
using UnityEngine; | ||
using EditorGUILayout = UnityEditor.EditorGUILayout; | ||
|
||
namespace CleverCrow.Fluid.BTs.Trees.Editors { | ||
public class PrintNode { | ||
private readonly ITask _task; | ||
private readonly List<PrintNode> _children = new List<PrintNode>(); | ||
|
||
public PrintNode (ITask task) { | ||
_task = task; | ||
|
||
var parent = task as ITaskParent; | ||
if (parent == null) return; | ||
foreach (var child in parent.Children) { | ||
_children.Add(new PrintNode(child)); | ||
} | ||
} | ||
|
||
public void Print () { | ||
EditorGUILayout.BeginVertical(); | ||
|
||
var centeredStyle = GUI.skin.GetStyle("Label"); | ||
centeredStyle.alignment = TextAnchor.MiddleCenter; | ||
EditorGUILayout.LabelField(_task.Name, centeredStyle); | ||
|
||
EditorGUILayout.BeginHorizontal(); | ||
foreach (var child in _children) { | ||
child.Print(); | ||
} | ||
EditorGUILayout.EndHorizontal(); | ||
|
||
EditorGUILayout.EndVertical(); | ||
|
||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "Fluid.BehaviorTree.Editor", | ||
"references": [ | ||
"Fluid.BehaviorTree" | ||
], | ||
"optionalUnityReferences": [], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using CleverCrow.Fluid.BTs.Tasks; | ||
using CleverCrow.Fluid.BTs.Trees; | ||
using UnityEngine; | ||
|
||
namespace FluidBehaviorTree.Runtime { | ||
public class BehaviorTreeSerializationTestDeleteMe : MonoBehaviour { | ||
[SerializeField] | ||
private BehaviorTree _tree; | ||
|
||
private void Awake () { | ||
_tree = new BehaviorTreeBuilder(gameObject) | ||
.Sequence() | ||
.Condition("Custom Condition", () => true) | ||
.Do("Custom Action", () => TaskStatus.Success) | ||
.Sequence("Nested Sequence") | ||
.Condition("Custom Condition", () => true) | ||
.Do("Custom Action", () => TaskStatus.Success) | ||
.End() | ||
.End() | ||
.Build(); | ||
} | ||
|
||
private void Update () { | ||
// Update our tree every frame | ||
_tree.Tick(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.