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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a08b2b3e631346b2b155982df199f9a
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable, Unity.Properties.GeneratePropertyBag]
|
||||
[Condition(name: "GameObject is Null", story: "[Object] is [IsNull] null", category: "Variable Conditions", id: "9be617c0444353affee2f412e94ae715")]
|
||||
public partial class GameObjectNullCondition : Condition
|
||||
{
|
||||
[SerializeReference] public BlackboardVariable<GameObject> Object;
|
||||
[SerializeReference] public BlackboardVariable<bool> IsNull;
|
||||
|
||||
public override bool IsTrue()
|
||||
{
|
||||
return (Object.Value == null && IsNull) || (Object.Value != null && !IsNull);
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 534847d817af848138303989d8adde9b
|
||||
Reference in New Issue
Block a user