Skip to content

Commit

Permalink
feat(Cast): add raycast hit validity rule for points cast
Browse files Browse the repository at this point in the history
The PointsCast now has a RaycastHitValidity rule that will allow
any data within the cast RaycastHit to be used within a rule for
any custom.
  • Loading branch information
thestonefox committed Apr 17, 2024
1 parent f90f1e8 commit 170a241
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions Runtime/Cast/PointsCast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ public RuleContainer TargetPointValidity
targetPointValidity = value;
}
}
[Tooltip("Allows to optionally determine if the raycast hit of the cast is valud based on the set rules.")]
[SerializeField]
private RuleContainer raycastHitValidity;
/// <summary>
/// Allows to optionally determine if the raycast hit of the cast is valud based on the set rules.
/// </summary>
public RuleContainer RaycastHitValidity
{
get
{
return raycastHitValidity;
}
set
{
raycastHitValidity = value;
}
}
[Tooltip("The amount of distance the cursor has to move before the destination of the cursor is updated to a new position.")]
[SerializeField]
private float cursorLockThreshold;
Expand Down Expand Up @@ -227,7 +244,7 @@ public float TransitionDuration
public UnityEvent ResultsChanged = new UnityEvent();

/// <summary>
/// The result of the most recent cast. <see langword="null"/> when the cast didn't hit anything or an invalid target according to <see cref="TargetValidity"/> or <see cref="TargetPointValidity"/> rules.
/// The result of the most recent cast. <see langword="null"/> when the cast didn't hit anything or an invalid target according to <see cref="TargetValidity"/> or <see cref="TargetPointValidity"/> or <see cref="RaycastHitValidity"/> rules.
/// </summary>
private RaycastHit? targetHit;
public RaycastHit? TargetHit
Expand All @@ -246,7 +263,7 @@ protected set
}
}
/// <summary>
/// Whether the current <see cref="TargetHit"/> is valid based on the <see cref="TargetValidity"/> and <see cref="TargetPointValidity"/> rules.
/// Whether the current <see cref="TargetHit"/> is valid based on the <see cref="TargetValidity"/> and <see cref="TargetPointValidity"/> and <see cref="RaycastHitValidity"/> rules.
/// </summary>
public bool IsTargetHitValid { get; protected set; }
/// <summary>
Expand Down Expand Up @@ -323,6 +340,19 @@ public virtual void ClearTargetPointValidity()
TargetPointValidity = default;
}

/// <summary>
/// Clears <see cref="RaycastHitValidity"/>.
/// </summary>
public virtual void ClearRaycastHitValidity()
{
if (!this.IsValidState())
{
return;
}

RaycastHitValidity = default;
}

/// <summary>
/// Clears the <see cref="DestinationPointOverride"/>.
/// </summary>
Expand Down Expand Up @@ -414,7 +444,7 @@ protected virtual RaycastHit GetActualTargetHit(RaycastHit actualHitData, bool h
/// </summary>
protected virtual void OnAfterTargetHitChange()
{
IsTargetHitValid = TargetHit != null && TargetValidity.Accepts(TargetHit.Value.transform.gameObject) && TargetPointValidity.Accepts(TargetHit.Value.point);
IsTargetHitValid = TargetHit != null && TargetValidity.Accepts(TargetHit.Value.transform.gameObject) && TargetPointValidity.Accepts(TargetHit.Value.point) && RaycastHitValidity.Accepts(TargetHit);
}
}
}

0 comments on commit 170a241

Please sign in to comment.