Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge revamp of behaviour tree #21

Open
wants to merge 88 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
e66adb8
Added missing support for decorator nodes
SebastianMeinberger Jul 26, 2022
0e662fc
Added base classes for decorator and composite nodes
SebastianMeinberger Jul 26, 2022
cf0efe5
Added option to reset task, in order to execute them again
SebastianMeinberger Jul 26, 2022
aadffa1
Added the decorator node RepeatUntilSucess
SebastianMeinberger Jul 26, 2022
225b28e
Adapted var to naming convention
SebastianMeinberger Jul 26, 2022
92ad993
Decorator base class now sets agent
SebastianMeinberger Jul 26, 2022
9150d01
Composite base class now sets agent
SebastianMeinberger Jul 26, 2022
3ca3b5f
Navmesh agent is now not deactivated, instead isStopped attribute is …
SebastianMeinberger Jul 26, 2022
a066e3b
Added inverter node, that ivert return state from child
SebastianMeinberger Jul 26, 2022
65f7520
Added wait for proximity task
SebastianMeinberger Jul 26, 2022
1ae6b45
Added second agent to display same tree on multiple agents
SebastianMeinberger Aug 3, 2022
c84de7e
Light refactors (comments, renames and structure)
SebastianMeinberger Aug 7, 2022
90b63f3
Added comments
SebastianMeinberger Aug 7, 2022
8940644
Added node that executes one of its child tasks at random
SebastianMeinberger Aug 9, 2022
d62b756
Moved handling of executing agent and child list initlising into the …
SebastianMeinberger Aug 9, 2022
eb146b2
Added nodde that lets it child fail, if it doesn't finish in a specif…
SebastianMeinberger Aug 9, 2022
b98185a
Added support for serializing bools
SebastianMeinberger Aug 9, 2022
7f668df
Added check tasks that allow to check for conditions in the enviornment
SebastianMeinberger Aug 9, 2022
9989ca9
Obsolete, can be replaced by repeat+checkForProximity nodes
SebastianMeinberger Aug 9, 2022
f3dc8e7
Resetting values manually in reset is uneccesarry, can be done in exe…
SebastianMeinberger Aug 9, 2022
a038c1c
Resetting a running task now also triggers Stop()
SebastianMeinberger Aug 9, 2022
e39bd58
RunnerInspector can now properly display serialized bools
SebastianMeinberger Aug 9, 2022
ff1bf07
navMeshAgent has to be set before execute is executed
SebastianMeinberger Aug 9, 2022
781f376
Sample tree displays the new node types
SebastianMeinberger Aug 9, 2022
51b6150
Higher children are now executed before lower children
SebastianMeinberger Aug 10, 2022
d1fba78
RootNode is now automatically added to every Tree Asset
SebastianMeinberger Aug 10, 2022
8b5cdcb
Rootnodes can now neither be deleted nor created
SebastianMeinberger Aug 20, 2022
ff52289
Root is now only added, if the asset is already saved (otherwise, an …
SebastianMeinberger Aug 20, 2022
d3f1ac8
Added a root node
SebastianMeinberger Aug 20, 2022
1eaafbd
Merge branch 'enhancment/behavior_tree_InSceneInspector' into enhancm…
SebastianMeinberger Aug 23, 2022
b4df3f6
Merge branch 'enhancment/behavior_tree_executionOrder' into enhancmen…
SebastianMeinberger Aug 23, 2022
a9e68a7
Root Node is only added after asset is named (i.e. pemanently saved)
SebastianMeinberger Aug 23, 2022
97e0e98
Interacting with the BH editor is now forbidden if the tree is not pa…
SebastianMeinberger Aug 23, 2022
7f54abc
Random node now has changable probabilities
SebastianMeinberger Aug 24, 2022
0ddde4d
Extracted CreatedNodesOverwriteData into a function
SebastianMeinberger Sep 1, 2022
6516e77
Added a BehaviourTree task
SebastianMeinberger Sep 1, 2022
eadf445
Serialized data is now cleared when creating new one, which fixes the…
SebastianMeinberger Sep 2, 2022
ded2ad7
Cleaned up the wrong serialization data
SebastianMeinberger Sep 2, 2022
fb45b92
Added AlwaysSucceed Decorator Node
SebastianMeinberger Sep 2, 2022
8cc66fc
update to newer unity version
David624634 Apr 6, 2024
4ce6941
fixing build error
David624634 Apr 6, 2024
01f75c4
added editable message to debug node
David624634 Apr 6, 2024
9785601
Merge branch 'feature/integratingBehaviorTree' into fix/builderrors
David624634 Apr 6, 2024
06ae0a9
fix naming errors of merge
David624634 Apr 6, 2024
cfb5652
Merge pull request #15 from David624634/fix/builderrors
David624634 Apr 6, 2024
0dc64dc
renaming method name to name on develop branch
David624634 Apr 7, 2024
b900fbd
Revert "Remove behavior tree completely"
David624634 Apr 7, 2024
6773031
Revert "Build error fix: encapsulated behavior tree in editor only as…
David624634 Apr 7, 2024
9ae47d0
Merge branch 'feature/integratingBehaviorTree' into merge/behaviorTree
David624634 Apr 7, 2024
96a58cc
updated BehaviorTree sample
David624634 Apr 7, 2024
7b317a5
updated animation start trigger
David624634 Apr 7, 2024
b44447a
Added: double clicking tree asset opens editor
David624634 Apr 15, 2024
db98443
visual revamp of behaviorTree and added sample scenes
David624634 Apr 28, 2024
907eef6
fixed: edges don't get removed in tree editor
David624634 Apr 28, 2024
a831671
fixed naming warning
David624634 Apr 28, 2024
d5e6795
added Undo/Redo operations to behavior tree
David624634 Apr 29, 2024
17f828f
improved sample trees structure
David624634 May 5, 2024
09b210b
editor opens corresponding tree when agent is selected
David624634 May 5, 2024
7662592
running/failed/success state is now shown in editor while running
David624634 May 5, 2024
c8c9890
tree from hierarchy outside of playmode
David624634 May 5, 2024
6b0ff34
Added error messages and highlighting for wrongly formatted trees
David624634 May 5, 2024
774c253
fixed random node (broke samples)
David624634 May 5, 2024
8d0c6d8
enhanced pickability of connection points
David624634 May 6, 2024
c4b3280
renamed behavior to behaviour
David624634 May 12, 2024
41f63e4
Serializations of tree nodes now update automatically when new attrib…
David624634 May 13, 2024
1b64b31
Added method to update serialization keys in existing files
David624634 May 13, 2024
fc4cb83
Added new Tasks and options to Behaviour Tree
David624634 May 13, 2024
cbf8e4a
Added changeable descriptions to nodes in editor
David624634 May 23, 2024
d5613f3
Improved in-editor manuel
David624634 May 26, 2024
a1c533d
Editor can now switch between task states of multiple agents
David624634 Jun 6, 2024
f523e8d
Inspector for nodes in inspector opens at the top now
David624634 Jun 6, 2024
539be70
Added better warnings
David624634 Jun 6, 2024
01fc7b2
fixed task status persisting when playmode is ended
David624634 Jun 7, 2024
313722d
added auto layout button
David624634 Jun 12, 2024
7b34bf9
small fixes
David624634 Jun 17, 2024
cb7c47e
revamped samples
David624634 Jun 17, 2024
e32ace0
added test scene
David624634 Jun 17, 2024
c426e6b
completed documentation
David624634 Jun 17, 2024
0fc316d
Merge branch 'develop' into merge/behaviorTree
David624634 Jun 17, 2024
b49f31a
added test run for behaviour tree
David624634 Jun 17, 2024
8c1851e
small fixes in example scenes
David624634 Jun 17, 2024
198e121
added references to behaviour tree in other parts of the documentation
David624634 Jun 17, 2024
5058ed9
Added samples to sample list
David624634 Jun 17, 2024
2c287dc
spelling corrections
David624634 Jun 17, 2024
a16d11b
revert breaking spelling correction
David624634 Jun 17, 2024
678869e
Resolve merge conflicts, merging behaviourTree into develop
lenalinke Oct 12, 2024
245e33d
Fix issues with SerializationDataContainer.cs and typos
lenalinke Oct 12, 2024
03a8619
Add previously untracked .meta file
lenalinke Oct 12, 2024
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@ crashlytics-build.properties

# Files generated by documentation tool
/Assets/Virtual Agents Framework/Editor/Scripts/Behaviour Tree/obj
/Assets/Virtual Agents Framework/Editor/Scripts/Behaviour Tree/obj.meta
/Assets/Virtual Agents Framework/Editor/Scripts/Behaviour Tree/obj.meta

# Files generated by spelling error correction
ltex.dictionary.en-US.txt
8 changes: 8 additions & 0 deletions Assets/Editor.meta

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

39 changes: 39 additions & 0 deletions Assets/Editor/RWTHColors.colors
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 12323, guid: 0000000000000000e000000000000000, type: 0}
m_Name: RWTHColors
m_EditorClassIdentifier:
m_Presets:
- m_Name:
m_Color: {r: 0, g: 0.03137255, b: 0.62352943, a: 1}
- m_Name:
m_Color: {r: 0.5568628, g: 0.7294118, b: 0.8980392, a: 1}
- m_Name:
m_Color: {r: 0.8901961, g: 0, b: 0.4, a: 1}
- m_Name:
m_Color: {r: 1, g: 0.92941177, b: 0, a: 1}
- m_Name:
m_Color: {r: 0, g: 0.38039216, b: 0.39607844, a: 1}
- m_Name:
m_Color: {r: 0, g: 0.59607846, b: 0.6313726, a: 1}
- m_Name:
m_Color: {r: 0.34117648, g: 0.67058825, b: 0.15294118, a: 1}
- m_Name:
m_Color: {r: 0.9647059, g: 0.65882355, b: 0, a: 1}
- m_Name:
m_Color: {r: 0.8, g: 0.02745098, b: 0.11764706, a: 1}
- m_Name:
m_Color: {r: 0.6313726, g: 0.0627451, b: 0.20784314, a: 1}
- m_Name:
m_Color: {r: 0.38039216, g: 0.12941177, b: 0.34509805, a: 1}
- m_Name:
m_Color: {r: 0.47843137, g: 0.43529412, b: 0.6745098, a: 1}
8 changes: 8 additions & 0 deletions Assets/Editor/RWTHColors.colors.meta

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,177 @@
using i5.VirtualAgents.BehaviourTrees;
using i5.VirtualAgents.BehaviourTrees.Visual;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.UIElements;

