UGameViewportClient::FOnWindowCloseRequested用法
时间: 2023-07-02 15:08:02 浏览: 40
UGameViewportClient::FOnWindowCloseRequested是一个委托事件,用于在游戏窗口关闭请求时触发自定义逻辑。在UE4中,窗口关闭请求可以由用户点击“关闭”按钮、按下“Alt + F4”组合键或操作系统发送关闭信号等方式触发。
下面是一个使用UGameViewportClient::FOnWindowCloseRequested的示例:
```cpp
// 在你的GameViewportClient类中声明FOnWindowCloseRequested委托事件
DECLARE_DELEGATE(FOnWindowCloseRequested);
class YourGameViewportClient : public UGameViewportClient
{
public:
// 注册FOnWindowCloseRequested事件处理函数
virtual void Init(struct FWorldContext& WorldContext, UGameInstance* OwningGameInstance, bool bCreateNewAudioDevice) override
{
Super::Init(WorldContext, OwningGameInstance, bCreateNewAudioDevice);
OnWindowCloseRequested.BindUObject(this, &YourGameViewportClient::HandleWindowCloseRequested);
}
private:
// 定义FOnWindowCloseRequested事件处理函数
void HandleWindowCloseRequested()
{
UE_LOG(LogTemp, Warning, TEXT("Window close requested!"));
// 在这里添加你的自定义逻辑
}
// 声明FOnWindowCloseRequested事件
FOnWindowCloseRequested OnWindowCloseRequested;
};
```
在上面的示例中,我们首先在自定义的GameViewportClient类中声明了一个FOnWindowCloseRequested委托事件,并在Init函数中注册了事件处理函数HandleWindowCloseRequested。每当用户请求关闭游戏窗口时,就会触发OnWindowCloseRequested事件,并调用HandleWindowCloseRequested函数。在HandleWindowCloseRequested函数中,我们可以添加任何自定义逻辑。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)