79 lines
2.7 KiB
C#
79 lines
2.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace BehaviorDesigner.Runtime.Tasks.Movement
|
|
{
|
|
[HelpURLAttribute("http://www.opsive.com/assets/BehaviorDesigner/Movement/documentation.php?id=11")]
|
|
[TaskIcon("Assets/Behavior Designer Movement/Editor/Icons/{SkinColor}CanSeeObjectIcon.png")]
|
|
[TaskCategory("Movement")]
|
|
[TaskDescription("Check to see if the any objects are within sight of the agent.")]
|
|
public class CanSeeObject : Conditional
|
|
{
|
|
[Tooltip("Should the 2D version be used?")]
|
|
public bool usePhysics2D;
|
|
|
|
[Tooltip("The object that we are searching for. If this value is null then the objectLayerMask will be used")]
|
|
public SharedGameObject targetObject;
|
|
|
|
[Tooltip("The LayerMask of the objects that we are searching for")]
|
|
public LayerMask objectLayerMask;
|
|
|
|
[Tooltip("The LayerMask of the objects to ignore when performing the line of sight check")]
|
|
public LayerMask ignoreLayerMask = 1 << LayerMask.NameToLayer("Ignore Raycast");
|
|
|
|
[Tooltip("The field of view angle of the agent (in degrees)")]
|
|
public SharedFloat fieldOfViewAngle = 90f;
|
|
|
|
[Tooltip("The distance that the agent can see")]
|
|
public SharedFloat viewDistance = 1000f;
|
|
|
|
[Tooltip("The offset relative to the pivot position")]
|
|
public SharedVector3 offset;
|
|
|
|
[Tooltip("The target offset relative to the pivot position")]
|
|
public SharedVector3 targetOffset;
|
|
|
|
[Tooltip("The object that is within sight")]
|
|
public SharedGameObject returnedObject;
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (usePhysics2D)
|
|
{
|
|
if (targetObject.Value == null)
|
|
{
|
|
returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, targetOffset.Value, ignoreLayerMask);
|
|
}
|
|
else
|
|
{
|
|
returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value, targetOffset.Value, ignoreLayerMask);
|
|
}
|
|
}
|
|
else if (targetObject.Value == null)
|
|
{
|
|
returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, targetOffset.Value, ignoreLayerMask);
|
|
}
|
|
else
|
|
{
|
|
returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value, targetOffset.Value, ignoreLayerMask);
|
|
}
|
|
if (returnedObject.Value != null)
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
public override void OnReset()
|
|
{
|
|
fieldOfViewAngle = 90f;
|
|
viewDistance = 1000f;
|
|
offset = Vector3.zero;
|
|
}
|
|
|
|
public override void OnDrawGizmos()
|
|
{
|
|
MovementUtility.DrawLineOfSight(base.Owner.transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, usePhysics2D);
|
|
}
|
|
}
|
|
}
|