namespace i5.VirtualAgents.Editor.BehaviourTrees
{
/// <summary>
/// Provides a visual Behaviour Tree Editor.
/// </summary>
public class BehaviourTreeEditor : EditorWindow
{
private BehaviourTreeView treeView;
private InspectorView inspectorView;
private Label treeViewOccludeLabel;
private VisualElement occludeLabelParent;
private Button saveButton;
private Button layoutButton;

[MenuItem("Virtual Agents Framework/Behaviour Tree Editor")]
public static BehaviourTreeEditor ShowWindow()
{
BehaviourTreeEditor window = GetWindow<BehaviourTreeEditor>();
window.titleContent = new GUIContent("Behaviour Tree Editor");
// Set minimum window size, so that every part of the Editor can be seen
window.minSize = new Vector2(600f, 400f);
return window;
}

public void CreateGUI()
{
// Each editor window contains a root VisualElement object
VisualElement root = rootVisualElement;

// Import UXML. The UXML was generated by the Unity UIBuilder and contains which visual elements in which configuration comprise the BehaviourTreeEditor.
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Virtual Agents Framework/Editor/UI Builder/Behaviour Tree/BehaviourTreeEditor.uxml");
visualTree.CloneTree(root);

// A stylesheet can be added to a VisualElement.
// The style will be applied to the VisualElement and all of its children.
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Virtual Agents Framework/Editor/UI Builder/Behaviour Tree/BehaviourTreeEditorStyleSheet.uss");
root.styleSheets.Add(styleSheet);

// Fetch and initialize objects from window
treeView = root.Query<BehaviourTreeView>();
treeView.SetupManipulators();
inspectorView = root.Query<InspectorView>();
treeView.OnNodeSelect = OnNodeSelectionChanged;
treeViewOccludeLabel = root.Query<Label>("treeViewOccludeLabel");
occludeLabelParent = treeViewOccludeLabel.parent;

// Setup the save button
saveButton = root.Query<Button>("Save");
saveButton.clicked += SaveTree;

// Setup the auto layout button
layoutButton = root.Query<Button>("AutoLayout");
layoutButton.clicked += AutoLayoutTree;

// Forbid until a tree is selected
ForbidTreeEditing();
}

// Changes the currently edited tree to the one selected in the unity project tab
private void OnSelectionChange()
{
LoadSelectedTree();
}

private void LoadSelectedTree()
{
BehaviourTreeAsset tree = Selection.activeObject as BehaviourTreeAsset;
// If the tree is not selected in the project window, check if the tree is attached to the selected game object
if (!tree)
{
if (Selection.activeGameObject)
{
if (Selection.activeGameObject.TryGetComponent<BehaviourTreeRunner>(out var runner))
{
if(runner.Tree == null)
{
return;
}
tree = runner.Tree;
Debug.Log("Tree selected from hierarchy window: " + tree.name);
AllowTreeEditing();
treeView.PopulateView(tree);

if (Selection.activeGameObject.GetComponent<Agent>())
{
treeView.CurrentlySelectedAgent = Selection.activeGameObject.GetComponent<Agent>();
}
}

}
}
// If a tree is selected in the project window, populate the editor with the tree
else
{
if (AssetDatabase.Contains(tree))
{
AllowTreeEditing();
treeView.PopulateView(tree);
}
else
{
// The asset is currently being created and named. Delay loading the tree until the tree is fully created.
ForbidTreeEditing();
tree.CreatedAndNamed += LoadSelectedTree;
}
}
}

[OnOpenAsset]
// Handles opening the editor window when double-clicking BehaviourTreeAsset files
public static bool OnOpenAsset(int instanceID, int line)
{
UnityEngine.Object obj = EditorUtility.InstanceIDToObject(instanceID);

if (obj is BehaviourTreeAsset)
{
BehaviourTreeEditor window = ShowWindow();
window.LoadSelectedTree();
return true;
}
return false;

}

// Allows the user interact with the editor
private void AllowTreeEditing()
{
treeViewOccludeLabel.RemoveFromHierarchy();
treeView.SetEnabled(true);
saveButton.SetEnabled(true);
layoutButton.SetEnabled(true);
}

// Forbids the user to interact with the editor
private void ForbidTreeEditing()
{
if (!occludeLabelParent.Contains(treeViewOccludeLabel))
{
occludeLabelParent.Insert(0, treeViewOccludeLabel);
}
treeView.SetEnabled(false);
saveButton.SetEnabled(false);
layoutButton.SetEnabled(false);
}

// Displays the inspector for the currently selected node
private void OnNodeSelectionChanged(NodeView view)
{
inspectorView.UpdateSelection(view);
}

// Saves all changes made to the currently selected Behaviour Tree to the disc
private void SaveTree()
{
EditorUtility.SetDirty(treeView.Tree);
AssetDatabase.SaveAssets();
}

// Orders the tree in a way that the nodes are displayed in a more readable way
private void AutoLayoutTree()
{
treeView.AutoLayoutTree();
}

private void OnInspectorUpdate()
{
treeView?.UpdateNodeStates();
}
}
}

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

Loading
Loading