61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AmmoScreenView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image TorpedoReloadBar;
|
|
[SerializeField] private Image MissileReloadBar;
|
|
[SerializeField] private float FillMaxSpeed = 10;
|
|
|
|
[SerializeField] private TextMeshProUGUI TorpedoAmmoLabel;
|
|
[SerializeField] private TextMeshProUGUI MissileAmmoLabel;
|
|
[SerializeField] private GameObject TorpedoPointer;
|
|
[SerializeField] private GameObject MissilePointer;
|
|
|
|
WeaponModel model;
|
|
|
|
public void Initialize(WeaponModel weaponModel)
|
|
{
|
|
model = weaponModel;
|
|
weaponModel.OnUpdate += Refresh;
|
|
Refresh(G.WeaponModel);
|
|
}
|
|
|
|
private void Refresh(WeaponModel model)
|
|
{
|
|
TorpedoAmmoLabel.text = model.Weapons[0].Ammo.ToString();
|
|
MissileAmmoLabel.text = model.Weapons[1].Ammo.ToString();
|
|
|
|
if (model.CurrentWeapon == model.Weapons[0])
|
|
{
|
|
TorpedoPointer.SetActive(true);
|
|
MissilePointer.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
TorpedoPointer.SetActive(false);
|
|
MissilePointer.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (model == null) return;
|
|
|
|
//Расчет отображения прогресса перезарядки
|
|
float delta = FillMaxSpeed * Time.deltaTime;
|
|
ProcessBar(TorpedoReloadBar, delta, G.WeaponModel.Weapons[0].ReloadPercent);
|
|
ProcessBar(MissileReloadBar, delta, G.WeaponModel.Weapons[1].ReloadPercent);
|
|
|
|
}
|
|
|
|
private void ProcessBar(Image bar, float delta, float targetPercent)
|
|
{
|
|
float targetFillAmount = 1 - targetPercent;
|
|
//float progress = Mathf.MoveTowards(bar.fillAmount, targetFillAmount, delta);
|
|
//bar.fillAmount = progress;
|
|
bar.fillAmount = targetFillAmount;
|
|
}
|
|
}
|