/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR. */ using System.ComponentModel; using OmiLAXR.Components; using OmiLAXR.Extensions; using UnityEngine; using UnityEngine.UI; namespace OmiLAXR.Listeners { /// /// Specialized listener for Unity UI Selectable components (buttons, toggles, sliders, etc.). /// Automatically detects UI elements and optionally adds interaction tracking components. /// Provides comprehensive support for tracking user interactions with UI elements, /// including clicks, selections, and other user interface events. /// [AddComponentMenu("OmiLAXR / 1) Listeners / Objects Listener")] [Description("Provides all components to pipeline.")] public sealed class SelectableObjectsListener : Listener { /// /// Whether to include inactive/disabled selectable objects in the detection. /// When true, finds selectables even if their GameObjects are currently inactive. /// Useful for tracking all potential UI interactions, not just currently active ones. /// public bool includeInactive = true; /// /// Whether to automatically add InteractionEventHandler components to detected selectables. /// When true, ensures each selectable has the necessary tracking component for analytics. /// Automatically enhances UI elements with interaction tracking capabilities. /// public bool addInteractionEventHandler = true; /// /// Initiates detection of all Selectable UI components in the scene. /// Optionally adds InteractionEventHandler components for comprehensive interaction tracking. /// Provides flexibility in handling both active and inactive UI elements. /// public override void StartListening() { // Find all selectable components, respecting the includeInactive setting var selectables = FindObjects(includeInactive); // Optionally add interaction event handlers for tracking if (addInteractionEventHandler) { foreach (var selectable in selectables) { // Only add the handler if it doesn't already exist selectable.gameObject.EnsureComponent(); } } // Report the found selectables to the pipeline Found(selectables); } } }