UE4运用C++和框架开发坦克大战教程笔记(十九)(第58~60集)完结

UE4运用C++和框架开发坦克大战教程笔记(十九)(第58~60集)完结

  • 58. 弹窗显示与隐藏
  • 59. UI 面板销毁
  • 60. 框架完成与总结

58. 弹窗显示与隐藏

这节课我们先来补全 TransferMask() 里对于 Overlay 布局类型面板的遮罩转移逻辑,大体上与 Canvas 布局类型的差不多。

接下来就是编写弹窗的隐藏和重新显示的逻辑。

在写重新显示弹窗的逻辑时我们发现 DoEnterUIPanel() 有一段代码可以复用,但是发现了一处逻辑上的错误,所以要调整一下代码。

DDFrameWidget.cpp

void UDDFrameWidget::DoEnterUIPanel(FName PanelName)
{// ... 省略// 此处作更改	if (!WorkLayout) {if (UnActiveCanvas.Num() == 0) {WorkLayout = WidgetTree->ConstructWidget<UCanvasPanel>(UCanvasPanel::StaticClass());WorkLayout->SetVisibility(ESlateVisibility::SelfHitTestInvisible);}elseWorkLayout = UnActiveCanvas.Pop();// 添加布局控件到界面最顶层UCanvasPanelSlot* FrameCanvasSlot = RootCanvas->AddChildToCanvas(WorkLayout);FrameCanvasSlot->SetAnchors(FAnchors(0.f, 0.f, 1.f, 1.f));FrameCanvasSlot->SetOffsets(FMargin(0.f, 0.f, 0.f, 0.f));// 添加到激活画布组ActiveCanvas.Push(WorkLayout);	}// ... 省略// 此处作更改if (!WorkLayout) {if (UnActiveOverlay.Num() == 0) {WorkLayout = WidgetTree->ConstructWidget<UOverlay>(UOverlay::StaticClass());WorkLayout->SetVisibility(ESlateVisibility::SelfHitTestInvisible);}elseWorkLayout = UnActiveOverlay.Pop();// 添加布局控件到界面最顶层UCanvasPanelSlot* FrameCanvasSlot = RootCanvas->AddChildToCanvas(WorkLayout);FrameCanvasSlot->SetAnchors(FAnchors(0.f, 0.f, 1.f, 1.f));FrameCanvasSlot->SetOffsets(FMargin(0.f, 0.f, 0.f, 0.f));// 添加到激活画布组ActiveOverlay.Push(WorkLayout);	}// ... 省略
}void UDDFrameWidget::HidePanelReverse(UDDPanelWidget* PanelWidget)
{// 获取弹窗栈到数组TArray<UDDPanelWidget*> PopStack;PopPanelStack.GenerateValueArray(PopStack);// 如果不是最上层的弹窗,直接返回if (PopStack[PopStack.Num() - 1] != PanelWidget) {DDH::Debug() << PanelWidget->GetObjectName() << " Is Not Last Panel In PopPanelStack" << DDH::Endl();return;}// 从栈中移除PopPanelStack.Remove(PanelWidget->GetObjectName());// 执行隐藏函数PanelWidget->PanelHidden();// 调整弹窗栈PopStack.Pop();if (PopStack.Num() > 0) {UDDPanelWidget* PrePanelWidget = PopStack[PopStack.Num() - 1];// 转移遮罩到新的最顶层的弹窗的下一层TransferMask(PrePanelWidget);// 恢复被冻结的最顶层的弹窗PrePanelWidget->PanelResume();}// 如果没有弹窗就移除遮罩elseRemoveMaskPanel();
}void UDDFrameWidget::ShowPanelReverse(UDDPanelWidget* PanelWidget)
{// 如果弹窗栈里有元素,冻结最顶层的弹窗if (PopPanelStack.Num() > 0) {TArray<UDDPanelWidget*> PanelStack;PopPanelStack.GenerateValueArray(PanelStack);PanelStack[PanelStack.Num() - 1]->PanelFreeze();}// 弹窗对象必须从当前父控件移除,再重新添加到最顶层的界面(因为弹窗只是隐藏而不是销毁了)if (PanelWidget->UINature.LayoutType == ELayoutType::Canvas) {UCanvasPanel* PreWorkLayout = Cast<UCanvasPanel>(PanelWidget->GetParent());UCanvasPanelSlot* PrePanelSlot = Cast<UCanvasPanelSlot>(PanelWidget->Slot);FAnchors PreAnchors = PrePanelSlot->GetAnchors();FMargin PreOffsets = PrePanelSlot->GetOffsets();// 将 PanelWidget 从当前父控件移除PanelWidget->RemoveFromParent();// 处理父控件if (PreWorkLayout->GetChildrenCount() == 0) {PreWorkLayout->RemoveFromParent();ActiveCanvas.Remove(PreWorkLayout);UnActiveCanvas.Push(PreWorkLayout);}// 寻找最顶层的 WorkLayoutUCanvasPanel* WorkLayout = NULL;// 判断最底层的布局控件是否是 Canvasif (RootCanvas->GetChildrenCount() > 0)WorkLayout = Cast<UCanvasPanel>(RootCanvas->GetChildAt(RootCanvas->GetChildrenCount() - 1));if (!WorkLayout) {// 如果没有任何对象if (UnActiveCanvas.Num() == 0) {WorkLayout = WidgetTree->ConstructWidget<UCanvasPanel>(UCanvasPanel::StaticClass());WorkLayout->SetVisibility(ESlateVisibility::SelfHitTestInvisible);}elseWorkLayout = UnActiveCanvas.Pop();// 添加布局控件到界面最顶层UCanvasPanelSlot* FrameCanvasSlot = RootCanvas->AddChildToCanvas(WorkLayout);FrameCanvasSlot->SetAnchors(FAnchors(0.f, 0.f, 1.f, 1.f));FrameCanvasSlot->SetOffsets(FMargin(0.f, 0.f, 0.f, 0.f));// 添加到激活画布组ActiveCanvas.Push(WorkLayout);	}// 激活遮罩到最顶层弹窗ActiveMask(WorkLayout, PanelWidget->UINature.PanelLucencyType);// 把弹窗添加到获取的最顶层的父控件UCanvasPanelSlot* PanelSlot = WorkLayout->AddChildToCanvas(PanelWidget);PanelSlot->SetAnchors(PreAnchors);PanelSlot->SetOffsets(PreOffsets);}else {UOverlay* PreWorkLayout = Cast<UOverlay>(PanelWidget->GetParent());UOverlaySlot* PrePanelSlot = Cast<UOverlaySlot>(PanelWidget->Slot);FMargin PrePadding = PrePanelSlot->Padding;TEnumAsByte<EHorizontalAlignment> PreHAlign = PrePanelSlot->HorizontalAlignment;TEnumAsByte<EVerticalAlignment> PreVAlign = PrePanelSlot->VerticalAlignment;// 将 PanelWidget 从当前父控件移除PanelWidget->RemoveFromParent();// 处理父控件if (PreWorkLayout->GetChildrenCount() == 0) {PreWorkLayout->RemoveFromParent();ActiveOverlay.Remove(PreWorkLayout);UnActiveOverlay.Push(PreWorkLayout);}UOverlay* WorkLayout = NULL;// 如果存在布局控件,试图把最后一个布局控件转换成 Overlayif (RootCanvas->GetChildrenCount() > 0)WorkLayout = Cast<UOverlay>(RootCanvas->GetChildAt(RootCanvas->GetChildrenCount() - 1));if (!WorkLayout) {if (UnActiveOverlay.Num() == 0) {WorkLayout = WidgetTree->ConstructWidget<UOverlay>(UOverlay::StaticClass());WorkLayout->SetVisibility(ESlateVisibility::SelfHitTestInvisible);}elseWorkLayout = UnActiveOverlay.Pop();// 添加布局控件到界面最顶层UCanvasPanelSlot* FrameCanvasSlot = RootCanvas->AddChildToCanvas(WorkLayout);FrameCanvasSlot->SetAnchors(FAnchors(0.f, 0.f, 1.f, 1.f));FrameCanvasSlot->SetOffsets(FMargin(0.f, 0.f, 0.f, 0.f));// 添加到激活画布组ActiveOverlay.Push(WorkLayout);	}// 激活遮罩到最顶层弹窗ActiveMask(WorkLayout, PanelWidget->UINature.PanelLucencyType);// 添加弹窗到获取到的最顶层的布局控件UOverlaySlot* PanelSlot = WorkLayout->AddChildToOverlay(PanelWidget);PanelSlot->SetPadding(PrePadding);PanelSlot->SetHorizontalAlignment(PreHAlign);PanelSlot->SetVerticalAlignment(PreVAlign);}// 添加弹窗到栈PopPanelStack.Add(PanelWidget->GetObjectName(), PanelWidget);// 显示弹窗PanelWidget->PanelDisplay();
}void UDDFrameWidget::TransferMask(UDDPanelWidget* PanelWidget)
{// ... 省略if (PanelWidget->UINature.LayoutType == ELayoutType::Canvas) {// ... 省略}else {UOverlay* WorkLayout = Cast<UOverlay>(PanelWidget->GetParent());int32 StartOrder = WorkLayout->GetChildIndex(PanelWidget);for (int i = StartOrder; i < WorkLayout->GetChildrenCount(); ++i) {UDDPanelWidget* TempPanelWidget = Cast<UDDPanelWidget>(WorkLayout->GetChildAt(i));if (!TempPanelWidget)continue;// 保存 UI 面板以及布局数据AbovePanelStack.Push(TempPanelWidget);FUINature TempUINature;UOverlaySlot* TempPanelSlot = Cast<UOverlaySlot>(TempPanelWidget->Slot);TempUINature.Offsets = TempPanelSlot->Padding;TempUINature.HAlign = TempPanelSlot->HorizontalAlignment;TempUINature.VAlign = TempPanelSlot->VerticalAlignment;AboveNatureStack.Push(TempUINature);}// 循环移除上层 UI 面板for (int i = 0; i < AbovePanelStack.Num(); ++i)AbovePanelStack[i]->RemoveFromParent();// 添加遮罩到新的父控件UOverlaySlot* MaskSlot = WorkLayout->AddChildToOverlay(MaskPanel);MaskSlot->SetPadding(FMargin(0.f, 0.f, 0.f, 0.f));MaskSlot->SetHorizontalAlignment(HAlign_Fill);MaskSlot->SetVerticalAlignment(VAlign_Fill);// 根据透明类型设置透明度switch (PanelWidget->UINature.PanelLucencyType) {case EPanelLucencyType::Lucency:MaskPanel->SetVisibility(ESlateVisibility::Visible);MaskPanel->SetColorAndOpacity(NormalLucency);break;case EPanelLucencyType::Translucence:MaskPanel->SetVisibility(ESlateVisibility::Visible);MaskPanel->SetColorAndOpacity(TranslucenceLucency);break;case EPanelLucencyType::ImPenetrable:MaskPanel->SetVisibility(ESlateVisibility::Visible);MaskPanel->SetColorAndOpacity(ImPenetrableLucency);break;case EPanelLucencyType::Penetrate:MaskPanel->SetVisibility(ESlateVisibility::Hidden);MaskPanel->SetColorAndOpacity(NormalLucency);break;}// 将 UI 面板填充回布局控件for (int i = 0; i < AbovePanelStack.Num(); ++i) {UOverlaySlot* PanelSlot = WorkLayout->AddChildToOverlay(AbovePanelStack[i]);PanelSlot->SetPadding(AboveNatureStack[i].Offsets);PanelSlot->SetHorizontalAlignment(AboveNatureStack[i].HAlign);PanelSlot->SetVerticalAlignment(AboveNatureStack[i].VAlign);}}
}

