Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/BehaviorDesigner/Runtime/Tasks/Movement/Search.cs
2026-02-21 16:45:37 +08:00

91 lines
3.0 KiB
C#

using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks.Movement
{
[HelpURLAttribute("http://www.opsive.com/assets/BehaviorDesigner/Movement/documentation.php?id=10")]
[TaskIcon("Assets/Behavior Designer Movement/Editor/Icons/{SkinColor}SearchIcon.png")]
[TaskDescription("Search for a target by combining the wander, within hearing range, and the within seeing range tasks using the Unity NavMesh.")]
[TaskCategory("Movement")]
public class Search : NavMeshMovement
{
[Tooltip("How far ahead of the current position to look ahead for a wander")]
public SharedFloat wanderDistance = 10f;
[Tooltip("The amount that the agent rotates direction")]
public SharedFloat wanderRate = 1f;
[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 = 30f;
[Tooltip("The LayerMask of the objects to ignore when performing the line of sight check")]
public LayerMask ignoreLayerMask = 1 << LayerMask.NameToLayer("Ignore Raycast");
[Tooltip("Should the search end if audio was heard?")]
public SharedBool senseAudio = true;
[Tooltip("How far away the unit can hear")]
public SharedFloat hearingRadius = 30f;
[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 LayerMask of the objects that we are searching for")]
public LayerMask objectLayerMask;
[Tooltip("The further away a sound source is the less likely the agent will be able to hear it. Set a threshold for the the minimum audibility level that the agent can hear")]
public SharedFloat audibilityThreshold = 0.05f;
[Tooltip("The object that is found")]
public SharedGameObject returnedObject;
public override void OnStart()
{
base.OnStart();
SetDestination(Target());
}
public override TaskStatus OnUpdate()
{
SetDestination(Target());
returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, targetOffset.Value, ignoreLayerMask);
if (returnedObject.Value != null)
{
return TaskStatus.Success;
}
if (senseAudio.Value)
{
returnedObject.Value = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, objectLayerMask);
if (returnedObject.Value != null)
{
return TaskStatus.Success;
}
}
return TaskStatus.Running;
}
private Vector3 Target()
{
Vector3 vector = transform.forward + Random.insideUnitSphere * wanderRate.Value;
return transform.position + vector.normalized * wanderDistance.Value;
}
public override void OnReset()
{
base.OnReset();
wanderDistance = 10f;
wanderRate = 1f;
fieldOfViewAngle = 90f;
viewDistance = 30f;
senseAudio = true;
hearingRadius = 30f;
audibilityThreshold = 0.05f;
}
}
}