class StaticPlatform extends InteractiveDevice
{
	default m_controllerTypeName = 'StaticPlatformController';
	private const instanceeditable var m_componentsToToggleNames : array< CName >;
	private instanceeditable var m_meshName : CName;
	[ customEditor = "AudioEvent" ]
	private instanceeditable var m_sfxOnEnable : CName;
	private var m_componentsToToggle : array< IComponent >;

	protected event OnGameAttached()
	{
		super.OnGameAttached();
		if( GetController().GetPS().IsTriggered() )
		{
			SetVisualsAsActive();
		}
	}

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		var i : Int32;
		super.OnRequestComponents( ri );
		for( i = 0; i < m_componentsToToggleNames.Size(); i += 1 )
		{
			EntityRequestComponentsInterface.RequestComponent( ri, m_componentsToToggleNames[ i ], 'IComponent', false );
		}
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		var i : Int32;
		var component : IComponent;
		super.OnTakeControl( ri );
		for( i = 0; i < m_componentsToToggleNames.Size(); i += 1 )
		{
			component = ( ( IComponent )( EntityResolveComponentsInterface.GetComponent( ri, m_componentsToToggleNames[ i ] ) ) );
			if( component )
			{
				m_componentsToToggle.PushBack( component );
			}
		}
		m_controller = ( ( StaticPlatformController )( EntityResolveComponentsInterface.GetComponent( ri, 'controller' ) ) );
	}

	private const override function GetController() : StaticPlatformController
	{
		return ( ( StaticPlatformController )( m_controller ) );
	}

	protected event OnAreaEnter( evt : AreaEnteredEvent )
	{
		var whoEntered : EntityID;
		whoEntered = EntityGameInterface.GetEntity( evt.activator ).GetEntityID();
		if( ( whoEntered == GetPlayerMainObject().GetEntityID() ) && !( GetController().GetPS().IsTriggered() ) )
		{
			GetController().GetPS().SetAsTriggered();
			SetVisualsAsActive();
			PlaySfx();
		}
	}

	private function SetVisualsAsActive()
	{
		ActivateComponents();
		SetMeshAppearance( m_meshName );
	}

	private function ActivateComponents()
	{
		var i : Int32;
		for( i = 0; i < m_componentsToToggle.Size(); i += 1 )
		{
			m_componentsToToggle[ i ].Toggle( true );
		}
	}

	private function PlaySfx()
	{
		PlaySound( this, m_sfxOnEnable );
	}

}

