Unreal Slate Overlay ZOrder
언리얼 UMG Slate Overlay ZOrder 수정할 수 있게 코드 수정
UUserWidget클래스에 함수 추가
Root Widget에 대해서만 처리함.
bool UUserWidget::ChangeZOrder(const int32 InZOrder)
{
if (FullScreenWidget.IsValid())
{
TSharedPtr<SWidget> WidgetHost = FullScreenWidget.Pin();
UWorld* World = GetWorld();
if (World && World->IsGameWorld())
{
if (UGameViewportClient* ViewportClient = World->GetGameViewport())
{
TSharedRef<SWidget> WidgetHostRef = WidgetHost.ToSharedRef();
return ViewportClient->ChangeZOrderViewportWidgetContent(WidgetHostRef, InZOrder);
}
}
}
return false;
}
GameViewPortClient클래스에 함수 추가
bool UGameViewportClient::ChangeZOrderViewportWidgetContent(TSharedRef<SWidget> ViewportContent, const int32 ZOrder)
{
TSharedPtr< SOverlay > PinnedViewportOverlayWidget(ViewportOverlayWidget.Pin());
if (ensure(PinnedViewportOverlayWidget.IsValid()))
{
return PinnedViewportOverlayWidget->ChangeSlot(ViewportContent, ZOrder);
}
return false;
}
SOverlay 클래스에 함수 추가
Viewport root에 붙은 SOverlay에 대하여 처리한다.
bool SOverlay::ChangeSlot(TSharedRef<SWidget> Widget, int32 ZOrder)
{
bool bFindSlot = false;
for (int32 CurSlotIndex = 0; CurSlotIndex < Children.Num(); ++CurSlotIndex)
{
FOverlaySlot& CurSlot = Children[CurSlotIndex];
if (CurSlot.GetWidget() == Widget)
{
CurSlot.ZOrder = ZOrder;
bFindSlot = true;
break;
}
}
if (bFindSlot)
{
Children.Sort([](const FOverlaySlot& InLeft, const FOverlaySlot& InRight)
{
return InLeft.ZOrder < InRight.ZOrder;
});
Invalidate(EInvalidateWidget::Layout);
}
return bFindSlot;
}