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 { [BlackboardOnly] public BBParameter> targets; [BlackboardOnly] public BBParameter closerTarget; [BlackboardOnly] public BBParameter targetIsValid; List cacheList = new(); bool isValid; IEnumerable detecteds; EntityHealth entityHealth; protected override bool OnCheck() { agent.Excute(); cacheList.Clear(); foreach (var target in agent.Get()) { if (target.TryGetComponent(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; } } }