// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using System;
using UnityEngine;
namespace UltimateXR.Mechanics.Weapons
{
///
/// Class describing all the information of a type of projectile that a GameObject having a
/// component can shoot.
/// Normally there will be a with a component
/// supporting one or more .
/// For example, a rifle with a grenade launcher attachment will be able to fire two types of projectiles: bullets and
/// explosive grenades.
/// components, however, do not require to be part of a
/// and can be used on their own.
///
[Serializable]
public class UxrShotDescriptor
{
#region Inspector Properties/Serialized Fields
[SerializeField] private Transform _shotSource;
[SerializeField] private Transform _tip;
[SerializeField] private bool _useAutomaticProjectileTrajectory = true;
[SerializeField] private string _shotAnimationVarName;
[SerializeField] private GameObject _prefabInstantiateOnTipWhenShot;
[SerializeField] private float _prefabInstantiateOnTipLife = 5.0f;
[SerializeField] private bool _prefabInstantiateOnTipParent = true;
[SerializeField] private GameObject _projectilePrefab;
[SerializeField] private float _projectileSpeed = 30.0f;
[SerializeField] private float _projectileMaxDistance = 300.0f;
[SerializeField] private float _projectileLength = 0.01f;
[SerializeField] private float _projectileDamageNear = 20.0f;
[SerializeField] private float _projectileDamageFar = 20.0f;
[SerializeField] private float _projectileImpactForceMultiplier = 1.0f;
[SerializeField] private LayerMask _collisionLayerMask = -1;
[SerializeField] private GameObject _prefabInstantiateOnImpact;
[SerializeField] private float _prefabInstantiateOnImpactLife = 5.0f;
[SerializeField] private UxrImpactDecal _prefabScenarioImpactDecal;
[SerializeField] private float _prefabScenarioImpactDecalLife = 10.0f;
[SerializeField] private float _decalFadeoutDuration = 7.0f;
[SerializeField] private LayerMask _createDecalLayerMask = -1;
#endregion
#region Public Types & Data
///
/// Gets the that is used to fire projectiles from, using the forward vector as direction.
///
public Transform ShotSource => _shotSource;
///
/// Gets the that is used to instantiate effects on the tip when a shot was fired, using
/// .
///
public Transform Tip => _tip;
///
/// Gets whether the projectiles fired should be updated automatically to compute their trajectory or they will be
/// updated manually.
///
public bool UseAutomaticProjectileTrajectory => _useAutomaticProjectileTrajectory;
///
/// Optional trigger variable name that will be triggered on the weapon each time a round is
/// fired.
///
public string ShotAnimationVarName => _shotAnimationVarName;
///
/// An optional prefab that will be instantiated on the each time a round is fired.
///
public GameObject PrefabInstantiateOnTipWhenShot => _prefabInstantiateOnTipWhenShot;
///
/// Life in seconds of after which it will be destroyed.
///
public float PrefabInstantiateOnTipLife => _prefabInstantiateOnTipLife;
///
/// Whether will be parented to the after being
/// instantiated or will remain unparented.
///
public bool PrefabInstantiateOnTipParent => _prefabInstantiateOnTipParent;
///
/// Prefab that will be instantiated as the projectile.
///
public GameObject ProjectilePrefab => _projectilePrefab;
///
/// Speed at which the projectile will move.
///
public float ProjectileSpeed => _projectileSpeed;
///
/// Maximum reach of the projectile, after which it will be destroyed.
///
public float ProjectileMaxDistance => _projectileMaxDistance;
///
/// The physical length of the projectile, used in ray-casting computations.
///
public float ProjectileLength => _projectileLength;
///
/// The damage a projectile will do if it were to hit at the closest distance. Damage will linearly decrease over
/// distance down to until the projectile reaches
/// .
///
public float ProjectileDamageNear => _projectileDamageNear;
///
/// The damage a projectile will do if it were to hit at the farthest distance. Damage will linearly decrease over
/// distance from the start down to until the projectile reaches
/// .
///
public float ProjectileDamageFar => _projectileDamageFar;
///
/// The force multiplier applied to a rigidbody that was hit by a projectile. The total force applied will be speed *
/// ForceMultiplier.
///
public float ProjectileImpactForceMultiplier => _projectileImpactForceMultiplier;
///
/// The layer mask used to determine which objects can be hit.
///
public LayerMask CollisionLayerMask => _collisionLayerMask;
///
/// An optional prefab to instantiate at the point of impact.
///
public GameObject PrefabInstantiateOnImpact => _prefabInstantiateOnImpact;
///
/// Life in seconds after which will be destroyed.
///
public float PrefabInstantiateOnImpactLife => _prefabInstantiateOnImpactLife;
///
/// Default decal that will be used when the projectile impacted with something. Can be overriden using the
/// component.
///
public UxrImpactDecal PrefabScenarioImpactDecal => _prefabScenarioImpactDecal;
///
/// Life in seconds after which will fadeout and be destroyed.
///
public float PrefabScenarioImpactDecalLife => _prefabScenarioImpactDecalLife;
///
/// Duration of the fadeout effect before a is destroyed.
///
public float DecalFadeoutDuration => _decalFadeoutDuration;
///
/// The layer mask used to determine if an impact will generate a decal.
///
public LayerMask CreateDecalLayerMask => _createDecalLayerMask;
#endregion
}
}