Added Behavior Graph asset for AI simulations
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using DefaultNamespace;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "Find by Raycast", story: "Find [Target] by raycast from [Agent]", category: "Action/Find", id: "cde581f97d96148705ed557e6d9ef0c0")]
|
||||
public partial class FindByRaycastAction : Action
|
||||
{
|
||||
[SerializeReference] public BlackboardVariable<GameObject> Target;
|
||||
[SerializeReference] public BlackboardVariable<GameObject> Agent;
|
||||
[SerializeReference] public BlackboardVariable<float> MaxDistance = new(10.0f);
|
||||
|
||||
protected override Status OnStart()
|
||||
{
|
||||
// initialize the node
|
||||
|
||||
// check variables first
|
||||
if (Agent.Value == null) return Status.Failure;
|
||||
|
||||
return Status.Running;
|
||||
}
|
||||
|
||||
protected override Status OnUpdate()
|
||||
{
|
||||
// will be called every frame while the node is running
|
||||
Target.Value = null;
|
||||
|
||||
RaycastHit hit;
|
||||
if (!Physics.Raycast(Agent.Value.transform.position, Agent.Value.transform.forward, out hit, MaxDistance)) return Status.Failure;
|
||||
|
||||
PlayerController playerController = hit.collider.GetComponent<PlayerController>();
|
||||
if (!playerController) return Status.Failure;
|
||||
|
||||
Target.Value = playerController.gameObject;
|
||||
return Status.Success;
|
||||
}
|
||||
|
||||
protected override void OnEnd()
|
||||
{
|
||||
// deinitialize the node
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user