UE4在Editor下的按键响应
通过FSlateApplication的委托实现:
#include "SLevelViewport.h"
void FMatAbsorbModule::StartupModule()
{
FDelegateHandle TickerHandle = FTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateRaw(this, &FMatAbsorbModule::MyTick), 0.0f);
FSlateApplication::Get().OnApplicationPreInputKeyDownListener().AddRaw(this,&FMatAbsorbModule::MKeyEvent);
}
void FMatAbsorbModule::MKeyEvent(const FKeyEvent& KeyEvent)
{
FKey CurrentKey = KeyEvent.GetKey();
if (CurrentKey == EKeys::M)
{
//加入要响应M键的操作
}
}
获取鼠标选中的Actor
通过GEditor实现
USelection* SelectedActors = GEditor->GetSelectedActors();
TArray<AActor*> Actors;
for (FSelectionIterator Iter(*SelectedActors); Iter; ++Iter)
{
AActor* Actor = Cast<AActor>(*Iter);
}