Advertisement
CassataGames

Untitled

Feb 27th, 2022
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using Sirenix.OdinInspector;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5.  
  6. [System.Serializable]
  7. [HideLabel]
  8. public class GunClip
  9. {
  10.     internal int CurrentAmmo = 0;
  11.     internal int MaxAmmo = 3;
  12.    
  13.     private float _currentReloadTime;
  14.     private float _currentDelayTime;
  15.     private bool _weaponLoading;
  16.     private bool _weaponLocked;
  17.     [SuffixLabel("Second(s)", Overlay = true), ShowInInspector] public float maxReloadTime;
  18.     [SuffixLabel("Second(s)", Overlay = true), ShowInInspector] public float maxDelayTime;
  19.  
  20.     public Dictionary<string, Vector2> ClipUI_Info()
  21.     {
  22.         var ammoUI = new Vector2(CurrentAmmo, MaxAmmo);
  23.         var reloadUI = new Vector2(_currentReloadTime, maxReloadTime);
  24.         var delayUI = new Vector2(_currentDelayTime, maxDelayTime);
  25.         var clipInfo = new Dictionary<string, Vector2> {{"ammo", ammoUI}, {"reload", reloadUI}, {"delay", delayUI}};
  26.         return
  27.             clipInfo;
  28.     }
  29.  
  30.     internal bool WeaponLocked()
  31.     {
  32.         return _weaponLocked;
  33.     }
  34.     internal void InternalUpdate()
  35.     {
  36.         CountUp();
  37.         if (CurrentAmmo < MaxAmmo && !_weaponLoading)
  38.             StartReload();
  39.         if (_currentReloadTime >= maxReloadTime)
  40.             FinishReload();
  41.        
  42.         _weaponLoading = _currentReloadTime <= maxReloadTime;
  43.         _weaponLocked = _currentDelayTime <= maxDelayTime;
  44.     }
  45.    
  46.     internal void StartDelay()
  47.     {
  48.         _currentDelayTime = 0;
  49.     }
  50.  
  51.     private void CountUp()
  52.     {
  53.         if (_currentReloadTime < maxReloadTime)
  54.             _currentReloadTime += Time.fixedDeltaTime;
  55.         if (_currentDelayTime < maxDelayTime)
  56.             _currentDelayTime += Time.fixedDeltaTime;
  57.     }
  58.  
  59.     private void StartReload()
  60.     {
  61.         _currentReloadTime = 0;
  62.     }
  63.  
  64.     private void FinishReload()
  65.     {
  66.         CurrentAmmo = MaxAmmo;
  67.         _weaponLoading = false;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement