namespace Mapbox.Unity.Location { using System; using Mapbox.Unity.Map; using Mapbox.Unity.Utilities; using Mapbox.Utils; using UnityEngine; /// /// The TransformLocationProvider is responsible for providing mock location and heading data /// for testing purposes in the Unity editor. /// This is achieved by querying a Unity Transform every frame. /// You might use this to to update location based on a touched position, for example. /// public class TransformLocationProvider : AbstractEditorLocationProvider { /// /// The transform that will be queried for location and heading data. /// [SerializeField] Transform _targetTransform; /// /// Sets the target transform. /// Use this if you want to switch the transform at runtime. /// public Transform TargetTransform { set { _targetTransform = value; } } protected override void SetLocation() { var _map = LocationProviderFactory.Instance.mapManager; _currentLocation.UserHeading = _targetTransform.eulerAngles.y; _currentLocation.LatitudeLongitude = _targetTransform.GetGeoPosition(_map.CenterMercator, _map.WorldRelativeScale); _currentLocation.Accuracy = _accuracy; _currentLocation.Timestamp = UnixTimestampUtils.To(DateTime.UtcNow); _currentLocation.IsLocationUpdated = true; _currentLocation.IsUserHeadingUpdated = true; } } }