using UnityEngine;

using UPG.Debugging;

namespace BR.BattleRoyale
{
    [SelectionBase]
    public class DiscoBall : MonoBehaviour
    {
        #region INSPECTOR FIELDS
        [Header("Settings")]
        [SerializeField] float m_rotationSpeed = 1;

        [Header("Debug")]
        [SerializeField] DebugChannel m_debugChannel = null;
        #endregion

        #region DEFAULT METHODS
        void Start()
        {
            foreach (Transform child in transform)
            {
                MeshRenderer _renderer = child.gameObject.GetComponent<MeshRenderer>();

                if (!_renderer)
                    continue;

                MaterialPropertyBlock _props = new MaterialPropertyBlock();

                _renderer.GetPropertyBlock(_props);

                Color _color = Color.HSVToRGB(Random.Range(0f, 1f), 1, 1);

                _props.SetColor("_LightColor", _color);

                _renderer.SetPropertyBlock(_props);

                foreach (Transform grandchild in child)
                {
                    Light _light = grandchild.GetComponent<Light>();

                    if (!_light)
                        continue;

                    _light.color = _color;
                }
            }
        }
        void Update()
        {
            transform.localRotation *= Quaternion.Euler(0, 0, 45f * m_rotationSpeed * Time.deltaTime);
        }
        #endregion
    }
}