接下来我们测试一下弹窗隐藏和重新显示的逻辑是否正常运行。依旧是修改协程方法里的调用顺序。

RCGameUIFrame.cpp

// 修改协程方法如下
DDCoroTask* URCGameUIFrame::UIProcess()
{DDCORO_PARAM(URCGameUIFrame);#include DDCORO_BEGIN()// 显示状态栏和小地图D->ShowUIPanel("StatePanel");D->ShowUIPanel("MiniMapPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);		// 缩短时间// 显示菜单栏D->ShowUIPanel("MenuPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);// 显示设置栏D->ShowUIPanel("OptionPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);// 隐藏菜单栏,这个操作会失败并输出 Debug 错误D->HideUIPanel("MenuPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);// 隐藏设置栏D->HideUIPanel("OptionPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);// 隐藏菜单栏,本次操作成功D->HideUIPanel("MenuPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);	// 显示菜单栏D->ShowUIPanel("MenuPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);// 显示设置栏D->ShowUIPanel("OptionPanel");#include DDCORO_END()
}

运行游戏,可见界面上有状态栏和小地图,
3 秒后菜单弹窗伴随着遮罩出现,菜单弹窗可交互;
再 3 秒后设置弹窗出现,遮罩移到它的底下,菜单弹窗不可交互,设置弹窗可交互;
再 3 秒后试图隐藏菜单弹窗,但是它不是最靠前的弹窗,所以左上角输出 Debug 语句提示失败。
再 3 秒后设置弹窗隐藏,遮罩移到菜单弹窗的底下,并且菜单弹窗又恢复可交互;
再 3 秒菜单弹窗和遮罩隐藏;
再 3 秒,菜单弹窗和遮罩重新出现,菜单弹窗可交互;
最后再 3 秒,设置弹窗出现,遮罩移到它的底下,菜单弹窗不可交互,设置弹窗可交互;

