Bullet Dynamics v1.0.0
Loading...
Searching...
No Matches
BulletDynamics.Weapons.WeaponMagazine Class Reference


Component that works with Weapon to set it's Weapon.IsShootingEnabled flag to false when the magazine is empty.
Support reloading with Reload method. More...

Public Member Functions

virtual void Reload (float reloadDuration)
 
Sets the Weapon.IsShootingEnabled to false, and calls Reload after reloadDuration .
It will raise ReloadStarted event.
ReloadFinished event is raised after the reload has finished.
 
virtual void Reload ()
 
Resets the bullet count to the magazine size.
It will raise ReloadFinished event.
This method does not raise ReloadStarted event since the reload is instant.
 
virtual void CancelReload ()
 Canceles the reload, activates the weapon shooting, and raises ReloadCanceled event.
 
virtual void SetNumberOfBulletsInMagazine (int numberOfBullets)
 Sets the current number of bullets inside the magazine.
 

Public Attributes

UnityEvent< int > BulletCountChanged
 Event that is raised when the bullet count changes in this WeaponMagazine.
 
UnityEvent ReloadStarted
 Event that is raised when the reload starts.
 
UnityEvent ReloadFinished
 Event that is raised when the reload finished.
 
UnityEvent ReloadCanceled
 Event that is raised when the reload was canceled.
 

Protected Member Functions

virtual void Awake ()
 
virtual void Start ()
 
virtual void OnEnable ()
 
virtual void OnDisable ()
 
virtual IEnumerator ReloadCoroutine (float duration)
 Coroutine that delays the ability to shoot by setting _fireRateDelayActive to false until the _fireRate delay doesn't pass.
 
virtual void OnWeaponShoot (Bullet firedBullet)
 
Handler for the Weapon.OnShoot event.
It will reduce the number of bullets inside the magazine by 1.
 
void StartReloadCoroutine (float duration)
 Starts the ReloadCoroutine in a safe way (by stopping current coroutine).
 
void StopReloadCoroutine ()
 Stops the ReloadCoroutine.
 

Protected Attributes

Weapon _weapon
 
Coroutine _reloadCoroutine
 

Properties

int MagazineSize [get]
 Returns the amount of bullets this magazine can hold.
 
int BulletsInMagazine [get]
 Returns the current amount of bullets inside this magazine.
 

Detailed Description


Component that works with Weapon to set it's Weapon.IsShootingEnabled flag to false when the magazine is empty.
Support reloading with Reload method.

Definition at line 13 of file WeaponMagazine.cs.

Member Function Documentation

◆ Awake()

virtual void BulletDynamics.Weapons.WeaponMagazine.Awake ( )
protectedvirtual

Definition at line 48 of file WeaponMagazine.cs.

◆ CancelReload()

virtual void BulletDynamics.Weapons.WeaponMagazine.CancelReload ( )
virtual

Canceles the reload, activates the weapon shooting, and raises ReloadCanceled event.

Definition at line 95 of file WeaponMagazine.cs.

◆ OnDisable()

virtual void BulletDynamics.Weapons.WeaponMagazine.OnDisable ( )
protectedvirtual

Definition at line 63 of file WeaponMagazine.cs.

◆ OnEnable()

virtual void BulletDynamics.Weapons.WeaponMagazine.OnEnable ( )
protectedvirtual

Definition at line 58 of file WeaponMagazine.cs.

◆ OnWeaponShoot()

virtual void BulletDynamics.Weapons.WeaponMagazine.OnWeaponShoot ( Bullet firedBullet)
protectedvirtual


Handler for the Weapon.OnShoot event.
It will reduce the number of bullets inside the magazine by 1.

Definition at line 130 of file WeaponMagazine.cs.

◆ Reload() [1/2]

virtual void BulletDynamics.Weapons.WeaponMagazine.Reload ( )
virtual


Resets the bullet count to the magazine size.
It will raise ReloadFinished event.
This method does not raise ReloadStarted event since the reload is instant.

Definition at line 86 of file WeaponMagazine.cs.

◆ Reload() [2/2]

virtual void BulletDynamics.Weapons.WeaponMagazine.Reload ( float reloadDuration)
virtual


Sets the Weapon.IsShootingEnabled to false, and calls Reload after reloadDuration .
It will raise ReloadStarted event.
ReloadFinished event is raised after the reload has finished.

Parameters
reloadDurationDelay between this call and the actual reload of the magazine.

Definition at line 75 of file WeaponMagazine.cs.

◆ ReloadCoroutine()

virtual IEnumerator BulletDynamics.Weapons.WeaponMagazine.ReloadCoroutine ( float duration)
protectedvirtual

Coroutine that delays the ability to shoot by setting _fireRateDelayActive to false until the _fireRate delay doesn't pass.

Returns

Definition at line 117 of file WeaponMagazine.cs.

◆ SetNumberOfBulletsInMagazine()

virtual void BulletDynamics.Weapons.WeaponMagazine.SetNumberOfBulletsInMagazine ( int numberOfBullets)
virtual

Sets the current number of bullets inside the magazine.

Parameters
numberOfBulletsNumber of bullets that will be inside the magazine.

Definition at line 106 of file WeaponMagazine.cs.

◆ Start()

virtual void BulletDynamics.Weapons.WeaponMagazine.Start ( )
protectedvirtual

Definition at line 53 of file WeaponMagazine.cs.

◆ StartReloadCoroutine()

void BulletDynamics.Weapons.WeaponMagazine.StartReloadCoroutine ( float duration)
protected

Starts the ReloadCoroutine in a safe way (by stopping current coroutine).

Definition at line 139 of file WeaponMagazine.cs.

◆ StopReloadCoroutine()

void BulletDynamics.Weapons.WeaponMagazine.StopReloadCoroutine ( )
protected

Stops the ReloadCoroutine.

Definition at line 148 of file WeaponMagazine.cs.

Member Data Documentation

◆ _reloadCoroutine

Coroutine BulletDynamics.Weapons.WeaponMagazine._reloadCoroutine
protected

Definition at line 19 of file WeaponMagazine.cs.

◆ _weapon

Weapon BulletDynamics.Weapons.WeaponMagazine._weapon
protected

Definition at line 17 of file WeaponMagazine.cs.

◆ BulletCountChanged

UnityEvent<int> BulletDynamics.Weapons.WeaponMagazine.BulletCountChanged

Event that is raised when the bullet count changes in this WeaponMagazine.

Definition at line 34 of file WeaponMagazine.cs.

◆ ReloadCanceled

UnityEvent BulletDynamics.Weapons.WeaponMagazine.ReloadCanceled

Event that is raised when the reload was canceled.

Definition at line 46 of file WeaponMagazine.cs.

◆ ReloadFinished

UnityEvent BulletDynamics.Weapons.WeaponMagazine.ReloadFinished

Event that is raised when the reload finished.

Definition at line 42 of file WeaponMagazine.cs.

◆ ReloadStarted

UnityEvent BulletDynamics.Weapons.WeaponMagazine.ReloadStarted

Event that is raised when the reload starts.

Definition at line 38 of file WeaponMagazine.cs.

Property Documentation

◆ BulletsInMagazine

int BulletDynamics.Weapons.WeaponMagazine.BulletsInMagazine
get

Returns the current amount of bullets inside this magazine.

Definition at line 29 of file WeaponMagazine.cs.

◆ MagazineSize

int BulletDynamics.Weapons.WeaponMagazine.MagazineSize
get

Returns the amount of bullets this magazine can hold.

Definition at line 24 of file WeaponMagazine.cs.