Skip to content

Commit

Permalink
Merge pull request #106 from ashblue/feature/master-fix
Browse files Browse the repository at this point in the history
Feature/master fix
  • Loading branch information
ashblue authored Nov 9, 2024
0 parents commit ff2fa5d
Show file tree
Hide file tree
Showing 247 changed files with 7,226 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Placeholder for meta files
7 changes: 7 additions & 0 deletions CHANGELOG.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/BehaviorTree.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Editor/BehaviorTree/BehaviorTreeDrawer.cs
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, tree.Name ?? property.displayName);
}
GUI.enabled = true;

EditorGUI.EndProperty();
}
}
}
11 changes: 11 additions & 0 deletions Editor/BehaviorTree/BehaviorTreeDrawer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions Editor/BehaviorTree/BehaviorTreeWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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<BehaviorTreeWindow>(false);
window.titleContent = new GUIContent($"Behavior Tree: {name}");
window.SetTree(tree, name);
}

private void SetTree (IBehaviorTree tree, string name) {
_printer?.Unbind();
_printer = new BehaviorTreePrinter(tree, position.size);
_name = name;
}

private void OnGUI () {
if (!Application.isPlaying) {
ClearView();
}

GUILayout.Label($"Behavior Tree: {_name}", EditorStyles.boldLabel);
_printer?.Print(position.size);
}

private void ClearView () {
_name = null;
_printer = null;
}

private void Update () {
if (Application.isPlaying) {
Repaint();
}
}

void OnEnable() {
EditorApplication.update += OnEditorUpdate;
}

void OnDisable() {
EditorApplication.update -= OnEditorUpdate;
}

private void OnEditorUpdate() {
// Update faders separately so the current state is maintained when the game is paused
if (!EditorApplication.isPaused)
_printer?.UpdateFaders();
}
}
}
3 changes: 3 additions & 0 deletions Editor/BehaviorTree/BehaviorTreeWindow.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Editor/BehaviorTree/Printer.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions Editor/BehaviorTree/Printer/BehaviorTreePrinter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using UnityEngine;

namespace CleverCrow.Fluid.BTs.Trees.Editors {
public class BehaviorTreePrinter {
private const float SCROLL_PADDING = 40;

private readonly VisualTask _root;
private readonly Rect _containerSize;

private Vector2 _scrollPosition;

public static StatusIcons StatusIcons { get; private set; }
public static GuiStyleCollection SharedStyles { get; private set; }


public BehaviorTreePrinter (IBehaviorTree tree, Vector2 windowSize) {
StatusIcons = new StatusIcons();
SharedStyles = new GuiStyleCollection();

var container = new GraphContainerVertical();
container.SetGlobalPosition(SCROLL_PADDING, SCROLL_PADDING);
_root = new VisualTask(tree.Root, container);
container.CenterAlignChildren();

_containerSize = new Rect(0, 0,
container.Width + SCROLL_PADDING * 2,
container.Height + SCROLL_PADDING * 2);

CenterScrollView(windowSize, container);
}

private void CenterScrollView (Vector2 windowSize, GraphContainerVertical container) {
var scrollOverflow = container.Width + SCROLL_PADDING * 2 - windowSize.x;
var centerViewPosition = scrollOverflow / 2;
_scrollPosition.x = centerViewPosition;
}

public void Print (Vector2 windowSize) {
_scrollPosition = GUI.BeginScrollView(
new Rect(0, 0, windowSize.x, windowSize.y),
_scrollPosition,
_containerSize);
_root.Print();
GUI.EndScrollView();
}

public void Unbind () {
_root.RecursiveTaskUnbind();
}

public void UpdateFaders () {
_root.UpdateFaders();
}
}
}
3 changes: 3 additions & 0 deletions Editor/BehaviorTree/Printer/BehaviorTreePrinter.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Editor/BehaviorTree/Printer/Containers.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Editor/BehaviorTree/Printer/Containers/GraphBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Collections.Generic;