在这里插入图片描述

说明我们写的遮罩管理器以及弹窗的隐藏和重新显示都没有问题。

59. UI 面板销毁

UI 框架已经实现了大半,我们接下来继续实现 UI 的销毁功能。对于销毁逻辑也需要根据面板类型来使用相应的方法。

DDFrameWidget.h

public:// 销毁 UIUFUNCTION()void ExitUIPanel(FName PanelName);// 处理 UI 面板销毁后的父控件(供反射系统调用)UFUNCTION()void ExitCallBack(ELayoutType LayoutType, UPanelWidget* InLayout);protected:// 销毁 UIvoid ExitPanelDoNothing(UDDPanelWidget* PanelWidget);void ExitPanelHideOther(UDDPanelWidget* PanelWidget);void ExitPanelReverse(UDDPanelWidget* PanelWidget);

DDFrameWidget.cpp

void UDDFrameWidget::ExitUIPanel(FName PanelName)
{// 如果正在预加载但是没有加载完成(这种情况出现在执行第一次显示或提前加载后就马上执行销毁界面)if (!AllPanelGroup.Contains(PanelName) && LoadedPanelName.Contains(PanelName)) {DDH::Debug() << "Do Not Exit UI Panel when Loading Panel" << DDH::Endl();return;}// 如果这个 UI 面板没有加载到全部组if (!AllPanelGroup.Contains(PanelName))return;// 获取 UI 面板UDDPanelWidget* PanelWidget = *AllPanelGroup.Find(PanelName);// 是否在显示组或者弹窗栈内if (!ShowPanelGroup.Contains(PanelName) && !PopPanelStack.Contains(PanelName)) {AllPanelGroup.Remove(PanelName);LoadedPanelName.Remove(PanelName);// 运行 PanelExit 生命周期,具体的内存释放代码在该周期函数里面PanelWidget->PanelExit();// 直接返回return;}// 处理隐藏 UI 面板相关的流程switch (PanelWidget->UINature.PanelShowType) {case EPanelShowType::DoNothing:ExitPanelDoNothing(PanelWidget);break;case EPanelShowType::HideOther:ExitPanelHideOther(PanelWidget);break;case EPanelShowType::Reverse:ExitPanelReverse(PanelWidget);break;}
}void UDDFrameWidget::ExitPanelDoNothing(UDDPanelWidget* PanelWidget)
{// 从显示组,全部组,加载名字组移除ShowPanelGroup.Remove(PanelWidget->GetObjectName());AllPanelGroup.Remove(PanelWidget->GetObjectName());LoadedPanelName.Remove(PanelWidget->GetObjectName());// 运行销毁生命周期PanelWidget->PanelExit();
}void UDDFrameWidget::ExitPanelHideOther(UDDPanelWidget* PanelWidget)
{// 从显示组,全部组,加载名字组移除ShowPanelGroup.Remove(PanelWidget->GetObjectName());AllPanelGroup.Remove(PanelWidget->GetObjectName());LoadedPanelName.Remove(PanelWidget->GetObjectName());// 显示同一层级下的其他 UI 面板,如果该面板是 Level_All 层级,显示所有显示组的面板for (TMap<FName, UDDPanelWidget*>::TIterator It(ShowPanelGroup); It; ++It) {if (PanelWidget->UINature.LayoutLevel == ELayoutLevel::Level_All || PanelWidget->UINature.LayoutLevel == It.Value()->UINature.LayoutLevel)It.Value()->PanelDisplay();}// 运行销毁生命周期PanelWidget->PanelExit();
}void UDDFrameWidget::ExitPanelReverse(UDDPanelWidget* PanelWidget)
{// 获取弹窗栈到数组TArray<UDDPanelWidget*> PopStack;PopPanelStack.GenerateValueArray(PopStack);// 如果不是最上层的弹窗,直接返回if (PopStack[PopStack.Num() - 1] != PanelWidget) {DDH::Debug() << PanelWidget->GetObjectName() << " Is Not Last Panel In PopPanelStack" << DDH::Endl();return;}// 从栈,全部组,加载名字组中移除PopPanelStack.Remove(PanelWidget->GetObjectName());AllPanelGroup.Remove(PanelWidget->GetObjectName());LoadedPanelName.Remove(PanelWidget->GetObjectName());// 运行销毁生命周期函数PanelWidget->PanelExit();// 调整弹窗栈PopStack.Pop();if (PopStack.Num() > 0) {UDDPanelWidget* PrePanelWidget = PopStack[PopStack.Num() - 1];// 转移遮罩到新的最顶层的弹窗的下一层TransferMask(PrePanelWidget);// 恢复被冻结的最顶层的弹窗PrePanelWidget->PanelResume();}elseRemoveMaskPanel();
}void UDDFrameWidget::ExitCallBack(ELayoutType LayoutType, UPanelWidget* InLayout)
{if (LayoutType == ELayoutType::Canvas) {UCanvasPanel* WorkLayout = Cast<UCanvasPanel>(InLayout);if (WorkLayout->GetChildrenCount() == 0) {WorkLayout->RemoveFromParent();ActiveCanvas.Remove(WorkLayout);UnActiveCanvas.Push(WorkLayout);}}else {UOverlay* WorkLayout = Cast<UOverlay>(InLayout);if (WorkLayout->GetChildrenCount() == 0) {WorkLayout->RemoveFromParent();ActiveOverlay.Remove(WorkLayout);UnActiveOverlay.Push(WorkLayout);}}
}

