/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR. */ namespace OmiLAXR { /// /// Abstract base class for pipeline components that need access to Actor and Pipeline functionality. /// Provides automatic pipeline discovery through component hierarchy and extension system. /// Includes logging utilities with pipeline context information. /// public abstract class ActorPipelineComponent : PipelineComponent { /// /// Cached reference to the associated Pipeline component. /// Automatically discovered through component hierarchy or extension system. /// private Pipeline _pipeline; /// /// Gets the Pipeline component associated with this component. /// Uses intelligent discovery to find pipelines through: /// 1. Direct component attachment /// 2. Parent hierarchy search /// 3. Pipeline extension system /// public Pipeline Pipeline { get { // Return cached pipeline if available if (!_pipeline) { // Try to find pipeline on same GameObject or in parent hierarchy #if UNITY_2020_1_OR_NEWER _pipeline = GetComponent() ?? GetComponentInParent(true); #else // Unity 2019 and earlier don't support includeInactive parameter _pipeline = GetComponent() ?? GetComponentInParent(true); #endif } // Return pipeline if found through standard hierarchy if (_pipeline) return _pipeline; // Fallback: Look for Pipeline through extension system // This handles cases where pipelines are extended or wrapped var pipelineExt = GetComponentInParent(); _pipeline = pipelineExt.GetPipeline(); return _pipeline; } } /// /// Gets the Actor component associated with this pipeline. /// Provides access to the learner/user being tracked by this pipeline. /// /// The Actor component representing the tracked entity public Actor GetActor() => Pipeline.actor; /// /// Gets the Instructor component that manages this pipeline. /// Provides access to the learning management and analytics coordination. /// /// The Instructor component managing this pipeline public Instructor GetInstructor() => Pipeline.instructor; /// /// Logs a formatted message with pipeline context information. /// Automatically prefixes messages with the pipeline name for easier debugging. /// /// Format string for the log message /// Parameters for string formatting protected void Log(string message, params object[] ps) => DebugLog.OmiLAXR.Print($"(Pipeline '{Pipeline.name}') " + message); } }