namespace UnityEngine.XR.Content.Interaction
{
    /// 
    /// This class is responsible for creating the perler sockets grid and turning on/off the machine.
    /// 
    public class PerlerMachineController : MonoBehaviour
    {
        static readonly string k_EmissionKeyword = "_EMISSION";
        [SerializeField]
        [Tooltip("The emissive materials that will change state whenever the machine is turned on/off")]
        Material[] m_EmissiveMaterials;
        bool m_MachineActive;
        void Awake()
        {
            DisableEmissiveMaterials();
        }
#if UNITY_EDITOR
        void OnDestroy()
        {
            EnableEmissiveMaterials();
        }
#endif
        void DisableEmissiveMaterials()
        {
            foreach (var material in m_EmissiveMaterials)
                material.DisableKeyword(k_EmissionKeyword);
        }
        void EnableEmissiveMaterials()
        {
            foreach (var material in m_EmissiveMaterials)
                material.EnableKeyword(k_EmissionKeyword);
        }
        /// 
        /// Call this method to activate or deactivate the machine. This will also turn on/off its lights.
        /// Used by the BatterySlot GameObject socket.
        /// 
        /// Value of  to activate the machine;  otherwise.
        public void SetMachineActive(bool active)
        {
            // It's the same state?
            if (active == m_MachineActive)
                return;
            // Change the machine light state
            m_MachineActive = active;
            if (m_MachineActive)
                EnableEmissiveMaterials();
            else
                DisableEmissiveMaterials();
        }
    }
}