来到 DDPanelWidget,编写销毁 UI 的具体逻辑。

因为需要考虑面板销毁后父控件是否还有子面板(如果没有就没必要存在了),所以我们利用反射系统声明一个方法来调用 DDFrameWidget 里的方法来移除没有内容的父控件。

DDPanelWidget.h

protected:// 销毁动画回调函数void RemoveCallBack();protected:// UIFrame 管理器所在的模组 ID,约定在 HUD 下,数值是 1static int32 UIFrameModuleIndex;// UIFrame 管理器的对象名,约定是 UIFramestatic FName UIFrameName;// 销毁回调函数名字static FName ExitCallBackName;protected:DDOBJFUNC_TWO(ExitCallBack, ELayoutType, LayoutType, UPanelWidget*, WorkLayout);

DDPanelWidget.cpp

int32 UDDPanelWidget::UIFrameModuleIndex(1);FName UDDPanelWidget::UIFrameName(TEXT("UIFrame"));FName UDDPanelWidget::ExitCallBackName(TEXT("ExitCallBack"));void UDDPanelWidget::PanelExit()
{// 如果 UI 面板正在显示if (GetVisibility() != ESlateVisibility::Hidden)InvokeDelay(PanelHiddenName, DisplayLeaveMovie(), this, &UDDPanelWidget::RemoveCallBack);elseRemoveCallBack();
}void UDDPanelWidget::RemoveCallBack()
{// 获取父控件UPanelWidget* WorkLayout = GetParent();// 这个判断条件会在下一集补充// 已经加载了 UI 面板,但是一直没有运行显示命令的情况下,WorkLayout 为空if (WorkLayout) {RemoveFromParent();// 告诉 UI 管理器处理父控件ExitCallBack(UIFrameModuleIndex, UIFrameName, ExitCallBackName, UINature.LayoutType, WorkLayout);}// 执行销毁DDDestroy();
}

