using System; using UnityEngine; using UnityEngine.Events; namespace OmiLAXR.Components { [RequireComponent(typeof(TransformWatcher))] public class TransformWatcherEvents : MonoBehaviour { /// /// Event triggered when position changes exceed the defined threshold. /// Provides the old and new position values. /// [Tooltip("Event triggered when position changes exceed the threshold")] public UnityEvent onChangedPosition = new UnityEvent(); /// /// Event triggered when scale changes exceed the defined threshold. /// Provides the old and new scale values. /// [Tooltip("Event triggered when scale changes exceed the threshold")] public UnityEvent onChangedScale = new UnityEvent(); /// /// Event triggered when rotation changes exceed the defined threshold. /// Provides the old and new rotation values in Euler angles. /// [Tooltip("Event triggered when rotation changes exceed the threshold")] public UnityEvent onChangedRotation = new UnityEvent(); [Tooltip("Event triggered when forward changes exceed the threshold")] public UnityEvent onChangedForward = new UnityEvent(); private TransformWatcher _transformWatcher; private void Awake() { _transformWatcher = GetComponent(); } private void Update() { var state = _transformWatcher.GetTransformChangeState(); if (state.Position.HasChanged) onChangedPosition?.Invoke(state.Position); if (state.Rotation.HasChanged) onChangedRotation?.Invoke(state.Rotation); if (state.Scale.HasChanged) onChangedScale?.Invoke(state.Scale); if (state.Forward.HasChanged) onChangedForward?.Invoke(state.Forward); } } }