// Portfolio reconstruction, 2026. Not original production source. // Models rotation-dependent sensor selection; no proprietary sensor SDK or data. using System; using UnityEngine; public sealed class RotationSensorSelector : MonoBehaviour { [Serializable] public class Source { public Transform calibratedPose; // All poses must already share world coordinates. public float bestFacingYaw; public bool tracked = true; // Set by the sensor adapter, including stale-data handling. } [SerializeField] Transform rig; [SerializeField] Transform output; [SerializeField] Source[] sources; [SerializeField, Min(0)] float switchMarginDegrees = 12; [SerializeField, Min(0.001f)] float blendSeconds = 0.15f; int selected = -1; bool Valid(int i) => sources != null && i >= 0 && i < sources.Length && sources[i] != null && sources[i].tracked && sources[i].calibratedPose != null; void LateUpdate() { if (rig == null || output == null || sources == null) return; float yaw = rig.eulerAngles.y; int best = -1; float bestError = float.PositiveInfinity; for (int i = 0; i < sources.Length; i++) { if (!Valid(i)) continue; float error = Mathf.Abs(Mathf.DeltaAngle(yaw, sources[i].bestFacingYaw)); if (error < bestError) { best = i; bestError = error; } } if (best < 0) { selected = -1; return; } // Hold the last pose on complete tracking loss. float currentError = Valid(selected) ? Mathf.Abs(Mathf.DeltaAngle(yaw, sources[selected].bestFacingYaw)) : float.PositiveInfinity; if (!Valid(selected) || bestError + switchMarginDegrees < currentError) selected = best; Transform pose = sources[selected].calibratedPose; float alpha = 1 - Mathf.Exp(-Time.deltaTime / Mathf.Max(0.001f, blendSeconds)); output.SetPositionAndRotation(Vector3.Lerp(output.position, pose.position, alpha), Quaternion.Slerp(output.rotation, pose.rotation, alpha)); } }