// Copyright (C) 2023 Nicholas Maltbie
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using UnityEngine;
namespace nickmaltbie.OpenKCC.Utils.ColliderCast
{
///
/// This class is only meant for testing, no reason to include in code coverage metrics.
///
[ExcludeFromCodeCoverage]
public class MockColliderCast : MonoBehaviour, IColliderCast
{
///
/// Callback function for
///
/// Source point to check from.
/// Direction to search for step.
/// Distance to search for step ahead of player.
/// Information about hit.
/// Layer mask for checking which objects to collide with.
/// Configuration for QueryTriggerInteraction when solving for collisions.
/// Buffer around player when casting object.
/// Is something ahead hit.
public delegate void DoRaycastInDirectionCallback(Vector3 source, Vector3 direction, float distance, out IRaycastHit hit, int layerMask, QueryTriggerInteraction queryTriggerInteraction, float skinWidth);
///
/// Callback function for
///
/// Source point to check from.
/// Direction to search for step.
/// Distance to search for step ahead of player.
/// Information about hit.
/// Layer mask for checking which objects to collide with.
/// Configuration for QueryTriggerInteraction when solving for collisions.
/// Is something ahead hit.
public delegate bool DoRaycastInDirectionReturns(Vector3 source, Vector3 direction, float distance, out IRaycastHit hit, int layerMask, QueryTriggerInteraction queryTriggerInteraction);
///
/// Callback function for
///
/// Position of the object when it is being raycast.
/// Rotation of the objecting when it is being raycast.
/// Direction of the raycast.
/// Maximum distance of raycast.
/// First object hit and related information, will have a distance of Infinity if none
/// is found.
/// Width of skin of object to use when casting a hit. Essentially buffer
/// space around the edge of the object.
/// True if an object is hit within distance, false otherwise.
public delegate void CastSelfCallback(Vector3 position, Quaternion rotation, Vector3 direction, float distance, out IRaycastHit hit, int layerMask, QueryTriggerInteraction queryTriggerInteraction, float skinWidth);
///
/// Callback function for
///
/// Position of the object when it is being raycast.
/// Rotation of the objecting when it is being raycast.
/// Direction of the raycast.
/// Maximum distance of raycast.
/// First object hit and related information, will have a distance of Infinity if none
/// is found.
/// Buffer around player when casting object.
/// True if an object is hit within distance, false otherwise.
public delegate bool CastSelfReturns(Vector3 position, Quaternion rotation, Vector3 direction, float distance, out IRaycastHit hit, int layerMask, QueryTriggerInteraction queryTriggerInteraction, float skinWidth);
public delegate Vector3 PushOutOverlappingReturns(Vector3 position, Quaternion rotation, float maxDistance, int layerMask = -1, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Ignore, float skinWidth = 0.0f);
public delegate IEnumerable GetOverlappingReturns(Vector3 position, Quaternion rotation, int layerMask = -1, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Ignore, float skinWidth = 0.0f);
public delegate IEnumerable GetHitsReturns(Vector3 position, Quaternion rotation, Vector3 direction, float distance, int layerMask = -1, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Ignore, float skinWidth = 0.01f);
public delegate Vector3 GetBottomReturns(Vector3 position, Quaternion rotation);
public CastSelfReturns OnCastSelf;
public DoRaycastInDirectionReturns OnDoRaycastInDirection;
public GetBottomReturns OnGetBottom;
public GetHitsReturns OnGetHits;
public GetOverlappingReturns OnGetOverlapping;
public PushOutOverlappingReturns OnPushOutOverlapping;
public bool CastSelf(Vector3 position, Quaternion rotation, Vector3 direction, float distance, out IRaycastHit hit, int layerMask = -1, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Ignore, float skinWidth = 0.01f)
{
hit = default;
return OnCastSelf?.Invoke(position, rotation, direction, distance, out hit, layerMask, queryTriggerInteraction, skinWidth) ?? false;
}
public bool DoRaycastInDirection(Vector3 source, Vector3 direction, float distance, out IRaycastHit stepHit, int layerMask = -1, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Ignore)
{
stepHit = default;
return OnDoRaycastInDirection?.Invoke(source, direction, distance, out stepHit, layerMask, queryTriggerInteraction) ?? false;
}
public Vector3 GetBottom(Vector3 position, Quaternion rotation)
{
return OnGetBottom?.Invoke(position, rotation) ?? Vector3.zero;
}
public IEnumerable GetHits(Vector3 position, Quaternion rotation, Vector3 direction, float distance, int layerMask = -1, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Ignore, float skinWidth = 0.01f)
{
return OnGetHits?.Invoke(position, rotation, direction, distance, layerMask, queryTriggerInteraction, skinWidth);
}
public IEnumerable GetOverlapping(Vector3 position, Quaternion rotation, int layerMask = -1, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Ignore, float skinWidth = 0.0f)
{
return OnGetOverlapping?.Invoke(position, rotation, layerMask, queryTriggerInteraction, skinWidth);
}
public Vector3 PushOutOverlapping(Vector3 position, Quaternion rotation, float maxDistance, int layerMask = -1, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Ignore, float skinWidth = 0.0f)
{
return OnPushOutOverlapping?.Invoke(position, rotation, maxDistance, layerMask, queryTriggerInteraction, skinWidth) ?? Vector3.zero;
}
}
}