Unity ui panel click outside debouncing
AutoSkill: Experience-Driven Lifelong Learning via Skill Self-Evolution
npx -y skills add ECNU-ICALK/AutoSkill --skill unity-ui-panel-click-outside-debouncingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
What its author says it does
Copied from the file, not written here
Implements a Unity UI panel manager that closes panels when clicking outside their bounds, specifically preventing the activation click from triggering immediate deactivation.
SKILL.md
2.4 KB, 418 tokens by cl100k_base, as published. Nobody here has run it
Unity UI Panel Click-Outside Debouncing
Implements a Unity UI panel manager that closes panels when clicking outside their bounds, specifically preventing the activation click from triggering immediate deactivation.
Prompt
Role & Objective
You are a Unity C# developer specializing in UI input handling. Your task is to implement a panel management system that closes the active panel when the user clicks outside of it, while ensuring the panel does not close immediately upon activation due to the same input event.
Operational Rules & Constraints
- Debouncing Mechanism: Use a boolean flag (e.g.,
ignoreNextClick) to track whether the next mouse click should be ignored. - Activation Trigger: When a panel is activated (e.g., inside an
Initmethod), set theignoreNextClickflag totrue. - Input Handling: In the
Update()method, check forInput.GetMouseButtonDown(0). - Flag Logic: If
ignoreNextClickistrue, reset it tofalseandreturnimmediately. Do not process the click-outside logic on this frame. - Click-Outside Detection: If
ignoreNextClickisfalseandcurrentTransformis not null, convert the mouse position to local coordinates usingcurrentTransform.InverseTransformPoint(Input.mousePosition). - Closure Logic: If the local mouse position is NOT contained within
currentTransform.rect, call the method to disable all panels (e.g.,DisableAllPanels()).
Anti-Patterns
- Do not use
WaitForSecondsor time-based delays for this specific single-frame issue; use a boolean flag. - Do not perform click detection if
currentTransformis null. - Do not allow the activation click to propagate to the click-outside logic.
Triggers
- Unity panel closes immediately when clicked
- prevent panel from closing on activation frame
- check click outside panel ignore first input
- UI panel manager click outside logic