This document summarizes the refactorization of the click management system in the RPG-RougeLiteBatteler project. The goal was to replace the tightly coupled click handling in TeamTravelSystem with a modular, extensible system that allows UI components to handle their own click logic.
The original system in TeamTravelSystem.cs had several issues:
TravelUI, CombatEventPopupUXML)IClickBlocker InterfaceAssets/Scripts/UI/IClickBlocker.csbool IsBlockingClick(Vector2 screenPosition)ClickManager ClassAssets/Scripts/UI/ClickManager.csTravelUI ClassIClickBlocker interfaceClickManager on Enable/Disable/DestroyIsPointWithinUI() method now delegates to IsBlockingClick()CombatEventPopupUXML ClassIClickBlocker interfaceClickManager on Enable/Disable/DestroyIsPointWithinUI() method now delegates to IsBlockingClick()TeamTravelSystem ClassCombatEventPopupUXMLHandleInput() method to use ClickManager.Instance.IsClickBlocked()IsTravelUIBlocking() dependency on combat popupUI components automatically register themselves with the ClickManager:
void OnEnable()
{
if (ClickManager.Instance != null)
ClickManager.Instance.RegisterClickBlocker(this);
}
void OnDisable()
{
if (ClickManager.Instance != null)
ClickManager.Instance.UnregisterClickBlocker(this);
}
The travel system now uses a single, clean check:
if (ClickManager.Instance != null && ClickManager.Instance.IsClickBlocked(Input.mousePosition))
{
return; // Block map interaction
}
Existing code that calls IsPointWithinUI() continues to work as these methods now delegate to the new IsBlockingClick() implementation.
IClickBlocker and auto-registerTo add a new UI component that blocks clicks:
Implement IClickBlocker interface:
public class MyNewUI : MonoBehaviour, IClickBlocker
{
public bool IsBlockingClick(Vector2 screenPosition)
{
// Your click detection logic here
return isVisible && IsWithinBounds(screenPosition);
}
}
Add registration in lifecycle methods:
void OnEnable() => ClickManager.Instance?.RegisterClickBlocker(this);
void OnDisable() => ClickManager.Instance?.UnregisterClickBlocker(this);
void OnDestroy() => ClickManager.Instance?.UnregisterClickBlocker(this);
That's it! The travel system will automatically respect your UI's click blocking.
A test script ClickManagerTest.cs is provided to verify the system works correctly:
Assets/Scripts/UI/ClickManager.cs (NEW)Assets/Scripts/UI/IClickBlocker.cs (NEW)Assets/Scripts/UI/ClickManagerTest.cs (NEW)Assets/Scripts/UI/TravelUI.cs (MODIFIED)Assets/Scripts/UI/CombatEventPopupUXML.cs (MODIFIED)Assets/Scripts/Map/TeamTravelSystem.cs (MODIFIED)