/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR. */ using System.Collections.Generic; using OmiLAXR.Listeners; using OmiLAXR.Filters; using OmiLAXR.TrackingBehaviours; using UnityEngine; namespace OmiLAXR { /// /// Generic base class for creating modular pipeline extensions that target specific pipeline types. /// Automatically discovers and registers child components with the target pipeline during initialization. /// Executes early in Unity's order to ensure extensions are applied before pipeline startup. /// /// Specific type of Pipeline this extension targets [DefaultExecutionOrder(-100)] // Execute before most components but after GlobalSettings public abstract class PipelineExtension : PipelineComponent, IPipelineExtension where T : Pipeline { /// /// Reference to the specific Pipeline instance this extension is attached to. /// Strongly typed to the generic parameter for type-safe access to pipeline-specific functionality. /// public T Pipeline { get; protected set; } /// /// Gets the Pipeline as the base Pipeline type for interface compliance. /// Required by IPipelineExtension interface for polymorphic access. /// /// The Pipeline instance cast to the base Pipeline type public Pipeline GetPipeline() => Pipeline; /// /// Collection of Listener components discovered in child objects. /// Listeners detect and report objects for pipeline processing. /// public readonly List Listeners = new List(); /// /// Collection of TrackingBehaviour components discovered in child objects. /// TrackingBehaviours monitor and analyze detected objects for learning analytics. /// public readonly List TrackingBehaviours = new List(); /// /// Collection of Filter components discovered in child objects. /// Filters refine the set of objects that proceed through the pipeline. /// public readonly List Filters = new List(); /// /// Unity Awake callback that automatically discovers and extends the target pipeline. /// Searches for the target pipeline type and initiates the extension process. /// private void Awake() { // Find the target pipeline instance in the scene var pipeline = FindObject(); Extend(pipeline); } /// /// Extends the specified Pipeline with components found in this extension's hierarchy. /// Automatically discovers and registers all child Listeners, TrackingBehaviours, and Filters. /// Maintains local collections for extension management while integrating with the target pipeline. /// /// The Pipeline instance to extend with additional capabilities public void Extend(Pipeline pipeline) { // Cache the strongly-typed pipeline reference Pipeline = (T)pipeline; // Discover all extension components in child objects var listeners = gameObject.GetComponentsInChildren(); var tbs = gameObject.GetComponentsInChildren(); var filters = gameObject.GetComponentsInChildren(); // Store references locally for extension management Listeners.AddRange(listeners); TrackingBehaviours.AddRange(tbs); Filters.AddRange(filters); // Register components with the target pipeline Pipeline.Listeners.AddRange(listeners); Pipeline.TrackingBehaviours.AddRange(tbs); Pipeline.Filters.AddRange(filters); Pipeline.Extensions.Add(this); // Log successful extension for debugging DebugLog.OmiLAXR.Print("Extended pipeline " + pipeline); } } }