接下来测试下销毁 UI 的逻辑是否正常运行,依旧是调整协程方法里的调用逻辑。

RCGameUIFrame.cpp

// 修改协程方法如下
DDCoroTask* URCGameUIFrame::UIProcess()
{DDCORO_PARAM(URCGameUIFrame);#include DDCORO_BEGIN()D->ShowUIPanel("StatePanel");D->ShowUIPanel("MiniMapPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);D->ShowUIPanel("BigMapPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);D->ShowUIPanel("MenuPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);D->ShowUIPanel("OptionPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);DDH::Debug() << "ExitUIPanel MiniMapPanel" << DDH::Endl();D->ExitUIPanel("MiniMapPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);DDH::Debug() << "ExitUIPanel OptionPanel" << DDH::Endl();D->ExitUIPanel("OptionPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);DDH::Debug() << "ExitUIPanel BigMapPanel" << DDH::Endl();D->ExitUIPanel("BigMapPanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);DDH::Debug() << "ExitUIPanel StatePanel" << DDH::Endl();D->ExitUIPanel("StatePanel");#include DDYIELD_READY()DDYIELD_RETURN_SECOND(3.f);DDH::Debug() << "ExitUIPanel MenuPanel" << DDH::Endl();D->ExitUIPanel("MenuPanel");#include DDCORO_END()
}

