UE编辑器内模拟移动平台操控
在PC上:
GetMutableDefault<UInputSettings>()->bUseMouseForTouch = false; //是否用鼠标模拟touch
//设置当Viewport被点击的时候,鼠标被捕获的方式
GetMutableDefault<UInputSettings>()->DefaultViewportMouseCaptureMode = EMouseCaptureMode::CapturePermanently_IncludingInitialMouseDown;
在移动平台上:
APlayerController* PC = Cast<APlayerController>(GetOuter());
if (IsValid(PC))
{
GetMutableDefault<UInputSettings>()->bUseMouseForTouch = true;
GetMutableDefault<UInputSettings>()->DefaultViewportMouseCaptureMode = EMouseCaptureMode::NoCapture;
PC->bShowMouseCursor = true; //显示鼠标
PC->DefaultMouseCursor = EMouseCursor::Crosshairs;//显示默认的鼠标样式
}
绑定Touch回调事件:
每个actor都有一个InputComponent。
InputComponent->BindTouch(EInputEvent::IE_Pressed, this, &xxx::TouchPressed);
InputComponent->BindTouch(EInputEvent::IE_Released, this, &XXX::TouchReleased);
InputComponent->BindTouch(EInputEvent::IE_Repeat, this, &XXX::TouchRepeat);