Added: Unity Behavior Graph asset for behaviour demo
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user