运行游戏,首先可看到状态栏和小地图;接着是大地图出现(状态栏和小地图收起);菜单弹窗出现;设置弹窗出现;
随后销毁小地图、销毁设置弹窗、销毁大地图(状态栏出现)、销毁状态栏,最后销毁菜单弹窗。
说明销毁 UI 的功能也写好了。

在这里插入图片描述

60. 框架完成与总结

课程已经接近尾声,本集开头会修改一些疏漏的地方,笔者已经在先前的课程里标注了。

我们前面写了很多 UI 框架的方法,但是看起来都是管理类在操控面板,我们打算让面板自己也能执行这些操控方法,只要通过反射系统让管理类执行就可以实现了。

DDPanelWidget.h

protected:void ShowSelfPanel();void HideSelfPanel();void ExitSelfPanel();void AdvanceLoadPanel(FName PanelName);void ShowUIPanel(FName PanelName);void HideUIPanel(FName PanelName);void ExitUIPanel(FName PanelName);protected:// 显示 UI 方法名static FName ShowUIPanelName;// 隐藏 UI 方法名static FName HideUIPanelName;// 销毁 UI 方法名static FName ExitUIPanelName;// 预加载方法名static FName AdvanceLoadPanelName;protected:DDOBJFUNC_ONE(OperatorUIPanel, FName, PanelName);

DDPanelWidge.cpp

