Skip to content

Commit c5d41cc

Browse files
authored
Merge pull request #102 from ashblue/all-contributors/add-darkgnostic
docs: add darkgnostic as a contributor for bug
0 parents  commit c5d41cc

File tree

247 files changed

+7197
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+7197
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Placeholder for meta files

CHANGELOG.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/BehaviorTree.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace CleverCrow.Fluid.BTs.Trees.Editors {
5+
[CustomPropertyDrawer(typeof(BehaviorTree))]
6+
public class BehaviorTreeDrawer : PropertyDrawer {
7+
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
8+
EditorGUI.BeginProperty(position, label, property);
9+
10+
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
11+
GUI.enabled = Application.isPlaying;
12+
if (GUI.Button(position, "View Tree")) {
13+
var tree = fieldInfo.GetValue(property.serializedObject.targetObject) as IBehaviorTree;
14+
BehaviorTreeWindow.ShowTree(tree, tree.Name ?? property.displayName);
15+
}
16+
GUI.enabled = true;
17+
18+
EditorGUI.EndProperty();
19+
}
20+
}
21+
}

Editor/BehaviorTree/BehaviorTreeDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace CleverCrow.Fluid.BTs.Trees.Editors {
5+
public class BehaviorTreeWindow : EditorWindow {
6+
private BehaviorTreePrinter _printer;
7+
private string _name;
8+
9+
public static void ShowTree (IBehaviorTree tree, string name) {
10+
var window = GetWindow<BehaviorTreeWindow>(false);
11+
window.titleContent = new GUIContent($"Behavior Tree: {name}");
12+
window.SetTree(tree, name);
13+
}
14+
15+
private void SetTree (IBehaviorTree tree, string name) {
16+
_printer?.Unbind();
17+
_printer = new BehaviorTreePrinter(tree, position.size);
18+
_name = name;
19+
}
20+
21+
private void OnGUI () {
22+
if (!Application.isPlaying) {
23+
ClearView();
24+
}
25+
26+
GUILayout.Label($"Behavior Tree: {_name}", EditorStyles.boldLabel);
27+
_printer?.Print(position.size);
28+
}
29+
30+
private void ClearView () {
31+
_name = null;
32+
_printer = null;
33+
}
34+
35+
private void Update () {
36+
if (Application.isPlaying) {
37+
Repaint();
38+
}
39+
}
40+
}
41+
}

Editor/BehaviorTree/BehaviorTreeWindow.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/BehaviorTree/Printer.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using UnityEngine;
2+
3+
namespace CleverCrow.Fluid.BTs.Trees.Editors {
4+
public class BehaviorTreePrinter {
5+
private const float SCROLL_PADDING = 40;
6+
7+
private readonly VisualTask _root;
8+
private readonly Rect _containerSize;
9+
10+
private Vector2 _scrollPosition;
11+
12+
public static StatusIcons StatusIcons { get; private set; }
13+
public static GuiStyleCollection SharedStyles { get; private set; }
14+
15+
16+
public BehaviorTreePrinter (IBehaviorTree tree, Vector2 windowSize) {
17+
StatusIcons = new StatusIcons();
18+
SharedStyles = new GuiStyleCollection();
19+
20+
var container = new GraphContainerVertical();
21+
container.SetGlobalPosition(SCROLL_PADDING, SCROLL_PADDING);
22+
_root = new VisualTask(tree.Root, container);
23+
container.CenterAlignChildren();
24+
25+
_containerSize = new Rect(0, 0,
26+
container.Width + SCROLL_PADDING * 2,
27+
container.Height + SCROLL_PADDING * 2);
28+
29+
CenterScrollView(windowSize, container);
30+
}
31+
32+
private void CenterScrollView (Vector2 windowSize, GraphContainerVertical container) {
33+
var scrollOverflow = container.Width + SCROLL_PADDING * 2 - windowSize.x;
34+
var centerViewPosition = scrollOverflow / 2;
35+
_scrollPosition.x = centerViewPosition;
36+
}
37+
38+
public void Print (Vector2 windowSize) {
39+
_scrollPosition = GUI.BeginScrollView(
40+
new Rect(0, 0, windowSize.x, windowSize.y),
41+
_scrollPosition,
42+
_containerSize);
43+
_root.Print();
44+
GUI.EndScrollView();
45+
}
46+
47+
public void Unbind () {
48+
_root.RecursiveTaskUnbind();
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)