Skip to content

Commit cf296af

Browse files
authored
Merge pull request #104 from ashblue/all-contributors/add-JeremyVansnick
docs: add JeremyVansnick as a contributor for code
0 parents  commit cf296af

File tree

247 files changed

+7226
-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

+7226
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Placeholder for meta files

CHANGELOG.md.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/BehaviorTree.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+21
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

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
void OnEnable() {
42+
EditorApplication.update += OnEditorUpdate;
43+
}
44+
45+
void OnDisable() {
46+
EditorApplication.update -= OnEditorUpdate;
47+
}
48+
49+
private void OnEditorUpdate() {
50+
// Update faders separately so the current state is maintained when the game is paused
51+
if (!EditorApplication.isPaused)
52+
_printer?.UpdateFaders();
53+
}
54+
}
55+
}

Editor/BehaviorTree/BehaviorTreeWindow.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/BehaviorTree/Printer.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
public void UpdateFaders () {
52+
_root.UpdateFaders();
53+
}
54+
}
55+
}

Editor/BehaviorTree/Printer/BehaviorTreePrinter.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/BehaviorTree/Printer/Containers.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Collections.Generic;
2+
3+
namespace CleverCrow.Fluid.BTs.Trees.Editors {
4+
public class GraphBox : IGraphBox {
5+
public List<IGraphBox> ChildContainers { get; } = new List<IGraphBox>();
6+
public bool SkipCentering { get; set; }
7+
8+
public float LocalPositionX { get; private set; }
9+
public float LocalPositionY { get; private set; }
10+
11+
public float GlobalPositionX { get; private set; }
12+
public float GlobalPositionY { get; private set; }
13+
14+
public float Width { get; private set; }
15+
public float Height { get; private set; }
16+
17+
public float PaddingX { get; private set; }
18+
public float PaddingY { get; private set; }
19+
20+
public void SetSize (float width, float height) {
21+
Width = width;
22+
Height = height;
23+
}
24+
25+
public void SetPadding (float x, float y) {
26+
Width += x;
27+
Height += y;
28+
29+
PaddingX = x;
30+
PaddingY = y;
31+
}
32+
33+
public void CenterAlignChildren () {
34+
}
35+
36+
public void SetLocalPosition (float x, float y) {
37+
LocalPositionX = x;
38+
LocalPositionY = y;
39+
}
40+
41+
public void AddGlobalPosition (float x, float y) {
42+
GlobalPositionX += x;
43+
GlobalPositionY += y;
44+
}
45+
}
46+
}

Editor/BehaviorTree/Printer/Containers/GraphBox.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System.Collections.Generic;
2+
3+
namespace CleverCrow.Fluid.BTs.Trees.Editors {
4+
public class GraphContainerHorizontal : IGraphContainer {
5+
protected readonly List<IGraphBox> _childContainers = new List<IGraphBox>();
6+
7+
public float LocalPositionX { get; private set; }
8+
public float LocalPositionY { get; private set; }
9+
public float GlobalPositionX { get; private set; }
10+
public float GlobalPositionY { get; private set; }
11+
public float Width { get; protected set; }
12+
public float Height { get; protected set; }
13+
public float PaddingX { get; }
14+
public float PaddingY { get; }
15+
public List<IGraphBox> ChildContainers => _childContainers;
16+
17+
public void SetLocalPosition (float x, float y) {
18+
LocalPositionX = x;
19+
LocalPositionY = y;
20+
}
21+
22+
public virtual void AddBox (IGraphBox child) {
23+
CalculateChild(child);
24+
_childContainers.Add(child);
25+
}
26+
27+
private void CalculateChild (IGraphBox child) {
28+
child.SetLocalPosition(Width, 0);
29+
child.AddGlobalPosition(GlobalPositionX + child.LocalPositionX, GlobalPositionY + child.LocalPositionY);
30+
31+
Width += child.Width;
32+
if (child.Height > Height) Height = child.Height;
33+
}
34+
35+
public void SetSize (float width, float height) {
36+
throw new System.NotImplementedException();
37+
}
38+
39+
public void SetGlobalPosition (float x, float y) {
40+
GlobalPositionX = x;
41+
GlobalPositionY = y;
42+
}
43+
44+
public void AddGlobalPosition (float x, float y) {
45+
GlobalPositionX += x;
46+
GlobalPositionY += y;
47+
48+
foreach (var child in ChildContainers) {
49+
child.AddGlobalPosition(x, y);
50+
}
51+
}
52+
53+
public void SetPadding (float x, float y) {
54+
throw new System.NotImplementedException();
55+
}
56+
57+
public override string ToString () {
58+
return
59+
$"Size: {Width}, {Height}; Local: {LocalPositionX}, {LocalPositionY}; Global: {GlobalPositionX}, {GlobalPositionY};";
60+
}
61+
62+
public virtual void CenterAlignChildren () {
63+
foreach (var child in _childContainers) {
64+
child.CenterAlignChildren();
65+
}
66+
}
67+
68+
public bool SkipCentering { get; }
69+
}
70+
}

Editor/BehaviorTree/Printer/Containers/GraphContainerHorizontal.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Collections.Generic;
2+
3+
namespace CleverCrow.Fluid.BTs.Trees.Editors {
4+
public class GraphContainerVertical : GraphContainerHorizontal {
5+
public override void AddBox (IGraphBox child) {
6+
CalculateChild(child);
7+
_childContainers.Add(child);
8+
}
9+
10+
private void CalculateChild (IGraphBox child) {
11+
child.SetLocalPosition(0, Height);
12+
child.AddGlobalPosition(GlobalPositionX + child.LocalPositionX, GlobalPositionY + child.LocalPositionY);
13+
14+
Height += child.Height;
15+
if (child.Width > Width) Width = child.Width;
16+
}
17+
18+
public override void CenterAlignChildren () {
19+
var positions = GetCenterAlignLocalPositions();
20+
21+
for (var i = 0; i < _childContainers.Count; i++) {
22+
var child = _childContainers[i];
23+
if (child.SkipCentering) continue;
24+
child.AddGlobalPosition(positions[i], 0);
25+
child.CenterAlignChildren();
26+
}
27+
}
28+
29+
private List<float> GetCenterAlignLocalPositions () {
30+
var list = new List<float>();
31+
foreach (var child in _childContainers) {
32+
var gap = Width - child.Width;
33+
var shift = gap / 2f;
34+
35+
list.Add(shift);
36+
}
37+
38+
return list;
39+
}
40+
}
41+
}

Editor/BehaviorTree/Printer/Containers/GraphContainerVertical.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)