Easily manage a stack of objects that respond to the ESC button / Android Back button in Unity, so that only the top object handles the event.
Check out the Popup Stack sample scene for some usage example.
- Only the last object in the stack will be called when the ESC/Back button is pressed.
- Inherit ABackButtonHandler to have scripts that handle the ESC/Back button be inserted/removed from the singleton stack automatically in their
OnEnable/OnDisablemethods. - Supports pure C# classes as well, just implement the IBackButtonHandler interface and call
AddToBackButtonStackandRemoveFromBackButtonStackto add / remove it from the singleton stack. - Custom inspector for debugging which objects are currently in the stack, just select the
BackButtonStackobject in theDontDestroyOnLoadscene while in Play Mode.
Either:
- Use the openupm registry and install this package using the openupm-cli:
openupm add com.gilzoide.back-button-stack - Install using the Unity Package Manager with the following URL:
https://github.com/gilzoide/unity-back-button-stack.git#1.0.0 - Clone this repository or download a snapshot of it directly inside your project's
AssetsorPackagesfolder.