Version: 2023.1

描述

当播放器应用程序想要退出时,Unity 会引发此事件。

向此事件添加一个事件处理程序,以便接收关于应用程序试图退出的通知。

引发此事件时,退出过程已开始但可以取消。这意味着播放器并不保证退出。有关保证退出事件,请查看 Application.quitting

Returns true and the quit process continues. Returns false and the quit process cancels.

Note: The return value of this event is ignored when exiting Play mode in the Editor.

Important: The return value has no effect on iOS or iPadOS. The Application._wantsToQuit can't prevent termination in iOS or iPadOS.

using UnityEngine;

public class PlayerWantsToQuitExample { static bool WantsToQuit() { Debug.Log("Player prevented from quitting."); return false; }

[RuntimeInitializeOnLoadMethod] static void RunOnStart() { Application.wantsToQuit += WantsToQuit; } }

另请参阅:Application.quitting