FName UDDPanelWidget::ShowUIPanelName(TEXT("ShowUIPanel"));FName UDDPanelWidget::HideUIPanelName(TEXT("HideUIPanel"));FName UDDPanelWidget::ExitUIPanelName(TEXT("ExitUIPanel"));FName UDDPanelWidget::AdvanceLoadPanelName(TEXT("AdvanceLoadPanel"));void UDDPanelWidget::ShowSelfPanel()
{ShowUIPanel(GetObjectName());
}void UDDPanelWidget::HideSelfPanel()
{HideUIPanel(GetObjectName());
}void UDDPanelWidget::ExitSelfPanel()
{ExitUIPanel(GetObjectName());
}void UDDPanelWidget::AdvanceLoadPanel(FName PanelName)
{OperatorUIPanel(UIFrameModuleIndex, UIFrameName, AdvanceLoadPanelName, PanelName);
}void UDDPanelWidget::ShowUIPanel(FName PanelName)
{OperatorUIPanel(UIFrameModuleIndex, UIFrameName, ShowUIPanelName, PanelName);
}void UDDPanelWidget::HideUIPanel(FName PanelName)
{OperatorUIPanel(UIFrameModuleIndex, UIFrameName, HideUIPanelName, PanelName);
}void UDDPanelWidget::ExitUIPanel(FName PanelName)
{OperatorUIPanel(UIFrameModuleIndex, UIFrameName, ExitUIPanelName, PanelName);
}

最后再改一些地方的错误。

DDTypes.h

// 执行 Execute 方法之前必须手动调用 IsBound() 方法判定是否有绑定函数
template<typename RetType, typename... VarTypes>
RetType DDCallHandle<RetType, VarTypes...>::Execute(VarTypes... Params)
{// 删除原来的 是否绑定 判断return MsgQuene->Execute<RetType, VarTypes...>(CallName, Params...);
}

DDDriver.cpp

#if WITH_EDITOR
void ADDDriver::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{Super::PostEditChangeProperty(PropertyChangedEvent);if (PropertyChangedEvent.Property && PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(ADDDriver, ModuleType)) {Center->IterChangeModuleType(Center, ModuleType);}
}
#endif// 下面这两个方法要放在预编译的 #if WITH_EDITOR 之外,笔者检查的时候已经是放在外面的了,应该是在前面的课程也有提到这个修改
void ADDDriver::ExecuteFunction(DDModuleAgreement Agreement, DDParam* Param)
{Center->AllotExecuteFunction(Agreement, Param);
}void ADDDriver::ExecuteFunction(DDObjectAgreement Agreement, DDParam* Param)
{Center->AllotExecuteFunction(Agreement, Param);
}

最后我们来看一下梁迪老师的 DataDriven 框架实现了如下功能:

  1. 模块化树状结构(适合分模块多人合作开发)
  2. 更多生命周期函数
  3. 反射事件系统(零耦合, 调用方便)
  4. 注册事件系统(零耦合, 运行效率高, 适合大批量调用时使用)
  5. 协程系统(全面实现 Unity 协程的功能)
  6. 延时事件系统
  7. 多按键绑定系统
  8. 资源同异步加载系统
  9. UI 框架

至于坦克大战,应该是没有的了。不过能系统地学习梁迪老师的这个框架,相信读者也能收获到很多。笔者在此衷心感谢梁迪老师的优质课程 : )

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/461223.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

华为第二批难题五:AI技术提升六面体网格生成自动化问题

有CAE开发商问及OCCT几何内核的网格方面的技术问题。其实&#xff0c;OCCT几何内核的现有网格生成能力比较弱。 HybridOctree_Hex的源代码&#xff0c;还没有仔细去学习。 “HybridOctree_Hex”的开发者说&#xff1a;六面体网格主要是用在数值模拟领域的&#xff0c;比如汽车…

第十六篇【传奇开心果系列】Python的OpenCV库技术点案例示例:图像质量评估

传奇开心果短博文系列 系列短博文目录Python的OpenCV库技术点案例示例短博文系列博文目录前言一、图像质量评估方法和相关函数的介绍二、均方误差示例代码三、峰值信噪比示例代码四、结构相似性指数示例代码五、视频质量评估示例代码六、OpenCV均方根误差计算示例代码七、OpenC…

Go语言每日一题——链表篇(七)

