49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using NodeCanvas.BehaviourTrees;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
using NodeCanvas.Tasks.Actions;
|
|
using BITKit;
|
|
using System.Linq;
|
|
using BITKit.Entities;
|
|
using BITKit.Sensors;
|
|
using Cysharp.Threading.Tasks;
|
|
namespace BITKit.Nodes
|
|
{
|
|
public class GetTargetsBySensor : ConditionTask<Sensors.Sensor>
|
|
{
|
|
[BlackboardOnly]
|
|
public BBParameter<List<Transform>> targets;
|
|
[BlackboardOnly]
|
|
public BBParameter<Transform> closerTarget;
|
|
[BlackboardOnly]
|
|
public BBParameter<bool> targetIsValid;
|
|
List<Transform> cacheList = new();
|
|
bool isValid;
|
|
IEnumerable<Transform> detecteds;
|
|
EntityHealth entityHealth;
|
|
protected override bool OnCheck()
|
|
{
|
|
agent.Excute();
|
|
cacheList.Clear();
|
|
foreach (var target in agent.Get())
|
|
{
|
|
if (target.TryGetComponent<EntityHealth>(out entityHealth))
|
|
{
|
|
if (entityHealth.healthPoint >= 0)
|
|
{
|
|
cacheList.Add(target);
|
|
}
|
|
}
|
|
}
|
|
isValid = cacheList.Count > 0;
|
|
closerTarget.SetValue(isValid ? cacheList.First() : null);
|
|
targets.SetValue(cacheList);
|
|
if (targetIsValid.isDefined)
|
|
targetIsValid.SetValue(isValid);
|
|
return isValid;
|
|
}
|
|
}
|
|
} |