// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using UnityEngine; namespace UltimateXR.Mechanics.Weapons { public partial class UxrWeaponManager { #region Private Types & Data /// /// Stores information of a projectile currently travelling through the world. /// private class ProjectileInfo { #region Public Types & Data /// /// Gets the that shot the projectile, or deflected it. It will be used know who to attribute /// the damage to. /// public UxrActor WeaponOwner { get; } /// /// Gets the source that shot the projectile. /// public UxrProjectileSource ProjectileSource { get; } /// /// Gets the shot descriptor that was used to shoot the projectile. /// public UxrShotDescriptor ShotDescriptor { get; } /// /// Gets the layer mask, used to determine which objects the shot can collide with. /// public LayerMask ShotLayerMask { get; } /// /// Gets the projectile GameObject instance. /// public GameObject Projectile { get; } /// /// Gets the world-space point the projectile came from. /// public Vector3 ProjectileOrigin { get; } /// /// Gets the current projectile speed in units/second. /// public float ProjectileSpeed { get; } /// /// Gets or sets the projectile's position during the previous frame. /// public Vector3 ProjectileLastPosition { get; set; } /// /// Gets or sets the currently travelled distance. /// public float ProjectileDistanceTravelled { get; set; } /// /// Gets or sets the deflector that deflected the shot or null if there wasn't any. /// public UxrProjectileDeflect ProjectileDeflectSource { get; set; } /// /// Gets or sets whether the current state is the first frame in the shot. /// public bool FirstFrame { get; set; } #endregion #region Constructors & Finalizer /// /// Constructor. /// /// Weapon owner, that fired the shot /// Projectile source component /// Shot descriptor /// World-space position where the shot started /// /// World space orientation where the shot started. The shot will travel in the z (forward) /// position of these axes /// public ProjectileInfo(UxrActor weaponOwner, UxrProjectileSource projectileSource, UxrShotDescriptor shotDescriptor, Vector3 position, Quaternion orientation) { WeaponOwner = weaponOwner; ProjectileSource = projectileSource; ShotDescriptor = shotDescriptor; ShotLayerMask = shotDescriptor.CollisionLayerMask; Projectile = Instantiate(shotDescriptor.ProjectilePrefab, position, orientation); Projectile.transform.parent = null; ProjectileOrigin = position; ProjectileSpeed = shotDescriptor.ProjectileSpeed; ProjectileLastPosition = ProjectileOrigin; ProjectileDistanceTravelled = 0.0f; ProjectileDeflectSource = null; FirstFrame = true; } #endregion #region Public Methods /// /// Adds a value to the layer mask that is used to determine the objects the projectile can collide with. /// /// Value to add to the mask public void AddShotLayerMask(int value) { _shotLayerMask |= value; } #endregion #region Private Types & Data private LayerMask _shotLayerMask; #endregion } #endregion } }