Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

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,19 @@
using GroveGames.BehaviourTree.Collections;
using UnityEngine;

namespace GroveGames.BehaviourTree.Unity
{
public abstract class BehaviourTreeMono : MonoBehaviour
{
protected BehaviourTree _tree;
public BehaviourTree Tree => _tree;

protected abstract BehaviourTree CreateTree(Blackboard blackboard);

protected virtual void Awake()
{
var blackboard = new Blackboard();
_tree = CreateTree(blackboard);
}
}
}

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

11 changes: 11 additions & 0 deletions src/GroveGames.BehaviourTree/Nodes/BehaviourNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ public abstract class BehaviourNode : INode
public static readonly INode Empty = new EmptyBehaviourNode();

private IParent _parent = null!;
private string _name;
protected NodeState _nodeState;

protected IParent Parent => _parent;
public IBlackboard Blackboard => _parent.Blackboard;
public NodeState State => _nodeState;
public string Name => _name;

public BehaviourNode()
{
_name = GetType().Name;
}

public virtual void SetParent(IParent parent)
{
Expand Down Expand Up @@ -42,4 +49,8 @@ public virtual void EndEvaluate()
{

}
public void SetName(string name)
{
_name = name;
}
}
8 changes: 8 additions & 0 deletions src/GroveGames.BehaviourTree/Nodes/BehaviourRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ public sealed class BehaviourRoot : IRoot
private readonly IBlackboard _blackboard;
private INode _child;
private NodeState _nodeState;
private string _name;

public IBlackboard Blackboard => _blackboard;
public NodeState State => _nodeState;
public string Name => _name;

public BehaviourRoot(IBlackboard blackboard)
{
_blackboard = blackboard;
_child = BehaviourNode.Empty;
_name = GetType().Name;
}

public NodeState Evaluate(float deltaTime)
Expand Down Expand Up @@ -64,4 +67,9 @@ public void SetParent(IParent parent)
{

}

public void SetName(string name)
{
_name = name;
}
}
7 changes: 7 additions & 0 deletions src/GroveGames.BehaviourTree/Nodes/EmptyBehaviourNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public sealed class EmptyBehaviourNode : INode
{
public NodeState State => NodeState.Failure;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
return NodeState.Failure;
Expand Down Expand Up @@ -33,4 +35,9 @@ public void SetParent(IParent parent)
{

}

public void SetName(string name)
{

}
}
2 changes: 2 additions & 0 deletions src/GroveGames.BehaviourTree/Nodes/INode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public interface INode
public void StartEvaluate();
public void EndEvaluate();
public void SetParent(IParent parent);
public void SetName(string name);
public NodeState State { get; }
public string Name { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ private sealed class TestNode : INode
public int ResetCallCount { get; private set; }
public NodeState State { get; set; } = NodeState.Success;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime) => State;

public void Reset()
Expand All @@ -61,6 +63,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime) => ReturnState;
public void Reset() { }
public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -34,6 +36,10 @@ public void Reset() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -31,6 +33,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -32,6 +34,10 @@ public void Reset() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -31,6 +33,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -31,6 +33,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private sealed class TestNode : INode
public float LastDeltaTime { get; private set; }
public NodeState State => NodeState.Success;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -34,6 +36,10 @@ public NodeState Evaluate(float deltaTime)
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -31,6 +33,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -31,6 +33,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -31,6 +33,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -31,6 +33,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -32,6 +34,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ private sealed class TestNode : INode
public NodeState ReturnState { get; set; } = NodeState.Success;
public NodeState State => ReturnState;

public string Name => string.Empty;

public NodeState Evaluate(float deltaTime)
{
EvaluateCount++;
Expand All @@ -31,6 +33,10 @@ public void Abort() { }
public void StartEvaluate() { }
public void EndEvaluate() { }
public void SetParent(IParent parent) { }

public void SetName(string name)
{
}
}

private sealed class TestParent : IParent
Expand Down
Loading
Loading