namespace CleverCrow.Fluid.BTs.Trees.Editors {
public class GraphBox : IGraphBox {
public List<IGraphBox> ChildContainers { get; } = new List<IGraphBox>();
public bool SkipCentering { get; set; }

public float LocalPositionX { get; private set; }
public float LocalPositionY { get; private set; }

public float GlobalPositionX { get; private set; }
public float GlobalPositionY { get; private set; }

public float Width { get; private set; }
public float Height { get; private set; }

public float PaddingX { get; private set; }
public float PaddingY { get; private set; }

public void SetSize (float width, float height) {
Width = width;
Height = height;
}

public void SetPadding (float x, float y) {
Width += x;
Height += y;

PaddingX = x;
PaddingY = y;
}

public void CenterAlignChildren () {
}

public void SetLocalPosition (float x, float y) {
LocalPositionX = x;
LocalPositionY = y;
}

public void AddGlobalPosition (float x, float y) {
GlobalPositionX += x;
GlobalPositionY += y;
}
}
}
11 changes: 11 additions & 0 deletions Editor/BehaviorTree/Printer/Containers/GraphBox.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions Editor/BehaviorTree/Printer/Containers/GraphContainerHorizontal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Collections.Generic;

namespace CleverCrow.Fluid.BTs.Trees.Editors {
public class GraphContainerHorizontal : IGraphContainer {
protected readonly List<IGraphBox> _childContainers = new List<IGraphBox>();

public float LocalPositionX { get; private set; }
public float LocalPositionY { get; private set; }
public float GlobalPositionX { get; private set; }
public float GlobalPositionY { get; private set; }
public float Width { get; protected set; }
public float Height { get; protected set; }
public float PaddingX { get; }
public float PaddingY { get; }
public List<IGraphBox> ChildContainers => _childContainers;

public void SetLocalPosition (float x, float y) {
LocalPositionX = x;
LocalPositionY = y;
}

public virtual void AddBox (IGraphBox child) {
CalculateChild(child);
_childContainers.Add(child);
}

private void CalculateChild (IGraphBox child) {
child.SetLocalPosition(Width, 0);
child.AddGlobalPosition(GlobalPositionX + child.LocalPositionX, GlobalPositionY + child.LocalPositionY);

Width += child.Width;
if (child.Height > Height) Height = child.Height;
}

public void SetSize (float width, float height) {
throw new System.NotImplementedException();
}

public void SetGlobalPosition (float x, float y) {
GlobalPositionX = x;
GlobalPositionY = y;
}

public void AddGlobalPosition (float x, float y) {
GlobalPositionX += x;
GlobalPositionY += y;

foreach (var child in ChildContainers) {
child.AddGlobalPosition(x, y);
}
}

public void SetPadding (float x, float y) {
throw new System.NotImplementedException();
}

public override string ToString () {
return
$"Size: {Width}, {Height}; Local: {LocalPositionX}, {LocalPositionY}; Global: {GlobalPositionX}, {GlobalPositionY};";
}

public virtual void CenterAlignChildren () {
foreach (var child in _childContainers) {
child.CenterAlignChildren();
}
}

public bool SkipCentering { get; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Editor/BehaviorTree/Printer/Containers/GraphContainerVertical.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;

namespace CleverCrow.Fluid.BTs.Trees.Editors {
public class GraphContainerVertical : GraphContainerHorizontal {
public override void AddBox (IGraphBox child) {
CalculateChild(child);
_childContainers.Add(child);
}

private void CalculateChild (IGraphBox child) {
child.SetLocalPosition(0, Height);
child.AddGlobalPosition(GlobalPositionX + child.LocalPositionX, GlobalPositionY + child.LocalPositionY);

Height += child.Height;
if (child.Width > Width) Width = child.Width;
}

public override void CenterAlignChildren () {
var positions = GetCenterAlignLocalPositions();

for (var i = 0; i < _childContainers.Count; i++) {
var child = _childContainers[i];
if (child.SkipCentering) continue;
child.AddGlobalPosition(positions[i], 0);
child.CenterAlignChildren();
}
}

private List<float> GetCenterAlignLocalPositions () {
var list = new List<float>();
foreach (var child in _childContainers) {
var gap = Width - child.Width;
var shift = gap / 2f;

list.Add(shift);
}

return list;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ff2fa5d

Please sign in to comment.