// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using System;
using UltimateXR.Audio;
using UltimateXR.Core.Math;
using UltimateXR.Haptics;
using UltimateXR.Manipulation;
using UnityEngine;
namespace UltimateXR.Mechanics.Weapons
{
///
/// Stores all the information related to a trigger in a . The projectile that will be
/// shot is described by a separate . determines
/// which in a will be shot. It usually is 0, but
/// can be higher if the projectile source supports multiple shot types.
///
[Serializable]
internal class UxrFirearmTrigger
{
#region Inspector Properties/Serialized Fields
[SerializeField] private int _projectileShotIndex;
[SerializeField] private UxrShotCycle _cycleType;
[SerializeField] private int _maxShotFrequency;
[SerializeField] private UxrAudioSample _shotAudio;
[SerializeField] private UxrAudioSample _shotAudioNoAmmo;
[SerializeField] private UxrHapticClip _shotHapticClip = new UxrHapticClip(null, UxrHapticClipType.Shot);
[SerializeField] private UxrGrabbableObject _triggerGrabbable;
[SerializeField] private int _grabbableGrabPointIndex;
[SerializeField] private Transform _triggerTransform;
[SerializeField] private UxrAxis _triggerRotationAxis = UxrAxis.X;
[SerializeField] private float _triggerRotationDegrees = 40.0f;
[SerializeField] private UxrGrabbableObjectAnchor _ammunitionMagAnchor;
[SerializeField] private float _recoilAngleOneHand = 0.5f;
[SerializeField] private float _recoilAngleTwoHands = 2.0f;
[SerializeField] private Vector3 _recoilOffsetOneHand = -Vector3.forward * 0.03f;
[SerializeField] private Vector3 _recoilOffsetTwoHands = -Vector3.forward * 0.01f;
[SerializeField] private float _recoilDurationSeconds;
#endregion
#region Public Types & Data
///
/// Gets the index in the component of the shot fired whenever the triggers is
/// pressed.
///
public int ProjectileShotIndex => _projectileShotIndex;
///
/// Gets the shot cycle type.
///
public UxrShotCycle CycleType => _cycleType;
///
/// Gets the maximum shooting frequency.
///
public int MaxShotFrequency => _maxShotFrequency;
///
/// Gets the audio played when the user pulls the trigger and the weapon shoots.
///
public UxrAudioSample ShotAudio => _shotAudio;
///
/// Gets the audio played when the user pulls the trigger and the weapon isn't loaded.
///
public UxrAudioSample ShotAudioNoAmmo => _shotAudioNoAmmo;
///
/// Gets the haptic feedback sent whenever the weapon shoots.
///
public UxrHapticClip ShotHapticClip => _shotHapticClip;
///
/// Gets the object that is required to grab in order to access the trigger.
///
public UxrGrabbableObject TriggerGrabbable => _triggerGrabbable;
///
/// Gets the index point for .
///
public int GrabbableGrabPointIndex => _grabbableGrabPointIndex;
///
/// Gets the transform that will rotate when the trigger is pressed.
///
public Transform TriggerTransform => _triggerTransform;
///
/// Gets the trigger rotation axis.
///
public UxrAxis TriggerRotationAxis => _triggerRotationAxis;
///
/// Gets the amount of degrees that the trigger will rotate when it is fully pressed.
///
public float TriggerRotationDegrees => _triggerRotationDegrees;
///
/// Gets the anchor where mags for ammo that will be shot using the trigger will be attached to.
///
public UxrGrabbableObjectAnchor AmmunitionMagAnchor => _ammunitionMagAnchor;
///
/// Recoil rotation in degrees when a single hand is grabbing the weapon.
///
public float RecoilAngleOneHand => _recoilAngleOneHand;
///
/// Recoil rotation in degrees when two hands are grabbing the weapon.
///
public float RecoilAngleTwoHands => _recoilAngleTwoHands;
///
/// Recoil offset when a single hand is grabbing the weapon.
///
public Vector3 RecoilOffsetOneHand => _recoilOffsetOneHand;
///
/// Recoil offset when two hands are grabbing the weapon.
///
public Vector3 RecoilOffsetTwoHands => _recoilOffsetTwoHands;
///
/// Recoil animation duration in seconds. The animation will be procedurally applied to the weapon.
///
public float RecoilDurationSeconds => _recoilDurationSeconds;
#endregion
}
}