// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using UltimateXR.Core;
using UltimateXR.Core.Components;
using UltimateXR.Extensions.Unity.Math;
using UnityEngine;
namespace UltimateXR.Avatar.Controllers
{
///
/// Component that describes a box volume where any hand that gets inside automatically adopts
/// a finger pointing pose. This is useful to place in front of UI screens or where precise finger pressing interaction
/// is required.
///
///
/// The finger pointing pose should only be adopted if it doesn't interfere with any other interaction, such
/// as the grab pose while grabbing an object inside the volume.
///
[RequireComponent(typeof(BoxCollider))]
public class UxrFingerPointingVolume : UxrComponent
{
#region Inspector Properties/Serialized Fields
[SerializeField] private bool _leftHand = true;
[SerializeField] private bool _rightHand = true;
#endregion
#region Public Types & Data
///
/// Gets the component describing the enclosed space where to adopt the finger pointing
/// pose.
///
public BoxCollider Box => GetCachedComponent();
///
/// Gets or sets whether the left hand should adopt the pose when inside.
///
public bool UseLeftHand
{
get => _leftHand;
set => _leftHand = value;
}
///
/// Gets or sets whether the right hand should adopt the pose when inside.
///
public bool UseRightHand
{
get => _rightHand;
set => _rightHand = value;
}
#endregion
#region Public Methods
///
/// Checks if a point is inside the attached to the this component
/// is attached to.
///
/// Point in world coordinates
/// Margin to add to the box sides
/// True if it is inside, false if not
public bool IsPointInside(Vector3 point, float margin = 0.0f)
{
return point.IsInsideBox(Box, Vector3.one * margin);
}
///
/// Checks if the volume is compatible with the given hand. This allows some volumes to work for the left or
/// right hand only.
///
/// Hand to check
/// Boolean telling whether the given hand is compatible or not
public bool IsCompatible(UxrHandSide handSide)
{
return (handSide == UxrHandSide.Left && UseLeftHand) || (handSide == UxrHandSide.Right && UseRightHand);
}
#endregion
}
}