using QSB.SectorSync.WorldObjects; using UnityEngine; namespace QSB.TransformSync { internal class IntermediaryTransform { private Transform _attachedTransform; private QSBSector _referenceSector; public IntermediaryTransform(Transform transform) => _attachedTransform = transform; /// /// Get the world position of this INVISIBLE transform. /// public Vector3 GetPosition() => _attachedTransform.position; /// /// Set the world position of this INVISIBLE transform. /// public void SetPosition(Vector3 worldPos) => _attachedTransform.position = worldPos; /// /// Get the world rotation of this INVISIBLE transform. /// public Quaternion GetRotation() => _attachedTransform.rotation; /// /// Set the world rotation of this INVISIBLE transform. /// public void SetRotation(Quaternion worldRot) => _attachedTransform.rotation = worldRot; /// /// Sets the reference sector - what sector this transform is syncing to. /// /// The new reference sector. public void SetReferenceSector(QSBSector sector) => _referenceSector = sector; /// /// Sets the position of the INVISIBLE transform to be correct, according to the reference sector and the position of the VISIBLE transform. /// /// The world position of the VISIBLE transform. public void EncodePosition(Vector3 worldPosition) => SetPosition(_referenceSector.Transform.InverseTransformPoint(worldPosition)); /// /// Sets the rotation of the INVISIBLE transform to be correct, according to the reference sector and the rotation of the VISIBLE transform. /// /// The world rotation of the VISIBLE transform. public void EncodeRotation(Quaternion worldRotation) => SetRotation(_referenceSector.Transform.InverseTransformRotation(worldRotation)); /// /// Gets what the VISIBLE transform's position should be, from the reference sector and the position of the INVISIBLE transform. /// public Vector3 GetTargetPosition() => GetPosition(); /// /// Gets what the VISIBLE transform's rotation should be, from the reference sector and the rotation of the INVISIBLE transform. /// public Quaternion GetTargetRotation() => GetRotation(); } }