using NaughtyAttributes;
using UnityEngine;

namespace Station46.Scripts
{
    public class MultiEmission : Emission
    {
        [BoxGroup("Internal")] public MeshRenderer[] additionalEmissionRenderers;

        private Material[] _additionalMaterials;

        protected override void Awake()
        {
            base.Awake();

            _additionalMaterials = new Material[additionalEmissionRenderers.Length];
            for (var i = 0; i < additionalEmissionRenderers.Length; i++)
            {
                _additionalMaterials[i] = additionalEmissionRenderers[i].material;
            }
        }

        protected override void ChangedToggle()
        {
            base.ChangedToggle();

            foreach (var material in _additionalMaterials)
            {
                if (active)
                {
                    material.EnableKeyword("_EMISSION");
                }
                else
                {
                    material.DisableKeyword("_EMISSION");
                }
            }
        }

        protected override void ChangedColor()
        {
            base.ChangedColor();

            foreach (var material in _additionalMaterials)
            {
                material.SetColor(EmissionColorNameID, color);
            }
        }
    }
}