컨트롤
개요
ControlsSystem
은 엔티티가 다른 엔티티를 제어하고 입력을 제어된 엔티티의 컨트롤러에 전달할 수 있는 메커니즘을 제공합니다.
설정
첫 번째 단계는 다른 사람에 의해 통제될 수 있는 엔티티를 만드는 것입니다. 이를 위해 제어 가능한 엔티티의 컨트롤러는 IControllableObjectController
인터페이스를 구현해야 합니다.
C#
public interface IControllableObjectController
{
bool CanControl(Frame frame, EntityRef entity, EntityRef controllingEntity);
void OnControlStarted(Frame frame, EntityRef entity, EntityRef controllingEntity);
void OnControlStopped(Frame frame, EntityRef entity, EntityRef controllingEntity);
}
다른 엔티티를 통제할 수 있는 능력을 가진 엔티티는 다음을 수행해야 합니다.
Controls
컴포넌트가 있어야 합니다.IControllingObjectController
인터페이스를 구현하는 컨트롤러가 있어야 합니다.
C#
public interface IControllingObjectController
{
bool CanControl(Frame frame, EntityRef entity, EntityRef controllableEntity);
void OnControlStarted(Frame frame, EntityRef entity, EntityRef controllableEntity);
void OnControlStopped(Frame frame, EntityRef entity, EntityRef controllableEntity);
}
엔티티 컨트롤러가 IControllingObjectController
를 구현하는 경우 해당 컨트롤러를 가진 엔티티는 다른 컨트롤러의 제어를 시작하고 중지할 수 있습니다. 인간 에이전트는 StartControlCommand()
그리고 StopControlCommand()
를 각각 전송하여 제어를 시작하고 취소하는 반면 AI 에이전트는 InputDesires
속성을 통해 또는 ControlsDesires
를 통해 직접 제어합니다. 컨트롤이 시작되거나 중지되면 제어 가능한 엔티티 모두 OnControlStarted()
그리고 OnControlStopped()
에 대한 호출을 받게 됩니다.
노트: 각 인터페이스에서 찾을 수 있는 CanControl()
메소드를 통해 엔티티는 다른 엔티티가 유효한지를 결정할 수 있습니다. 즉, 이 엔티티가 다른 엔티티를 제어하거나 다른 엔티티에 의해 제어될 수 있습니다.
예제
FPS 템플릿은 다음을 구현하여 이러한 상호 작용의 예를 제공합니다.
TurretController
내의IControllableObjectController
그리고,AgentController
내의IControllingObjectController
.
Unity 에서는 터렛 및 에이전트 프로토타입에서 각각 이러한 컨트롤러를 사용합니다.
Back to top