Added: Unity Behavior Graph asset for behaviour demo

This commit is contained in:
2026-11-12 18:54:45 +01:00
parent a9a29ac7c8
commit 7bd50affc9
32 changed files with 4163 additions and 7 deletions
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1c7088242d8e9401d810873c059860af
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4cd2fca1fc28b47cebdd53591c9d0ce7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 65669a08015ff4c2cad4097932064aba
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
+46 -3
View File
@@ -492,7 +492,7 @@ Transform:
m_GameObject: {fileID: 719183278}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: -0.11, y: 1, z: 7.67}
m_LocalPosition: {x: 0, y: 1, z: 7.67}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -738,6 +738,8 @@ GameObject:
- component: {fileID: 969040267}
- component: {fileID: 969040266}
- component: {fileID: 969040270}
- component: {fileID: 969040271}
- component: {fileID: 969040272}
m_Layer: 0
m_Name: Enemy
m_TagString: Untagged
@@ -834,7 +836,7 @@ Transform:
m_GameObject: {fileID: 969040265}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.70711, y: 1, z: -12.52}
m_LocalPosition: {x: 0, y: 1, z: -12.52}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -847,12 +849,53 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 969040265}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5584ae56d5b0404cb46ba84f0b62a341, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::AI.FSM.ChaseStateMachine
_playerTransform: {fileID: 719183282}
--- !u!114 &969040271
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 969040265}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f0038c16c34866b4f9e25c9c0dc0f7e6, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.Behavior::Unity.Behavior.BehaviorGraphAgent
m_Graph: {fileID: -1542508069126555020, guid: 65669a08015ff4c2cad4097932064aba, type: 2}
m_BlackboardVariableOverridesList:
- rid: 5073109553226973917
m_OriginalGraph: {fileID: 0}
m_IsInitialised: 0
m_IsStarted: 0
references:
version: 2
RefIds:
- rid: 5073109553226973917
type: {class: 'BlackboardVariable`1[[UnityEngine.GameObject, UnityEngine.CoreModule]]', ns: Unity.Behavior, asm: Unity.Behavior}
data:
GUID:
m_Value0: 1
m_Value1: 0
Name: Self
m_Value: {fileID: 969040265}
--- !u!114 &969040272
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 969040265}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b2377a84a8744e51ad63470db235b306, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::AI.BehaviourTree.BehaviourTree
--- !u!1 &1661958343
GameObject:
m_ObjectHideFlags: 0
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 299decc0c1c84f348d67c778592f87bf
timeCreated: 1794502155
+10
View File
@@ -0,0 +1,10 @@
namespace AI.BehaviourTree
{
public abstract class Action : Node
{
protected Action()
{
children = null;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f74fc08720e6434d99bf774b6a6f3b09
timeCreated: 1794503810
@@ -0,0 +1,30 @@
using UnityEngine;
namespace AI.BehaviourTree
{
public class BehaviourTree : MonoBehaviour
{
private Node rootNode;
private void OnEnable()
{
NodeStatus status = rootNode.Start();
Debug.Log("Behaviour tree started");
Debug.Log($"Behaviour tree start root node status: {status}");
if (status != NodeStatus.Running) enabled = false;
}
private void OnDisable()
{
Debug.Log("Behaviour tree stopped");
rootNode.Stop();
}
private void Update()
{
NodeStatus status = rootNode.Execute();
Debug.Log($"Behaviour tree execute root node status: {status}");
if (status != NodeStatus.Running) enabled = false;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b2377a84a8744e51ad63470db235b306
timeCreated: 1794502220
@@ -0,0 +1,10 @@
namespace AI.BehaviourTree
{
public abstract class Composite : Node
{
protected Composite(params Node[] children)
{
this.children.AddRange(children);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f3fc40a957b743bbb38e5fc6ac76431a
timeCreated: 1794503869
@@ -0,0 +1,7 @@
namespace AI.BehaviourTree
{
public abstract class Condition : Action
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bb50593562d3477d9c9b37ff6c40c654
timeCreated: 1794503879
@@ -0,0 +1,10 @@
namespace AI.BehaviourTree
{
public abstract class Decorator : Node
{
protected Decorator(Node child)
{
this.children.Add(child);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0a8feb2ab491450fa977c32f0262f949
timeCreated: 1794503911
+23
View File
@@ -0,0 +1,23 @@
using System.Collections.Generic;
namespace AI.BehaviourTree
{
public abstract class Node
{
protected List<Node> children = new List<Node>();
public virtual NodeStatus Start() => NodeStatus.Running;
public virtual NodeStatus Execute() => NodeStatus.Success;
public virtual void Stop()
{
}
}
public enum NodeStatus
{
Running,
Success,
Failure
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 53b501c551ff46848aaadb57d7118a3e
timeCreated: 1794502273
@@ -0,0 +1,7 @@
namespace AI.BehaviourTree
{
public class Selector : Composite
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 025f7db0aae240698cce07fb6743c2d9
timeCreated: 1794503925
@@ -0,0 +1,67 @@
namespace AI.BehaviourTree
{
public class Sequence : Composite
{
Node _currentChild;
int _currentChildIndex = 0;
public Sequence(params Node[] children) : base(children)
{
}
public override NodeStatus Start()
{
if (children.Count == 0) return NodeStatus.Failure;
_currentChildIndex = 0;
_currentChild = children[_currentChildIndex];
// if status == NodeStatus.Failure => whole sequence fails => return NodeStatus.Failure;
// if status == NodeStatus.Success => run the next child
do
{
NodeStatus status = _currentChild?.Start() ?? NodeStatus.Failure;
if (status == NodeStatus.Failure) return NodeStatus.Failure;
if (status == NodeStatus.Running) return NodeStatus.Running;
} while (RunNextChild());
return NodeStatus.Success;
}
public override NodeStatus Execute()
{
NodeStatus status = _currentChild?.Execute() ?? NodeStatus.Failure;
if (status == NodeStatus.Failure) return NodeStatus.Failure;
if (status == NodeStatus.Running) return NodeStatus.Running;
while (RunNextChild())
{
status = _currentChild?.Start() ?? NodeStatus.Failure;
if (status == NodeStatus.Failure) return NodeStatus.Failure;
if (status == NodeStatus.Running) return NodeStatus.Running;
}
return NodeStatus.Success;
}
public override void Stop()
{
_currentChild?.Stop();
}
private bool RunNextChild()
{
_currentChild?.Stop();
_currentChild = null;
_currentChildIndex++;
if (_currentChildIndex < children.Count)
{
_currentChild = children[_currentChildIndex];
return true;
}
return false;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71354184e3e64c428a329b5c493b8cc9
timeCreated: 1794503979
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 61b9621051732437db91df5e92e80098
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,56 @@
using System;
using Core;
using Unity.Behavior;
using UnityEngine;
using Action = Unity.Behavior.Action;
using Unity.Properties;
[Serializable, GeneratePropertyBag]
[NodeDescription(name: "FindByRaycastAction", story: "Find Player [Target] by raycast from [Self]", category: "Action",
id: "0211c365022a481bc2c40a1c93ef9f2b")]
public partial class FindByRaycastAction : Action
{
[SerializeReference] public BlackboardVariable<GameObject> Target;
[SerializeReference] public BlackboardVariable<GameObject> Self;
[SerializeReference] public BlackboardVariable<float> MaxDistance = new(10.0f);
[SerializeReference] public BlackboardVariable<Boolean> IsFound = new(false);
protected override Status OnStart()
{
// initialize the node
return Status.Running;
}
protected override Status OnUpdate()
{
// will be called every frame until the node returns a status not running
Target.Value = null;
IsFound.Value = false;
RaycastHit hit;
if (!Physics.Raycast(Self.Value.transform.position, Self.Value.transform.forward, out hit,
MaxDistance.Value))
{
return Status.Failure;
}
// return hit.collider.gameObject == Target.Value ? Status.Success : Status.Failure;
PlayerController playerController = hit.collider.gameObject.GetComponent<PlayerController>();
if (playerController == null)
{
return Status.Failure;
}
Target.Value = playerController.gameObject;
IsFound.Value = true;
return Status.Success;
}
protected override void OnEnd()
{
// deinitialize the node
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1561f6f216f4a46f9b1cccf66f577ed8
@@ -0,0 +1,27 @@
using System;
using Unity.Behavior;
using UnityEngine;
[Serializable, Unity.Properties.GeneratePropertyBag]
[Condition(name: "GameObjectNullCondition", story: "[Target] [is] null", category: "Conditions", id: "6766cb3cdf20628407006d946fe46a8b")]
public partial class GameObjectNullCondition : Condition
{
[SerializeReference] public BlackboardVariable<GameObject> Target;
[Comparison(comparisonType: ComparisonType.Boolean)]
[SerializeReference] public BlackboardVariable<ConditionOperator> Is;
public override bool IsTrue()
{
if (Target.Value == null && Is.Value == ConditionOperator.Equal) return true;
if (Target.Value != null && Is.Value == ConditionOperator.NotEqual) return true;
return false;
}
public override void OnStart()
{
}
public override void OnEnd()
{
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5c7760d815f8b4823b6cae55d87fc5b8
+1
View File
@@ -1,6 +1,7 @@
{
"dependencies": {
"com.unity.ai.navigation": "2.0.14",
"com.unity.behavior": "1.0.17",
"com.unity.collab-proxy": "2.13.6",
"com.unity.ide.rider": "3.0.40",
"com.unity.ide.visualstudio": "2.0.26",
+40 -4
View File
@@ -9,9 +9,26 @@
},
"url": "https://packages.unity.com"
},
"com.unity.behavior": {
"version": "1.0.17",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.7.2",
"com.unity.dt.app-ui": "2.2.3",
"com.unity.modules.ai": "1.0.0",
"com.unity.collections": "2.1.4",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.burst": {
"version": "1.8.30",
"depth": 2,
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.mathematics": "1.2.1",
@@ -28,7 +45,7 @@
},
"com.unity.collections": {
"version": "2.6.8",
"depth": 2,
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.8.29",
@@ -39,6 +56,18 @@
},
"url": "https://packages.unity.com"
},
"com.unity.dt.app-ui": {
"version": "2.2.3",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.screencapture": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.ext.nunit": {
"version": "2.0.5",
"depth": 1,
@@ -89,7 +118,14 @@
},
"com.unity.nuget.mono-cecil": {
"version": "1.11.6",
"depth": 3,
"depth": 2,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.nuget.newtonsoft-json": {
"version": "3.2.2",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
@@ -154,7 +190,7 @@
},
"com.unity.test-framework.performance": {
"version": "3.5.0",
"depth": 3,
"depth": 2,
"source": "registry",
"dependencies": {
"com.unity.test-framework": "1.1.33",
+28
View File
@@ -0,0 +1,28 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 53
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: 11500000, guid: 6118340bc55d5fc4b88ef6970b16d122, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.Behavior.Authoring::Unity.Behavior.BehaviorProjectSettings
m_GraphOwnerName: Self
m_AutoSaveLastSaveLocation: 1
m_SaveFolder: Scripts/UnityBehaviours
m_UseSeparateSaveFolders: 0
m_SaveFolderAction:
m_SaveFolderModifier:
m_SaveFolderFlow:
m_SaveFolderCondition:
m_SaveFolderEventChannels:
m_SaveFolderEnum:
m_AutoOpenNodeScriptsInExternalEditor: 1
m_Namespace:
m_AllowDisabledAgentDebugging: 0
m_IgnoreMissingManagedReferencesInBuild: 0
@@ -9,5 +9,6 @@ EditorBuildSettings:
path: Assets/Scenes/SampleScene.unity
guid: 99c9720ab356a0642a771bea13969a05
m_configObjects:
com.unity.dt.app-ui: {fileID: 11400000, guid: 99f9c9493070a9d4c979a8fec7c5a8d3, type: 2}
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 052faaac586de48259a63d0c4782560b, type: 3}
m_UseUCBPForAssetBundles: 0