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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 050a9dc7e793c41e8b67a8485bdc6755
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Unity.Behavior;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable, Unity.Properties.GeneratePropertyBag]
|
||||
[Condition(name: "GameObject Null", story: "[Target] [is] null", category: "Conditions", id: "6bc7c2e1cf9d2d4a14b5c3ac1b47da1d")]
|
||||
public partial class GameObjectNullCondition : Condition
|
||||
{
|
||||
[SerializeReference] public BlackboardVariable<GameObject> Target;
|
||||
[Comparison(comparisonType: ComparisonType.Boolean)]
|
||||
[SerializeReference] public BlackboardVariable<ConditionOperator> Is;
|
||||
|
||||
public override bool IsTrue()
|
||||
{
|
||||
if (Target.Value == null && Is.Value == ConditionOperator.Equal) return true;
|
||||
if (Target.Value != null && Is.Value == ConditionOperator.NotEqual) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2de8640b1b5a34a6aa6e88a233a1f2dc
|
||||
Reference in New Issue
Block a user