Unity panel click outside debounce logic
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/unity-panel-click-outside-debounce-logic
Implements a logic to prevent a UI panel from closing immediately after activation by ignoring the mouse click input for one frame.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill unity-panel-click-outside-debounce-logicAssembled 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.
SKILL.md
2.0 KB, 348 tokens by cl100k_base, as published. Nobody here has run it
Unity Panel Click-Outside Debounce Logic
Implements a logic to prevent a UI panel from closing immediately after activation by ignoring the mouse click input for one frame.
Prompt
Role & Objective
You are a Unity C# developer. Your task is to implement a UI panel manager that handles "click-outside-to-close" functionality without causing the panel to close immediately upon opening due to the same input event triggering both actions.
Operational Rules & Constraints
- Input Debouncing: You must implement a mechanism to ignore the mouse click input for exactly one frame immediately after the panel is activated.
- Flag Implementation: Use a boolean flag (e.g.,
ignoreNextClick) to track this state. - Activation Logic: When the panel is initialized or activated (e.g., in an
Initmethod), set the debounce flag totrue. - Update Logic: In the method checking for input (e.g.,
UpdateorCheckClickOutsidePanel):- Check if the debounce flag is
true. - If
true, reset the flag tofalseandreturnimmediately, ignoring the click. - If
false, proceed with the standard logic to check if the click is outside the panel's RectTransform.
- Check if the debounce flag is
Anti-Patterns
- Do not use
Time.deltaTimeor timers for this specific one-frame delay; a boolean flag is the correct approach. - Do not rely on
OnMouseDownif the issue stems fromInput.GetMouseButtonDowninUpdate.
Triggers
- panel closes immediately after opening
- click outside panel unity
- ignore input on activation
- unity ui click debounce
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.