Level/LightTrigger.cs
namespace Opium;

[EditorHandle( "materials/dev/light_trigger.png" )]
public partial class LightTrigger : Component, Component.ITriggerListener
{
	[Property] public List<Light> Lights { get; set; } = new();
	[Property] public List<GameObject> GameObjects { get; set; } = new();

	public IEnumerable<Light> LightCollection
	{
		get
		{
			var lights = Lights.ToList();
			lights.AddRange( Components.GetAll<Light>( FindMode.EverythingInSelfAndDescendants ) );

			return lights;
		}
	}

	private void SetState( bool state )
	{
		foreach ( var light in LightCollection )
		{
			light.Enabled = state;
		}

		foreach ( var go in GameObjects )
		{
			go.Enabled = state;
		}
	}

	protected override void OnStart()
	{
		SetState( false );	
	}

	public void OnTriggerEnter( Collider other )
	{
		if ( other.Components.Get<Opium.PlayerController>( FindMode.EverythingInSelfAndAncestors ) is not null )
		{
			SetState( true );
		}

	}

	public void OnTriggerExit( Collider other )
	{
		if ( other.Components.Get<Opium.PlayerController>( FindMode.EverythingInSelfAndAncestors ) is not null )
		{
			SetState( false );
		}
	}
}