This commit is contained in:
CortexCore
2024-11-03 16:42:23 +08:00
commit b125894cc3
5904 changed files with 1070129 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
using System.Linq;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Conditions
{
[Name("Target In Line Of Sight 2D")]
[Category("GameObject")]
[Description("Check of agent is in line of sight with target by doing a linecast and optionaly save the distance")]
public class CheckLOS2D : ConditionTask<Transform>
{
[RequiredField]
public BBParameter<GameObject> LOSTarget;
public BBParameter<LayerMask> layerMask = (LayerMask)( -1 );
[BlackboardOnly]
public BBParameter<float> saveDistanceAs;
[GetFromAgent]
protected Collider2D agentCollider;
private RaycastHit2D[] hits;
protected override string info {
get { return "LOS with " + LOSTarget.ToString(); }
}
protected override bool OnCheck() {
hits = Physics2D.LinecastAll(agent.position, LOSTarget.value.transform.position, layerMask.value);
foreach ( var collider in hits.Select(h => h.collider) ) {
if ( collider != agentCollider && collider != LOSTarget.value.GetComponent<Collider2D>() ) {
return false;
}
}
return true;
}
public override void OnDrawGizmosSelected() {
if ( agent && LOSTarget.value ) {
Gizmos.DrawLine((Vector2)agent.position, (Vector2)LOSTarget.value.transform.position);
}
}
}
}