/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR. */ using System; using System.ComponentModel; using UnityEngine; namespace OmiLAXR.TrackingBehaviours.Learner { /// /// Tracks session lifecycle events including start and stop. /// Automatically handles pipeline lifecycle and application shutdown events. /// [AddComponentMenu("OmiLAXR / 3) Tracking Behaviours / Session Tracking Behaviour")] [Description("Tracks the start and end of a session.")] public class SessionTrackingBehaviour : TrackingBehaviour { /// /// Indicates if a session is currently running. /// private bool _isRunning; /// /// Event triggered when a session starts. /// public readonly TrackingBehaviourEvent OnSessionStarted = new TrackingBehaviourEvent(); /// /// Event triggered when a session stops. /// public readonly TrackingBehaviourEvent OnSessionStopped = new TrackingBehaviourEvent(); /// /// Called when the pipeline starts. Triggers session start if not already running. /// protected override void BeforeStartedPipeline(Pipeline pipeline) { if (_isRunning) return; OnSessionStarted.Invoke(this, DateTime.Now); _isRunning = true; } /// /// Called when the pipeline stops. Triggers session end. /// protected override void BeforeStoppedPipeline(Pipeline pipeline) { TriggerEnd(); } /// /// Ends the current session if one is running. /// private void TriggerEnd() { if (!_isRunning) return; OnSessionStopped.Invoke(this, DateTime.Now); _isRunning = false; } } }