AutoSkill 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.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/unity-panel-click-outside-debounce-logic" ~/.claude/skills/ecnu-icalk-autoskill-unity-panel-click-outside-debounce-logic && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/unity-panel-click-outside-debounce-logic/SKILL.mdsource content
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.,
) to track this state.ignoreNextClick - Activation Logic: When the panel is initialized or activated (e.g., in an
method), set the debounce flag toInit
.true - Update Logic: In the method checking for input (e.g.,
orUpdate
):CheckClickOutsidePanel- Check if the debounce flag is
.true - If
, reset the flag totrue
andfalse
immediately, ignoring the click.return - If
, proceed with the standard logic to check if the click is outside the panel's RectTransform.false
- Check if the debounce flag is
Anti-Patterns
- Do not use
or timers for this specific one-frame delay; a boolean flag is the correct approach.Time.deltaTime - Do not rely on
if the issue stems fromOnMouseDown
inInput.GetMouseButtonDown
.Update
Triggers
- panel closes immediately after opening
- click outside panel unity
- ignore input on activation
- unity ui click debounce