// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) 2022-2023 Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Magic Leap 2 Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% using System; using UnityEngine; namespace MagicLeap.Spectator { public class MLSpectatorFollow : MonoBehaviour { public event Action onPoseUpdated = null; private Vector3 position = Vector3.zero; private Quaternion rotation = Quaternion.identity; void Update() { if (MLSpectator.Instance == null) return; //if (!transform.parent.hasChanged) return; bool parentTransformChanged = false; if (transform.parent.position != position) { parentTransformChanged = true; position = transform.parent.position; } if (transform.parent.rotation != rotation) { parentTransformChanged = true; rotation = transform.parent.rotation; } if (!parentTransformChanged) return; Pose pose = new Pose(transform.position, transform.rotation); onPoseUpdated?.Invoke(pose); } } }