sea-battle-vr/Assets/Scripts/Gameplay/PlayerIndicatorsController.cs

54 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Lights;
using UnityEngine;
public class PlayerIndicatorsController : MonoBehaviour
{
[SerializeField] Weapon torpedo;
[SerializeField] Weapon missile;
private bool initialized = false;
public void Init()
{
G.PlayerStateModel.PlayerHealthComponent.HealthChanged += PlayerHealthComponent_HealthChanged;
torpedo.AmmoChanged += Torpedo_AmmoChanged;
missile.AmmoChanged += Missile_AmmoChanged;
foreach (Weapon weapon in G.WeaponModel.Weapons)
weapon.OnShoot += Weapon_OnShoot;
initialized = true;
}
private void Weapon_OnShoot(AbstractProjectile obj) => LightSystem.Ef_Shoot();
private void OnDestroy()
{
if( initialized )
{
G.PlayerStateModel.PlayerHealthComponent.HealthChanged -= PlayerHealthComponent_HealthChanged;
torpedo.AmmoChanged -= Torpedo_AmmoChanged;
missile.AmmoChanged -= Missile_AmmoChanged;
foreach (Weapon weapon in G.WeaponModel.Weapons)
weapon.OnShoot -= Weapon_OnShoot;
}
}
private void Missile_AmmoChanged(int obj)
{
LightSystem.SetIndicator(Indiсator.MissileAmmo, missile.AmmoPercent);
}
private void Torpedo_AmmoChanged(int obj)
{
LightSystem.SetIndicator(Indiсator.TorpedoAmmo, torpedo.AmmoPercent);
}
private void PlayerHealthComponent_HealthChanged(float obj)
{
LightSystem.SetIndicator(Indiсator.Life, G.PlayerStateModel.PlayerHealthComponent.HpPercent);
}
}