传送门 牛客面试笔试必刷101题 ----------------删除链表的倒数第n个节点 题目以及解析 题目 解题代码及解析 解析 这一道题与昨天的题目在解题思路上有一定的相似之处&#xff0c;都是基于双指针定义快慢指针&#xff0c;这里我们让快指针先走n步&#xff0c;又因为n一定…

WebSocket+Http实现功能加成

WebSocketHttp实现功能加成 前言 首先&#xff0c;WebSocket和HTTP是两种不同的协议&#xff0c;它们在设计和用途上有一些显著的区别。以下是它们的主要特点和区别&#xff1a; HTTP (HyperText Transfer Protocol): 请求-响应模型&#xff1a; HTTP 是基于请求-响应模型的协…

监督学习 - 逻辑回归(Logistic Regression)

什么是机器学习 逻辑回归&#xff08;Logistic Regression&#xff09;虽然名字中包含"回归"一词&#xff0c;但实际上是一种用于解决分类问题的统计学习方法&#xff0c;而不是回归问题。它是一种线性模型&#xff0c;常用于二分类问题&#xff0c;也可以扩展到多分…

JMeter测试工具(性能篇)

自动化脚本 设置全局变量 断言 接口弱压力测试 模拟半小时之内1000个用户访问服务器资源&#xff0c;要求平均响应时间在3000ms内&#xff0c;且错误率为0 模拟100个用户同时访问服务器资源&#xff0c;要求平均响应时间在3000毫秒内&#xff0c;且错误率为0 高并发 模拟2个…

幻兽帕鲁服务器创建私服教程(新版教程更简单)

幻兽帕鲁官方服务器不稳定&#xff1f;自己搭建幻兽帕鲁服务器&#xff0c;低延迟、稳定不卡&#xff0c;目前阿里云和腾讯云均推出幻兽帕鲁专用服务器&#xff0c;腾讯云直接提供幻兽帕鲁镜像系统&#xff0c;阿里云通过计算巢服务&#xff0c;均可以一键部署&#xff0c;鼠标…

The Back-And-Forth Method (BFM) for Wasserstein Gradient Flows windows安装

本文记录了BFM算法代码在windows上的安装过程。 算法原网站&#xff1a;https://wasserstein-gradient-flows.netlify.app/ github&#xff1a;https://github.com/wonjunee/wgfBFMcodes 文章目录 FFTWwgfBFMcodesMATLABpython注 FFTW 官网/下载路径&#xff1a;https://ww…

多线程JUC:等待唤醒机制(生产者消费者模式)

&#x1f468;‍&#x1f393;作者简介&#xff1a;一位大四、研0学生&#xff0c;正在努力准备大四暑假的实习 &#x1f30c;上期文章&#xff1a;多线程&JUC&#xff1a;解决线程安全问题——synchronized同步代码块、Lock锁 &#x1f4da;订阅专栏&#xff1a;多线程&am…

MyBatis之动态代理实现增删改查以及MyBatis-config.xml中读取DB信息文件和SQL中JavaBean别名配置

MyBatis之环境搭建以及实现增删改查 前言实现步骤1. 编写MyBatis-config.xml配置文件2. 编写Mapper.xml文件&#xff08;增删改查SQL文&#xff09;3. 定义PeronMapper接口4. 编写测试类1. 执行步骤2. 代码实例3. 运行log 开发环境构造图总结 前言 上一篇文章&#xff0c;我们…

vue3 之 商城项目—一级分类

整体认识和路由配置 场景&#xff1a;点击哪个分类跳转到对应的路由页面&#xff0c;路由传对应的参数 router/index.js import { createRouter, createWebHashHistory } from vue-router import Layout from /views/Layout/index.vue import Home from /views/Home/index.vu…

作业2.8

1、选择题 1.1、以下选项中,不能作为合法常量的是 ____B______ A&#xff09;1.234e04 B&#xff09;1.234e0.4 C&#xff09;1.234e4 D&#xff09;1.234e0 1.2、以下定义变量并初始化错误的是_____D________。 A) char c1 ‘H’ &#xff1b; B) char c…