add unity behavior package & examples
add behavior tree implementation
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using DefaultNamespace;
|
||||
using DefaultNamespace.FSM;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
using Action = Unity.Behavior.Action;
|
||||
using Unity.Properties;
|
||||
|
||||
[Serializable, GeneratePropertyBag]
|
||||
[NodeDescription(name: "Find Player Controller By Raycast", story: "Find [Target] by Raycast from [Agent]", category: "Action/Find", id: "e2b3bc47cdb71b5678009c1d431fc68b")]
|
||||
public partial class FindPlayerControllerByRaycastAction : Action
|
||||
{
|
||||
[SerializeReference] public BlackboardVariable<GameObject> Target;
|
||||
[SerializeReference] public BlackboardVariable<GameObject> Agent;
|
||||
[SerializeReference] public BlackboardVariable<float> MaxDistance = new(100);
|
||||
|
||||
protected override Status OnStart()
|
||||
{
|
||||
// setup node
|
||||
// Target.Value = null;
|
||||
|
||||
// check initial values
|
||||
if (Agent.Value == null) return Status.Failure;
|
||||
|
||||
return Status.Running;
|
||||
}
|
||||
|
||||
protected override Status OnUpdate()
|
||||
{
|
||||
if (Physics.Raycast(Agent.Value.transform.position, Agent.Value.transform.forward, out RaycastHit hit,
|
||||
MaxDistance))
|
||||
{
|
||||
if (hit.transform.GetComponent<PlayerController>() != null)
|
||||
{
|
||||
Target.Value = hit.transform.gameObject;
|
||||
return Status.Success;
|
||||
}
|
||||
}
|
||||
|
||||
Target.Value = null;
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
protected override void OnEnd()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user