﻿using UnityEngine;
using UnityEngine.Extended;

public class GameplayUIReloadBarController : MonoBehaviour
{
    [SerializeField]
    private Color LerpFrom;

    [SerializeField]
    private Color LerpTo;

    private GameplayGunFireControllerBase m_GunFireController;
    private SpriteRendererEx m_ReloadRenderer;

    private void Start()
    {
        m_ReloadRenderer = GetComponent<SpriteRendererEx>();
    }

    private void Update()
    {
        if (GameplayGunsManager.currentGun == null)
        {
            m_GunFireController = null;
        }
        else
        {
            if (m_GunFireController == null)
            {
                m_GunFireController = GameplayGunsManager.currentGun.GetComponent<GameplayGunFireControllerBase>();
            }

            if (m_ReloadRenderer.fillAmount != m_GunFireController.ReloadValue)
            {
                m_ReloadRenderer.fillAmount = m_GunFireController.ReloadValue;
                m_ReloadRenderer.color = Color.Lerp(LerpFrom, LerpTo, m_GunFireController.ReloadValue);
            }
        }
    }
}
