Unity Events Integration
HookUI is designed to handle users navigating MENUS. But menus are just the gateway to the GAME.
The HookUI View Inspector
Every HookView has four standard events exposed in the Inspector:
- OnShowStarted: Best for pausing the game (
Time.timeScale = 0). - OnShowFinished: Best for enabling input.
- OnHideStarted: Best for disabling input.
- OnHideFinished: Best for unpausing (
Time.timeScale = 1).
Example: Pause Menu
- Create View: ID
PauseMenu. - OnShowStarted: Drag your
GameManagerscript and callGameManager.PauseGame(). - OnHideFinished: Drag your
GameManagerscript and callGameManager.ResumeGame().
Connecting Buttons to Logic
Buttons are not just for navigation.
- Play Button: Needs to load a scene.
- Settings Button: Just navigates.
- Save Button: Needs to write to disk.
For the Play Button (which navigates to a Loading Screen), you can attach a script to the same GameObject:
public class SceneLoader : MonoBehaviour
{
private HookButton _btn;
void Awake() {
_btn = GetComponent<HookButton>();
_btn.OnClick.AddListener(LoadLevel);
}
void LoadLevel() {
SceneManager.LoadScene("Level1");
}
}
Or just use the OnClick event in the Inspector directly.