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
@@ -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
}
}