/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR. */ using UnityEngine; using UnityEngine.Events; using UnityEngine.Serialization; namespace OmiLAXR.Components { /// /// Component that monitors and broadcasts GameObject state changes. /// Provides UnityEvents that can be subscribed to for handling destruction, enabling, and disabling events. /// public sealed class GameObjectStateWatcher : MonoBehaviour { /// /// UnityEvent invoked when the GameObject is destroyed. /// Passes the GameObject reference as a parameter. /// [FormerlySerializedAs("OnDestroyed")] public UnityEvent onDestroyed = new UnityEvent(); /// /// UnityEvent invoked when the GameObject is enabled. /// Passes the GameObject reference as a parameter. /// [FormerlySerializedAs("OnEnabled")] public UnityEvent onEnabled = new UnityEvent(); /// /// UnityEvent invoked when the GameObject is disabled. /// Passes the GameObject reference as a parameter. /// [FormerlySerializedAs("OnDisabled")] public UnityEvent onDisabled = new UnityEvent(); /// /// Called when the GameObject is destroyed. /// Triggers the onDestroyed event. /// private void OnDestroy() { onDestroyed?.Invoke(gameObject); } /// /// Called when the GameObject becomes enabled and active. /// Triggers the onEnabled event. /// private void OnEnable() { onEnabled?.Invoke(gameObject); } /// /// Called when the GameObject becomes disabled. /// Triggers the onDisabled event. /// private void OnDisable() { onDisabled?.Invoke(gameObject); } } }