From fefe010fe65d9beffd6740d69632a0c6390d4987 Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Thu, 13 Apr 2017 10:33:22 -0600 Subject: [PATCH 1/5] Initial check-in of location providers. --- .../Assets/Mapbox/Core/Unity/Location.meta | 9 ++ .../Unity/Location/DeviceLocationProvider.cs | 94 ++++++++++++++++ .../Location/DeviceLocationProvider.cs.meta | 12 +++ .../Unity/Location/EditorLocationProvider.cs | 101 ++++++++++++++++++ .../Location/EditorLocationProvider.cs.meta | 12 +++ .../Core/Unity/Location/ILocationProvider.cs | 29 +++++ .../Unity/Location/ILocationProvider.cs.meta | 12 +++ .../Core/Unity/Location/LocationLogger.cs | 98 +++++++++++++++++ .../Unity/Location/LocationLogger.cs.meta | 12 +++ .../Unity/Location/LocationProviderFactory.cs | 82 ++++++++++++++ .../Location/LocationProviderFactory.cs.meta | 12 +++ .../Location/TransformLocationProvider.cs | 52 +++++++++ .../TransformLocationProvider.cs.meta | 12 +++ 13 files changed, 537 insertions(+) create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs.meta diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location.meta b/sdkproject/Assets/Mapbox/Core/Unity/Location.meta new file mode 100644 index 000000000..bd3ee01d3 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8ef01f907e34d4888af041661232ec58 +folderAsset: yes +timeCreated: 1492101090 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs new file mode 100644 index 000000000..289c6c288 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs @@ -0,0 +1,94 @@ +using System.Collections; +using UnityEngine; +using Scripts.Location; +using System; + +namespace Location +{ + public class DeviceLocationProvider : MonoBehaviour, ILocationProvider + { + Coroutine _pollRoutine; + + float _lastHeading; + + double _lastTimestamp; + + Vector2 _location; + public Vector2 Location + { + get + { + return _location; + } + } + + public event EventHandler OnLocationUpdated; + public event EventHandler OnHeadingUpdated; + + void Start() + { + if (_pollRoutine == null) + { + _pollRoutine = StartCoroutine(PollLocationRoutine()); + } + } + + IEnumerator PollLocationRoutine() + { + if (!Input.location.isEnabledByUser) + { + yield break; + } + Input.location.Start(5f, 5f); + Input.compass.enabled = true; + + int maxWait = 20; + while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) + { + yield return new WaitForSeconds(1); + maxWait--; + } + + if (maxWait < 1) + { + yield break; + } + + if (Input.location.status == LocationServiceStatus.Failed) + { + yield break; + } + + while (true) + { + var heading = Input.compass.trueHeading; + SendHeadingUpdated(heading); + + var timestamp = Input.location.lastData.timestamp; + if (Input.location.status == LocationServiceStatus.Running && timestamp > _lastTimestamp) + { + _location = new Vector2(Input.location.lastData.latitude, Input.location.lastData.longitude); + SendLocationUpdated(_location); + _lastTimestamp = timestamp; + } + yield return null; + } + } + + void SendHeadingUpdated(float heading) + { + if (OnHeadingUpdated != null) + { + OnHeadingUpdated(this, new HeadingUpdatedEventArgs() { Heading = heading }); + } + } + + void SendLocationUpdated(Vector2 location) + { + if (OnLocationUpdated != null) + { + OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = location}); + } + } + } +} \ No newline at end of file diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs.meta new file mode 100644 index 000000000..8b9422519 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0a38712e93231418a84665190b8473d0 +timeCreated: 1484075762 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs new file mode 100644 index 000000000..413aad877 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections; +using Mapbox.Geocoding; +using Mapbox.Scripts.Utilities; +using UnityEngine; + +namespace Scripts.Location +{ + public class EditorLocationProvider : MonoBehaviour, ILocationProvider + { + [SerializeField] + string _forwardGeocodeQuery; + + [SerializeField] + float _latitude; + + [SerializeField] + float _longitude; + + [SerializeField] + [Range(0, 359)] + float _heading; + + ForwardGeocodeResource _resource; + + Coroutine _updateLocationRoutine; + + Vector2 _location; + public Vector2 Location + { + get + { + return _location; + } + } + + public event EventHandler OnHeadingUpdated; + public event EventHandler OnLocationUpdated; + + void Start() + { + _resource = new ForwardGeocodeResource(""); + + if (!string.IsNullOrEmpty(_forwardGeocodeQuery)) + { + _resource.Query = _forwardGeocodeQuery; + MapboxConvenience.Instance.Geocoder.Geocode(_resource, HandleGeocoderResponse); + } + else + { + _updateLocationRoutine = StartCoroutine(UpdateLocationRoutine()); + } + } + + void Update() + { + if (OnHeadingUpdated != null) + { + OnHeadingUpdated(this, new HeadingUpdatedEventArgs() { Heading = _heading }); + } + } + + void HandleGeocoderResponse(ForwardGeocodeResponse response) + { + var geocoords = response.Features[0].Center; + UpdateLocation((float)geocoords.Latitude, (float)geocoords.Longitude); + } + + IEnumerator UpdateLocationRoutine() + { + while (true) + { + _location = new Vector2(_latitude, _longitude); + SendLocationUpdated(); + yield return new WaitForSeconds(1f); + } + } + + [ContextMenu("Update location")] + public void UpdateLocation(float lat, float lon) + { + _latitude = lat; + _longitude = lon; + + if (_updateLocationRoutine != null) + { + StopCoroutine(_updateLocationRoutine); + _updateLocationRoutine = null; + } + _updateLocationRoutine = StartCoroutine(UpdateLocationRoutine()); + } + + void SendLocationUpdated() + { + if (OnLocationUpdated != null) + { + OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = _location }); + } + } + } +} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs.meta new file mode 100644 index 000000000..1a3c27e81 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 60712efc3153a4819b0c79437175846d +timeCreated: 1484085721 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs new file mode 100644 index 000000000..d17e58971 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs @@ -0,0 +1,29 @@ +using System; +using UnityEngine; + +namespace Scripts.Location +{ + public interface ILocationProvider + { + event EventHandler OnLocationUpdated; + event EventHandler OnHeadingUpdated; + Vector2 Location { get; } + } + + public class LocationUpdatedEventArgs: EventArgs + { + public Vector2 Location; + } + + public class HeadingUpdatedEventArgs : EventArgs + { + public float Heading; + } + + class LocationProviderMissingException : Exception + { + public LocationProviderMissingException(string message) : base(message) + { + } + } +} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs.meta new file mode 100644 index 000000000..e4fab6c3f --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7acec3aa2711f4ec0894a6d98ee70436 +timeCreated: 1484081764 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs new file mode 100644 index 000000000..4b11fbbe3 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs @@ -0,0 +1,98 @@ +using Mapbox.Geocoding; +using Mapbox.Scripts.Utilities; +using UnityEngine; +using UnityEngine.UI; +using Mapbox; +using System.Linq; + +namespace Scripts.Location +{ + public class LocationLogger : MonoBehaviour + { + [SerializeField] + Text _locationText; + + [SerializeField] + Text _latitudeText; + + Geocoder _geocoder; + bool _hasResponse; + GeoCoordinate _coordinate; + private ReverseGeocodeResource _resource; + private float _timerMax = 1; + private float _timer; + + ILocationProvider _locationProvider; + public ILocationProvider LocationProvider + { + private get + { + if (_locationProvider == null) + { + _locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; + } + + return _locationProvider; + } + set + { + if (_locationProvider != null) + { + _locationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated; + _locationProvider.OnHeadingUpdated -= LocationProvider_OnHeadingUpdated; + } + _locationProvider = value; + _locationProvider.OnHeadingUpdated += LocationProvider_OnHeadingUpdated; + _locationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated; + } + } + + void Start() + { + LocationProvider.OnHeadingUpdated += LocationProvider_OnHeadingUpdated; + LocationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated; + _geocoder = MapboxConvenience.Instance.Geocoder; + _timer = _timerMax; + //gameObject.SetActive(false); + } + + void OnDestroy() + { + if (LocationProvider != null) + { + LocationProvider.OnHeadingUpdated -= LocationProvider_OnHeadingUpdated; + LocationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated; + } + } + + void LocationProvider_OnHeadingUpdated(object sender, HeadingUpdatedEventArgs e) + { + //_headingText.text = "Heading: " + e.Heading; + } + + void LocationProvider_OnLocationUpdated(object sender, LocationUpdatedEventArgs e) + { + _latitudeText.text = e.Location.x.ToString("F2") + " / " + e.Location.y.ToString("F2"); + + if (_timer <= 0) + { + _coordinate.Latitude = e.Location.x; + _coordinate.Longitude = e.Location.y; + if (_resource == null) + _resource = new ReverseGeocodeResource(_coordinate); + + _resource.Query = _coordinate; + _geocoder.Geocode(_resource, HandleGeocoderResponse); + _timer = _timerMax; + } + _timer -= Time.deltaTime; + } + + void HandleGeocoderResponse(ForwardGeocodeResponse res) + { + if(res.Features.Any()) + _locationText.text = res.Features[0].Text; + } + + } +} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs.meta new file mode 100644 index 000000000..f6bc7dc3a --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: dd2fe94fa2f8c46369dc011153377b91 +timeCreated: 1484085721 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs new file mode 100644 index 000000000..6d6233d31 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs @@ -0,0 +1,82 @@ +// HACK: Does this belong here? +#if !UNITY_EDITOR +#define NOT_UNITY_EDITOR +#endif + +using System.Diagnostics; +using Mapbox.Scripts.Utilities; +using Location; +using UnityEngine; + +namespace Scripts.Location +{ + public class LocationProviderFactory : SingletonBehaviour + { + [SerializeField] + DeviceLocationProvider _deviceLocationProvider; + + [SerializeField] + EditorLocationProvider _editorLocationProvider; + + [SerializeField] + TransformLocationProvider _transformLocationProvider; + + ILocationProvider _defaultLocationProvider; + public ILocationProvider DefaultLocationProvider + { + get + { + return _defaultLocationProvider; + } + set + { + _defaultLocationProvider = value; + } + } + + public TransformLocationProvider TransformLocationProvider + { + get + { + return _transformLocationProvider; + } + } + + public EditorLocationProvider EditorLocationProvider + { + get + { + return _editorLocationProvider; + } + } + + public DeviceLocationProvider DeviceLocationProvider + { + get + { + return _deviceLocationProvider; + } + } + + public override void Awake() + { + base.Awake(); + InjectEditorLocationProvider(); + InjectDeviceLocationProvider(); + } + + [Conditional("UNITY_EDITOR")] + void InjectEditorLocationProvider() + { + UnityEngine.Debug.Log("LocationProviderFactory: " + "Injected EDITOR Location Provider"); + _defaultLocationProvider = _editorLocationProvider; + } + + [Conditional("NOT_UNITY_EDITOR")] + void InjectDeviceLocationProvider() + { + UnityEngine.Debug.Log("LocationProviderFactory: " + "Injected DEVICE Location Provider"); + _defaultLocationProvider = _deviceLocationProvider; + } + } +} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs.meta new file mode 100644 index 000000000..b8cecedd4 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b55f37f9a6f7e44f7bb35e6bc3863847 +timeCreated: 1484256054 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs new file mode 100644 index 000000000..764464566 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs @@ -0,0 +1,52 @@ +using System; +using UnityEngine; +using Assets.Scripts.Helpers; + +namespace Scripts.Location +{ + public class TransformLocationProvider : MonoBehaviour, ILocationProvider + { + [SerializeField] + Transform _targetTransform; + + public Vector2 Location + { + get + { + return GetLocation(); + } + } + + public Transform TargetTransform + { + set + { + _targetTransform = value; + } + } + + public event EventHandler OnHeadingUpdated; + public event EventHandler OnLocationUpdated; + + void Update() + { + if (OnHeadingUpdated != null) + { + OnHeadingUpdated(this, new HeadingUpdatedEventArgs() { Heading = _targetTransform.eulerAngles.y }); + } + + if (OnLocationUpdated != null) + { + // TODO: optimize this. Use Vector2 OR GeoCoordinate? + OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = GetLocation() }); + } + } + + Vector2 GetLocation() + { + var geo = _targetTransform.GetGeoPosition(); + var position = new Vector2((float)geo.Latitude, (float)geo.Longitude); + return position; + } + } +} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs.meta new file mode 100644 index 000000000..eb81eef59 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a034c4eeb3293418aab101c1895844a4 +timeCreated: 1484087415 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From dfc8d9eb00df5e3cae07920c541f9f1d7d95acb5 Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Thu, 13 Apr 2017 15:19:11 -0600 Subject: [PATCH 2/5] Example scene and map for LocationProvider. Fixing compile errors and update LocationProvider with latest conversion and Vector2 changes. Sample player positioned with location provider. --- .../Unity/Location/DeviceLocationProvider.cs | 199 +++--- .../Unity/Location/EditorLocationProvider.cs | 145 ++--- .../Core/Unity/Location/ILocationProvider.cs | 14 +- .../Core/Unity/Location/LocationLogger.cs | 98 --- .../Unity/Location/LocationProviderFactory.cs | 152 +++-- .../Location/TransformLocationProvider.cs | 25 +- .../Core/Unity/Utilities/Conversions.cs | 5 + .../Mapbox/Examples/LocationProvider.meta | 9 + .../LocationProvider/LocationProvider.unity | 595 ++++++++++++++++++ .../LocationProvider.unity.meta | 8 + .../LocationProvider/MapVisualization.meta | 9 + .../LocationProviderMapImageFactory.asset | 17 + ...LocationProviderMapImageFactory.asset.meta | 8 + .../LocationProviderMapMaterial.mat | 127 ++++ .../LocationProviderMapMaterial.mat.meta | 8 + .../LocationProviderTerrainFactory.asset | 20 + .../LocationProviderTerrainFactory.asset.meta | 8 + .../LocationProviderVisualization.asset | 16 + .../LocationProviderVisualization.asset.meta | 8 + .../Examples/LocationProvider/Scripts.meta | 9 + .../Scripts/PositionWithLocationProvider.cs | 64 ++ .../PositionWithLocationProvider.cs.meta} | 4 +- .../Scripts/RotateWithLocationProvider.cs | 69 ++ .../RotateWithLocationProvider.cs.meta | 12 + 24 files changed, 1254 insertions(+), 375 deletions(-) delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider.meta create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity.meta create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization.meta create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapImageFactory.asset create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapImageFactory.asset.meta create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapMaterial.mat create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapMaterial.mat.meta create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderTerrainFactory.asset create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderTerrainFactory.asset.meta create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderVisualization.asset create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderVisualization.asset.meta create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts.meta create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs rename sdkproject/Assets/Mapbox/{Core/Unity/Location/LocationLogger.cs.meta => Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs.meta} (75%) create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs.meta diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs index 289c6c288..7b491242e 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs @@ -1,94 +1,109 @@ -using System.Collections; -using UnityEngine; -using Scripts.Location; -using System; - -namespace Location +namespace Mapbox.Unity.Location { - public class DeviceLocationProvider : MonoBehaviour, ILocationProvider - { - Coroutine _pollRoutine; - - float _lastHeading; - - double _lastTimestamp; - - Vector2 _location; - public Vector2 Location - { - get - { - return _location; - } - } - - public event EventHandler OnLocationUpdated; - public event EventHandler OnHeadingUpdated; - - void Start() - { - if (_pollRoutine == null) - { - _pollRoutine = StartCoroutine(PollLocationRoutine()); - } - } - - IEnumerator PollLocationRoutine() - { - if (!Input.location.isEnabledByUser) - { - yield break; - } - Input.location.Start(5f, 5f); - Input.compass.enabled = true; - - int maxWait = 20; - while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) - { - yield return new WaitForSeconds(1); - maxWait--; - } - - if (maxWait < 1) - { - yield break; - } - - if (Input.location.status == LocationServiceStatus.Failed) - { - yield break; - } - - while (true) - { - var heading = Input.compass.trueHeading; - SendHeadingUpdated(heading); - - var timestamp = Input.location.lastData.timestamp; - if (Input.location.status == LocationServiceStatus.Running && timestamp > _lastTimestamp) - { - _location = new Vector2(Input.location.lastData.latitude, Input.location.lastData.longitude); - SendLocationUpdated(_location); - _lastTimestamp = timestamp; - } - yield return null; - } - } - - void SendHeadingUpdated(float heading) - { - if (OnHeadingUpdated != null) - { - OnHeadingUpdated(this, new HeadingUpdatedEventArgs() { Heading = heading }); - } - } - - void SendLocationUpdated(Vector2 location) - { - if (OnLocationUpdated != null) - { - OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = location}); - } - } - } + using System.Collections; + using UnityEngine; + using System; + using Mapbox.Utils; + + public class DeviceLocationProvider : MonoBehaviour, ILocationProvider + { + [SerializeField] + float _desiredAccuracyInMeters = 5f; + + [SerializeField] + float _updateDistanceInMeters = 5f; + + Coroutine _pollRoutine; + + double _lastLocationTimestamp; + + double _lastHeadingTimestamp; + + WaitForSeconds _wait; + + Vector2d _location; + public Vector2d Location + { + get + { + return _location; + } + } + + public event EventHandler OnLocationUpdated; + public event EventHandler OnHeadingUpdated; + + void Start() + { + _wait = new WaitForSeconds(1f); + if (_pollRoutine == null) + { + _pollRoutine = StartCoroutine(PollLocationRoutine()); + } + } + + IEnumerator PollLocationRoutine() + { + if (!Input.location.isEnabledByUser) + { + yield break; + } + + Input.location.Start(_desiredAccuracyInMeters, _updateDistanceInMeters); + Input.compass.enabled = true; + + int maxWait = 20; + while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) + { + yield return _wait; + maxWait--; + } + + if (maxWait < 1) + { + yield break; + } + + if (Input.location.status == LocationServiceStatus.Failed) + { + yield break; + } + + while (true) + { + var timestamp = Input.compass.timestamp; + if (Input.compass.enabled && timestamp > _lastHeadingTimestamp) + { + var heading = Input.compass.trueHeading; + SendHeadingUpdated(heading); + _lastHeadingTimestamp = timestamp; + } + + timestamp = Input.location.lastData.timestamp; + if (Input.location.status == LocationServiceStatus.Running && timestamp > _lastLocationTimestamp) + { + _location = new Vector2d(Input.location.lastData.latitude, Input.location.lastData.longitude); + SendLocationUpdated(_location); + _lastLocationTimestamp = timestamp; + } + yield return null; + } + } + + void SendHeadingUpdated(float heading) + { + if (OnHeadingUpdated != null) + { + OnHeadingUpdated(this, new HeadingUpdatedEventArgs() { Heading = heading }); + } + } + + void SendLocationUpdated(Vector2d location) + { + if (OnLocationUpdated != null) + { + OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = location }); + } + } + } } \ No newline at end of file diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs index 413aad877..dca344af6 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs @@ -1,101 +1,54 @@ -using System; -using System.Collections; -using Mapbox.Geocoding; -using Mapbox.Scripts.Utilities; -using UnityEngine; - -namespace Scripts.Location +namespace Mapbox.Unity.Location { - public class EditorLocationProvider : MonoBehaviour, ILocationProvider - { - [SerializeField] - string _forwardGeocodeQuery; - - [SerializeField] - float _latitude; - - [SerializeField] - float _longitude; - - [SerializeField] - [Range(0, 359)] - float _heading; - - ForwardGeocodeResource _resource; - - Coroutine _updateLocationRoutine; - - Vector2 _location; - public Vector2 Location - { - get - { - return _location; - } - } - - public event EventHandler OnHeadingUpdated; - public event EventHandler OnLocationUpdated; - - void Start() - { - _resource = new ForwardGeocodeResource(""); - - if (!string.IsNullOrEmpty(_forwardGeocodeQuery)) - { - _resource.Query = _forwardGeocodeQuery; - MapboxConvenience.Instance.Geocoder.Geocode(_resource, HandleGeocoderResponse); - } - else + using System; + using Mapbox.Unity.Utilities; + using Mapbox.Utils; + using UnityEngine; + + public class EditorLocationProvider : MonoBehaviour, ILocationProvider + { + [SerializeField] + [Geocode] + string _latitudeLongitude; + + [SerializeField] + [Range(0, 359)] + float _heading; + + public Vector2d Location + { + get { - _updateLocationRoutine = StartCoroutine(UpdateLocationRoutine()); + var split = _latitudeLongitude.Split(','); + return new Vector2d(double.Parse(split[0]), double.Parse(split[1])); } - } - - void Update() - { - if (OnHeadingUpdated != null) - { - OnHeadingUpdated(this, new HeadingUpdatedEventArgs() { Heading = _heading }); - } - } - - void HandleGeocoderResponse(ForwardGeocodeResponse response) - { - var geocoords = response.Features[0].Center; - UpdateLocation((float)geocoords.Latitude, (float)geocoords.Longitude); - } - - IEnumerator UpdateLocationRoutine() - { - while (true) - { - _location = new Vector2(_latitude, _longitude); - SendLocationUpdated(); - yield return new WaitForSeconds(1f); - } - } - - [ContextMenu("Update location")] - public void UpdateLocation(float lat, float lon) - { - _latitude = lat; - _longitude = lon; - - if (_updateLocationRoutine != null) - { - StopCoroutine(_updateLocationRoutine); - _updateLocationRoutine = null; - } - _updateLocationRoutine = StartCoroutine(UpdateLocationRoutine()); - } + } + + public event EventHandler OnHeadingUpdated; + public event EventHandler OnLocationUpdated; + +#if UNITY_EDITOR + void Update() + { + SendHeadingUpdated(); + SendLocationUpdated(); + } +#endif + + void SendHeadingUpdated() + { + if (OnHeadingUpdated != null) + { + OnHeadingUpdated(this, new HeadingUpdatedEventArgs() { Heading = _heading }); + } + } - void SendLocationUpdated() - { - if (OnLocationUpdated != null) - { - OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = _location }); - } - } - } + void SendLocationUpdated() + { + if (OnLocationUpdated != null) + { + OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = Location }); + } + } + } } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs index d17e58971..a192d41d7 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs @@ -1,18 +1,18 @@ -using System; -using UnityEngine; - -namespace Scripts.Location +namespace Mapbox.Unity.Location { - public interface ILocationProvider + using System; + using Mapbox.Utils; + + public interface ILocationProvider { event EventHandler OnLocationUpdated; event EventHandler OnHeadingUpdated; - Vector2 Location { get; } + Vector2d Location { get; } } public class LocationUpdatedEventArgs: EventArgs { - public Vector2 Location; + public Vector2d Location; } public class HeadingUpdatedEventArgs : EventArgs diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs deleted file mode 100644 index 4b11fbbe3..000000000 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs +++ /dev/null @@ -1,98 +0,0 @@ -using Mapbox.Geocoding; -using Mapbox.Scripts.Utilities; -using UnityEngine; -using UnityEngine.UI; -using Mapbox; -using System.Linq; - -namespace Scripts.Location -{ - public class LocationLogger : MonoBehaviour - { - [SerializeField] - Text _locationText; - - [SerializeField] - Text _latitudeText; - - Geocoder _geocoder; - bool _hasResponse; - GeoCoordinate _coordinate; - private ReverseGeocodeResource _resource; - private float _timerMax = 1; - private float _timer; - - ILocationProvider _locationProvider; - public ILocationProvider LocationProvider - { - private get - { - if (_locationProvider == null) - { - _locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; - } - - return _locationProvider; - } - set - { - if (_locationProvider != null) - { - _locationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated; - _locationProvider.OnHeadingUpdated -= LocationProvider_OnHeadingUpdated; - } - _locationProvider = value; - _locationProvider.OnHeadingUpdated += LocationProvider_OnHeadingUpdated; - _locationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated; - } - } - - void Start() - { - LocationProvider.OnHeadingUpdated += LocationProvider_OnHeadingUpdated; - LocationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated; - _geocoder = MapboxConvenience.Instance.Geocoder; - _timer = _timerMax; - //gameObject.SetActive(false); - } - - void OnDestroy() - { - if (LocationProvider != null) - { - LocationProvider.OnHeadingUpdated -= LocationProvider_OnHeadingUpdated; - LocationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated; - } - } - - void LocationProvider_OnHeadingUpdated(object sender, HeadingUpdatedEventArgs e) - { - //_headingText.text = "Heading: " + e.Heading; - } - - void LocationProvider_OnLocationUpdated(object sender, LocationUpdatedEventArgs e) - { - _latitudeText.text = e.Location.x.ToString("F2") + " / " + e.Location.y.ToString("F2"); - - if (_timer <= 0) - { - _coordinate.Latitude = e.Location.x; - _coordinate.Longitude = e.Location.y; - if (_resource == null) - _resource = new ReverseGeocodeResource(_coordinate); - - _resource.Query = _coordinate; - _geocoder.Geocode(_resource, HandleGeocoderResponse); - _timer = _timerMax; - } - _timer -= Time.deltaTime; - } - - void HandleGeocoderResponse(ForwardGeocodeResponse res) - { - if(res.Features.Any()) - _locationText.text = res.Features[0].Text; - } - - } -} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs index 6d6233d31..cc85a3dc7 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs @@ -1,82 +1,100 @@ -// HACK: Does this belong here? #if !UNITY_EDITOR #define NOT_UNITY_EDITOR #endif -using System.Diagnostics; -using Mapbox.Scripts.Utilities; -using Location; -using UnityEngine; - -namespace Scripts.Location +namespace Mapbox.Unity.Location { - public class LocationProviderFactory : SingletonBehaviour - { - [SerializeField] - DeviceLocationProvider _deviceLocationProvider; + using System.Diagnostics; + using UnityEngine; + + public class LocationProviderFactory : MonoBehaviour + { + [SerializeField] + DeviceLocationProvider _deviceLocationProvider; + + [SerializeField] + EditorLocationProvider _editorLocationProvider; + + [SerializeField] + TransformLocationProvider _transformLocationProvider; + + private static LocationProviderFactory _instance; + public static LocationProviderFactory Instance + { + get + { + return _instance; + } - [SerializeField] - EditorLocationProvider _editorLocationProvider; + private set + { + _instance = value; + } + } - [SerializeField] - TransformLocationProvider _transformLocationProvider; + ILocationProvider _defaultLocationProvider; + public ILocationProvider DefaultLocationProvider + { + get + { + return _defaultLocationProvider; + } + set + { + _defaultLocationProvider = value; + } + } - ILocationProvider _defaultLocationProvider; - public ILocationProvider DefaultLocationProvider - { - get - { - return _defaultLocationProvider; - } - set - { - _defaultLocationProvider = value; - } - } + public TransformLocationProvider TransformLocationProvider + { + get + { + return _transformLocationProvider; + } + } - public TransformLocationProvider TransformLocationProvider - { - get - { - return _transformLocationProvider; - } - } + public EditorLocationProvider EditorLocationProvider + { + get + { + return _editorLocationProvider; + } + } - public EditorLocationProvider EditorLocationProvider - { - get - { - return _editorLocationProvider; - } - } + public DeviceLocationProvider DeviceLocationProvider + { + get + { + return _deviceLocationProvider; + } + } - public DeviceLocationProvider DeviceLocationProvider - { - get - { - return _deviceLocationProvider; - } - } + private void Awake() + { + if (Instance != null) + { + DestroyImmediate(gameObject); + return; + } + Instance = this; + DontDestroyOnLoad(gameObject); - public override void Awake() - { - base.Awake(); - InjectEditorLocationProvider(); - InjectDeviceLocationProvider(); - } + InjectEditorLocationProvider(); + InjectDeviceLocationProvider(); + } - [Conditional("UNITY_EDITOR")] - void InjectEditorLocationProvider() - { - UnityEngine.Debug.Log("LocationProviderFactory: " + "Injected EDITOR Location Provider"); - _defaultLocationProvider = _editorLocationProvider; - } + [Conditional("UNITY_EDITOR")] + void InjectEditorLocationProvider() + { + UnityEngine.Debug.Log("LocationProviderFactory: " + "Injected EDITOR Location Provider"); + DefaultLocationProvider = _editorLocationProvider; + } - [Conditional("NOT_UNITY_EDITOR")] - void InjectDeviceLocationProvider() - { - UnityEngine.Debug.Log("LocationProviderFactory: " + "Injected DEVICE Location Provider"); - _defaultLocationProvider = _deviceLocationProvider; - } - } + [Conditional("NOT_UNITY_EDITOR")] + void InjectDeviceLocationProvider() + { + UnityEngine.Debug.Log("LocationProviderFactory: " + "Injected DEVICE Location Provider"); + DefaultLocationProvider = _deviceLocationProvider; + } + } } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs index 764464566..548b10037 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs @@ -1,15 +1,17 @@ -using System; -using UnityEngine; -using Assets.Scripts.Helpers; - -namespace Scripts.Location +namespace Mapbox.Unity.Location { - public class TransformLocationProvider : MonoBehaviour, ILocationProvider + using System; + using Mapbox.Unity.Utilities; + using Mapbox.Utils; + using UnityEngine; + using Mapbox.Unity.MeshGeneration; + + public class TransformLocationProvider : MonoBehaviour, ILocationProvider { - [SerializeField] + [SerializeField] Transform _targetTransform; - public Vector2 Location + public Vector2d Location { get { @@ -37,16 +39,13 @@ void Update() if (OnLocationUpdated != null) { - // TODO: optimize this. Use Vector2 OR GeoCoordinate? OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = GetLocation() }); } } - Vector2 GetLocation() + Vector2d GetLocation() { - var geo = _targetTransform.GetGeoPosition(); - var position = new Vector2((float)geo.Latitude, (float)geo.Longitude); - return position; + return _targetTransform.GetGeoPosition(MapController.ReferenceTileRect.Center, MapController.WorldScaleFactor); } } } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Conversions.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Conversions.cs index 7f24816d1..ce927b1d1 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Conversions.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Conversions.cs @@ -56,6 +56,11 @@ public static Vector2d GeoToWorldPosition(double lat, double lon, Vector2d refPo return new Vector2d((posx - refPoint.x) * scale, (posy - refPoint.y) * scale); } + public static Vector2d GeoToWorldPosition(Vector2d latLong, Vector2d refPoint, float scale = 1) + { + return GeoToWorldPosition(latLong.x, latLong.y, refPoint, scale); + } + /// /// Converts Spherical Mercator EPSG:900913 in xy meters to WGS84 lat/lon. /// Inverse of LatLonToMeters. diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider.meta new file mode 100644 index 000000000..c32017342 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 22e2a172b526d4e3bafd40f5f586d756 +folderAsset: yes +timeCreated: 1492113123 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity b/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity new file mode 100644 index 000000000..2a5d2a695 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity @@ -0,0 +1,595 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +SceneSettings: + m_ObjectHideFlags: 0 + m_PVSData: + m_PVSObjectsArray: [] + m_PVSPortalsArray: [] + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 7 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.44692504, g: 0.4967869, b: 0.57508504, a: 1} +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 7 + m_GIWorkflowMode: 0 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_TemporalCoherenceThreshold: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 1 + m_LightmapEditorSettings: + serializedVersion: 4 + m_Resolution: 2 + m_BakeResolution: 40 + m_TextureWidth: 1024 + m_TextureHeight: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_DirectLightInLightProbes: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_LightingDataAsset: {fileID: 0} + m_RuntimeCPUUsage: 25 +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + accuratePlacement: 0 + minRegionArea: 2 + cellSize: 0.16666667 + manualCellSize: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &105139462 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 105139464} + - 108: {fileID: 105139463} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &105139463 +Light: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 105139462} + m_Enabled: 1 + serializedVersion: 7 + m_Type: 1 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_CookieSize: 10 + m_Shadows: + m_Type: 2 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_Lightmapping: 4 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &105139464 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 105139462} + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalPosition: {x: 0, y: 3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 +--- !u!1 &114606470 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 114606472} + - 114: {fileID: 114606471} + m_Layer: 0 + m_Name: MapController + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &114606471 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 114606470} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c57173fef834bb94098b65581fb4f0e4, type: 3} + m_Name: + m_EditorClassIdentifier: + MapVisualization: {fileID: 11400000, guid: 38f8ab26621bb424d86f009e3dce979f, type: 2} + TileSize: 100 + _snapYToZero: 0 + LatLng: 37.7648, -122.463 + Zoom: 15 + Range: {x: 1, y: 1, z: 1, w: 1} +--- !u!4 &114606472 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 114606470} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 +--- !u!1 &354925210 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 354925211} + - 33: {fileID: 354925214} + - 65: {fileID: 354925213} + - 23: {fileID: 354925212} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &354925211 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 354925210} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 2, z: 0} + m_LocalScale: {x: 1, y: 4, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 1934621224} + m_RootOrder: 0 +--- !u!23 &354925212 +MeshRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 354925210} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 0} + m_SubsetIndices: + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 1 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_SelectedWireframeHidden: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingOrder: 0 +--- !u!65 &354925213 +BoxCollider: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 354925210} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!33 &354925214 +MeshFilter: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 354925210} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1 &433510106 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 433510108} + - 114: {fileID: 433510107} + m_Layer: 0 + m_Name: _LocationProviderFactory + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &433510107 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 433510106} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b55f37f9a6f7e44f7bb35e6bc3863847, type: 3} + m_Name: + m_EditorClassIdentifier: + _deviceLocationProvider: {fileID: 1098163516} + _editorLocationProvider: {fileID: 1628209262} + _transformLocationProvider: {fileID: 1649127105} +--- !u!4 &433510108 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 433510106} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: + - {fileID: 1098163517} + - {fileID: 1628209263} + - {fileID: 1649127106} + m_Father: {fileID: 0} + m_RootOrder: 1 +--- !u!1 &580608870 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 580608875} + - 20: {fileID: 580608874} + - 92: {fileID: 580608873} + - 124: {fileID: 580608872} + - 81: {fileID: 580608871} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &580608871 +AudioListener: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 580608870} + m_Enabled: 1 +--- !u!124 &580608872 +Behaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 580608870} + m_Enabled: 1 +--- !u!92 &580608873 +Behaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 580608870} + m_Enabled: 1 +--- !u!20 &580608874 +Camera: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 580608870} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 + m_StereoMirrorMode: 0 +--- !u!4 &580608875 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 580608870} + m_LocalRotation: {x: 0.5735764, y: 0, z: 0, w: 0.8191521} + m_LocalPosition: {x: 0, y: 25, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 70, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 1934621224} + m_RootOrder: 1 +--- !u!1 &1098163515 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1098163517} + - 114: {fileID: 1098163516} + m_Layer: 0 + m_Name: Device + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1098163516 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1098163515} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0a38712e93231418a84665190b8473d0, type: 3} + m_Name: + m_EditorClassIdentifier: + _desiredAccuracyInMeters: 5 + _updateDistanceInMeters: 5 +--- !u!4 &1098163517 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1098163515} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 433510108} + m_RootOrder: 0 +--- !u!1 &1628209261 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1628209263} + - 114: {fileID: 1628209262} + m_Layer: 0 + m_Name: Editor + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1628209262 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1628209261} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 60712efc3153a4819b0c79437175846d, type: 3} + m_Name: + m_EditorClassIdentifier: + _latitudeLongitude: 37.7648, -122.463 + _heading: 0 +--- !u!4 &1628209263 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1628209261} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 433510108} + m_RootOrder: 1 +--- !u!1 &1649127104 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1649127106} + - 114: {fileID: 1649127105} + m_Layer: 0 + m_Name: Transform + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1649127105 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1649127104} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a034c4eeb3293418aab101c1895844a4, type: 3} + m_Name: + m_EditorClassIdentifier: + _targetTransform: {fileID: 1649127106} +--- !u!4 &1649127106 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1649127104} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 433510108} + m_RootOrder: 2 +--- !u!1 &1934621221 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1934621224} + - 114: {fileID: 1934621223} + - 114: {fileID: 1934621222} + m_Layer: 0 + m_Name: Player + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1934621222 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1934621221} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 061d2afb48ace4fd19611279b6cf732f, type: 3} + m_Name: + m_EditorClassIdentifier: + _rotationFollowFactor: 2 + _rotateZ: 0 +--- !u!114 &1934621223 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1934621221} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4bb39d89f6f3742418be7c93b4259637, type: 3} + m_Name: + m_EditorClassIdentifier: + _positionFollowFactor: 0.5 +--- !u!4 &1934621224 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1934621221} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: + - {fileID: 354925211} + - {fileID: 580608875} + m_Father: {fileID: 0} + m_RootOrder: 3 diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity.meta new file mode 100644 index 000000000..5696e38e1 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3f89098a339c744e88644a47f777dbf9 +timeCreated: 1492113148 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization.meta new file mode 100644 index 000000000..c1657c2ea --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 4f208f9ae62a4460fb9b729033d4c174 +folderAsset: yes +timeCreated: 1492114600 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapImageFactory.asset b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapImageFactory.asset new file mode 100644 index 000000000..ab24fc2e5 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapImageFactory.asset @@ -0,0 +1,17 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2b10536479dade041b6db9893fdf723a, type: 3} + m_Name: LocationProviderMapImageFactory + m_EditorClassIdentifier: + _mapIdType: 0 + _customMapId: + _mapId: mapbox://styles/mapbox/outdoors-v10 + _baseMaterial: {fileID: 2100000, guid: 8ba055cb55bcc4488b727c601be0be29, type: 2} diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapImageFactory.asset.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapImageFactory.asset.meta new file mode 100644 index 000000000..9a8a20da3 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapImageFactory.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 70ae1b4720c0f4f3d8bd4e48b43f6945 +timeCreated: 1492114655 +licenseType: Pro +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapMaterial.mat b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapMaterial.mat new file mode 100644 index 000000000..1243acabd --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapMaterial.mat @@ -0,0 +1,127 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: LocationProviderMapMaterial + m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: _EMISSION + m_LightmapFlags: 1 + m_CustomRenderQueue: -1 + stringTagMap: {} + m_SavedProperties: + serializedVersion: 2 + m_TexEnvs: + - first: + name: _BumpMap + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - first: + name: _DetailAlbedoMap + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - first: + name: _DetailMask + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - first: + name: _DetailNormalMap + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - first: + name: _EmissionMap + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - first: + name: _MainTex + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - first: + name: _MetallicGlossMap + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - first: + name: _OcclusionMap + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - first: + name: _ParallaxMap + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - first: + name: _BumpScale + second: 1 + - first: + name: _Cutoff + second: 0.5 + - first: + name: _DetailNormalMapScale + second: 1 + - first: + name: _DstBlend + second: 0 + - first: + name: _GlossMapScale + second: 1 + - first: + name: _Glossiness + second: 0.5 + - first: + name: _GlossyReflections + second: 1 + - first: + name: _Metallic + second: 0 + - first: + name: _Mode + second: 0 + - first: + name: _OcclusionStrength + second: 1 + - first: + name: _Parallax + second: 0.02 + - first: + name: _SmoothnessTextureChannel + second: 0 + - first: + name: _SpecularHighlights + second: 1 + - first: + name: _SrcBlend + second: 1 + - first: + name: _UVSec + second: 0 + - first: + name: _ZWrite + second: 1 + m_Colors: + - first: + name: _Color + second: {r: 1, g: 1, b: 1, a: 1} + - first: + name: _EmissionColor + second: {r: 0, g: 0, b: 0, a: 1} diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapMaterial.mat.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapMaterial.mat.meta new file mode 100644 index 000000000..eb934f414 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderMapMaterial.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8ba055cb55bcc4488b727c601be0be29 +timeCreated: 1492114686 +licenseType: Pro +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderTerrainFactory.asset b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderTerrainFactory.asset new file mode 100644 index 000000000..8c8325d3d --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderTerrainFactory.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8338f26893d62c1439f387800a8e1c9a, type: 3} + m_Name: LocationProviderTerrainFactory + m_EditorClassIdentifier: + _generationType: 0 + _baseMaterial: {fileID: 0} + _mapIdType: 0 + _customMapId: mapbox.terrain-rgb + _mapId: + _heightModifier: 1 + _sampleCount: 2 diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderTerrainFactory.asset.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderTerrainFactory.asset.meta new file mode 100644 index 000000000..6ea3244c8 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderTerrainFactory.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 82b1ecdf2417242a98d0f32cb1cea955 +timeCreated: 1492114634 +licenseType: Pro +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderVisualization.asset b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderVisualization.asset new file mode 100644 index 000000000..02393f71c --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderVisualization.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c66bbffbe36286f43ba04d55504d674c, type: 3} + m_Name: LocationProviderVisualization + m_EditorClassIdentifier: + Factories: + - {fileID: 11400000, guid: 82b1ecdf2417242a98d0f32cb1cea955, type: 2} + - {fileID: 11400000, guid: 70ae1b4720c0f4f3d8bd4e48b43f6945, type: 2} diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderVisualization.asset.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderVisualization.asset.meta new file mode 100644 index 000000000..6c7077fd8 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/MapVisualization/LocationProviderVisualization.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 38f8ab26621bb424d86f009e3dce979f +timeCreated: 1492114615 +licenseType: Pro +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts.meta new file mode 100644 index 000000000..2d5378c20 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: ce38eef23ab1e4f4fbbb5476587f7eff +folderAsset: yes +timeCreated: 1492115016 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs new file mode 100644 index 000000000..a5f70db2b --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs @@ -0,0 +1,64 @@ +namespace Mapbox.Examples.LocationProvider +{ + using Mapbox.Unity.Location; + using Mapbox.Unity.Utilities; + using Mapbox.Unity.MeshGeneration; + using UnityEngine; + + public class PositionWithLocationProvider : MonoBehaviour + { + [SerializeField] + float _positionFollowFactor; + + ILocationProvider _locationProvider; + public ILocationProvider LocationProvider + { + private get + { + if (_locationProvider == null) + { + _locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; + } + + return _locationProvider; + } + set + { + if (_locationProvider != null) + { + _locationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated; + + } + _locationProvider = value; + _locationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated; + } + } + + Vector3 _targetPosition; + + void Start() + { + LocationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated; + } + + void OnDestroy() + { + if (LocationProvider != null) + { + LocationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated; + } + } + + void LocationProvider_OnLocationUpdated(object sender, LocationUpdatedEventArgs e) + { + _targetPosition = Conversions.GeoToWorldPosition(e.Location, + MapController.ReferenceTileRect.Center, + MapController.WorldScaleFactor).ToVector3xz(); + } + + void Update() + { + transform.position = Vector3.Lerp(transform.position, _targetPosition, Time.deltaTime * _positionFollowFactor); + } + } +} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs.meta similarity index 75% rename from sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs.meta rename to sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs.meta index f6bc7dc3a..d463b002f 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationLogger.cs.meta +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: dd2fe94fa2f8c46369dc011153377b91 -timeCreated: 1484085721 +guid: 4bb39d89f6f3742418be7c93b4259637 +timeCreated: 1492115167 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs new file mode 100644 index 000000000..c79947617 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs @@ -0,0 +1,69 @@ +namespace Mapbox.Examples.LocationProvider +{ + using Mapbox.Unity.Location; + using UnityEngine; + + public class RotateWithLocationProvider : MonoBehaviour + { + [SerializeField] + float _rotationFollowFactor; + + [SerializeField] + bool _rotateZ; + + ILocationProvider _locationProvider; + public ILocationProvider LocationProvider + { + private get + { + if (_locationProvider == null) + { + _locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; + } + + return _locationProvider; + } + set + { + if (_locationProvider != null) + { + _locationProvider.OnHeadingUpdated -= LocationProvider_OnHeadingUpdated; + + } + _locationProvider = value; + _locationProvider.OnHeadingUpdated += LocationProvider_OnHeadingUpdated; + } + } + + Vector3 _targetPosition; + + void Start() + { + LocationProvider.OnHeadingUpdated += LocationProvider_OnHeadingUpdated; + } + + void OnDestroy() + { + if (LocationProvider != null) + { + LocationProvider.OnHeadingUpdated -= LocationProvider_OnHeadingUpdated; + } + } + + void LocationProvider_OnHeadingUpdated(object sender, HeadingUpdatedEventArgs e) + { + var euler = Vector3.zero; + if (_rotateZ) + { + euler.z = -e.Heading; + } + else + { + euler.y = e.Heading; + } + + var rotation = Quaternion.Euler(euler); + transform.localRotation = Quaternion.Lerp(transform.localRotation, rotation, Time.deltaTime * _rotationFollowFactor); + } + } +} diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs.meta new file mode 100644 index 000000000..766628f68 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 061d2afb48ace4fd19611279b6cf732f +timeCreated: 1492115182 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From e04e620ffa8bf6e5f61781e9a111d1f43aed6c1c Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Fri, 14 Apr 2017 14:15:12 -0600 Subject: [PATCH 3/5] You can now build a map based on an ILocationProvider location. Updated inline documentation. --- .../Unity/Location/DeviceLocationProvider.cs | 31 +++++ .../Unity/Location/EditorLocationProvider.cs | 23 ++++ .../Core/Unity/Location/ILocationProvider.cs | 19 ++-- .../Unity/Location/LocationProviderFactory.cs | 44 +++++++ .../Location/TransformLocationProvider.cs | 107 +++++++++++------- .../LocationProvider/LocationProvider.unity | 90 ++++----------- .../Scripts/BuildMapAtLocation.cs | 42 +++++++ .../Scripts/BuildMapAtLocation.cs.meta | 12 ++ .../Scripts/PositionWithLocationProvider.cs | 22 +++- .../Scripts/RotateWithLocationProvider.cs | 20 +++- .../ProjectSettings/EditorBuildSettings.asset | 4 +- .../ProjectSettings/GraphicsSettings.asset | 24 ++-- 12 files changed, 308 insertions(+), 130 deletions(-) create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/BuildMapAtLocation.cs create mode 100644 sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/BuildMapAtLocation.cs.meta diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs index 7b491242e..8bd94fffc 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/DeviceLocationProvider.cs @@ -5,11 +5,25 @@ namespace Mapbox.Unity.Location using System; using Mapbox.Utils; + /// + /// The DeviceLocationProvider is responsible for providing real world location and heading data, + /// served directly from native hardware and OS. + /// This relies on Unity's LocationService for location + /// and Compass for heading. + /// public class DeviceLocationProvider : MonoBehaviour, ILocationProvider { + /// + /// Using higher value like 500 usually does not require to turn GPS chip on and thus saves battery power. + /// Values like 5-10 could be used for getting best accuracy. + /// [SerializeField] float _desiredAccuracyInMeters = 5f; + /// + /// The minimum distance (measured in meters) a device must move laterally before Input.location property is updated. + /// Higher values like 500 imply less overhead. + /// [SerializeField] float _updateDistanceInMeters = 5f; @@ -22,6 +36,10 @@ public class DeviceLocationProvider : MonoBehaviour, ILocationProvider WaitForSeconds _wait; Vector2d _location; + /// + /// Gets the current cached location. + /// + /// The location. public Vector2d Location { get @@ -30,7 +48,14 @@ public Vector2d Location } } + /// + /// Occurs when on location updates. + /// public event EventHandler OnLocationUpdated; + + /// + /// Occurs when the compass updates. + /// public event EventHandler OnHeadingUpdated; void Start() @@ -42,6 +67,12 @@ void Start() } } + /// + /// Enable location and compass services. + /// Sends continuous location and heading updates based on + /// _desiredAccuracyInMeters and _updateDistanceInMeters. + /// + /// The location routine. IEnumerator PollLocationRoutine() { if (!Input.location.isEnabledByUser) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs index dca344af6..c8cdf7e87 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/EditorLocationProvider.cs @@ -5,16 +5,32 @@ namespace Mapbox.Unity.Location using Mapbox.Utils; using UnityEngine; + /// + /// The EditorLocationProvider is responsible for providing mock location and heading data + /// for testing purposes in the Unity editor. + /// public class EditorLocationProvider : MonoBehaviour, ILocationProvider { + /// + /// The mock "latitude, longitude" location, respresented with a string. + /// You can search for a place using the embedded "Search" button in the inspector. + /// This value can be changed at runtime in the inspector. + /// [SerializeField] [Geocode] string _latitudeLongitude; + /// + /// The mock heading value. + /// [SerializeField] [Range(0, 359)] float _heading; + /// + /// Gets the current location, as specified in the inspector. + /// + /// The location. public Vector2d Location { get @@ -24,7 +40,14 @@ public Vector2d Location } } + /// + /// Occurs every frame. + /// public event EventHandler OnHeadingUpdated; + + /// + /// Occurs every frame. + /// public event EventHandler OnLocationUpdated; #if UNITY_EDITOR diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs index a192d41d7..d4fd570bd 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs @@ -3,6 +3,9 @@ namespace Mapbox.Unity.Location using System; using Mapbox.Utils; + /// + /// Implement ILocationProvider to send Heading and Location updates. + /// public interface ILocationProvider { event EventHandler OnLocationUpdated; @@ -10,20 +13,22 @@ public interface ILocationProvider Vector2d Location { get; } } + /// + /// Location updated event arguments. + /// Location.x represents Latitude. + /// Location.y represents Longitude. + /// public class LocationUpdatedEventArgs: EventArgs { public Vector2d Location; } + /// + /// Heading updated event arguments. + /// Heading represents a facing angle, generally between 0-359. + /// public class HeadingUpdatedEventArgs : EventArgs { public float Heading; } - - class LocationProviderMissingException : Exception - { - public LocationProviderMissingException(string message) : base(message) - { - } - } } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs index cc85a3dc7..ea1061f3b 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs @@ -7,6 +7,10 @@ namespace Mapbox.Unity.Location using System.Diagnostics; using UnityEngine; + /// + /// Singleton factory to allow easy access to various LocationProviders. + /// This is meant to be attached to a game object. + /// public class LocationProviderFactory : MonoBehaviour { [SerializeField] @@ -18,6 +22,9 @@ public class LocationProviderFactory : MonoBehaviour [SerializeField] TransformLocationProvider _transformLocationProvider; + /// + /// The singleton instance of this factory. + /// private static LocationProviderFactory _instance; public static LocationProviderFactory Instance { @@ -32,6 +39,23 @@ private set } } + /// + /// The default location provider. + /// Outside of the editor, this will be a . + /// In the Unity editor, this will be an + /// + /// + /// Fetch location to set a transform's position: + /// + /// void Update() + /// { + /// var locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; + /// transform.position = Conversions.GeoToWorldPosition(locationProvider.Location, + /// MapController.ReferenceTileRect.Center, + /// MapController.WorldScaleFactor).ToVector3xz(); + /// } + /// + /// ILocationProvider _defaultLocationProvider; public ILocationProvider DefaultLocationProvider { @@ -45,6 +69,9 @@ public ILocationProvider DefaultLocationProvider } } + /// + /// Returns the serialized . + /// public TransformLocationProvider TransformLocationProvider { get @@ -53,6 +80,9 @@ public TransformLocationProvider TransformLocationProvider } } + /// + /// Returns the serialized . + /// public EditorLocationProvider EditorLocationProvider { get @@ -61,6 +91,9 @@ public EditorLocationProvider EditorLocationProvider } } + /// + /// Returns the serialized + /// public DeviceLocationProvider DeviceLocationProvider { get @@ -69,6 +102,9 @@ public DeviceLocationProvider DeviceLocationProvider } } + /// + /// Create singleton instance and inject the DefaulyLocationProvider upon initialization of this component. + /// private void Awake() { if (Instance != null) @@ -83,6 +119,10 @@ private void Awake() InjectDeviceLocationProvider(); } + /// + /// Injects the editor location provider. + /// Depending on the platform, this method and calls to it will be stripped during compile. + /// [Conditional("UNITY_EDITOR")] void InjectEditorLocationProvider() { @@ -90,6 +130,10 @@ void InjectEditorLocationProvider() DefaultLocationProvider = _editorLocationProvider; } + /// + /// Injects the device location provider. + /// Depending on the platform, this method and calls to it will be stripped during compile. + /// [Conditional("NOT_UNITY_EDITOR")] void InjectDeviceLocationProvider() { diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs index 548b10037..3a8b6e2d5 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/TransformLocationProvider.cs @@ -6,46 +6,75 @@ namespace Mapbox.Unity.Location using UnityEngine; using Mapbox.Unity.MeshGeneration; + /// + /// 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 : MonoBehaviour, ILocationProvider - { + { + /// + /// The transform that will be queried for location and heading data. + /// [SerializeField] - Transform _targetTransform; - - public Vector2d Location - { - get - { - return GetLocation(); - } - } - - public Transform TargetTransform - { - set - { - _targetTransform = value; - } - } - - public event EventHandler OnHeadingUpdated; - public event EventHandler OnLocationUpdated; - - void Update() - { - if (OnHeadingUpdated != null) - { - OnHeadingUpdated(this, new HeadingUpdatedEventArgs() { Heading = _targetTransform.eulerAngles.y }); - } - - if (OnLocationUpdated != null) - { - OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = GetLocation() }); - } - } - - Vector2d GetLocation() - { + Transform _targetTransform; + + /// + /// Gets the latitude, longitude of the transform. + /// This is converted from unity world space to real world geocoordinate space. + /// + /// The location. + public Vector2d Location + { + get + { + return GetLocation(); + } + } + + /// + /// Sets the target transform. + /// Use this if you want to switch the transform at runtime. + /// + public Transform TargetTransform + { + set + { + _targetTransform = value; + } + } + + /// + /// Occurs every frame. + /// + public event EventHandler OnHeadingUpdated; + + /// + /// Occurs every frame. + /// + public event EventHandler OnLocationUpdated; + + void Update() + { + if (OnHeadingUpdated != null) + { + OnHeadingUpdated(this, new HeadingUpdatedEventArgs() { Heading = _targetTransform.eulerAngles.y }); + } + + if (OnLocationUpdated != null) + { + OnLocationUpdated(this, new LocationUpdatedEventArgs() { Location = GetLocation() }); + } + } + + Vector2d GetLocation() + { + if (MapController.ReferenceTileRect == null) + { + return LocationProviderFactory.Instance.DefaultLocationProvider.Location; + } return _targetTransform.GetGeoPosition(MapController.ReferenceTileRect.Center, MapController.WorldScaleFactor); - } - } + } + } } diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity b/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity index 2a5d2a695..86c02a678 100644 --- a/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity @@ -37,7 +37,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44692504, g: 0.4967869, b: 0.57508504, a: 1} + m_IndirectSpecularColor: {r: 0.37356392, g: 0.38112, b: 0.3588766, a: 1} --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 @@ -90,69 +90,6 @@ NavMeshSettings: cellSize: 0.16666667 manualCellSize: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &105139462 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 105139464} - - 108: {fileID: 105139463} - m_Layer: 0 - m_Name: Directional Light - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!108 &105139463 -Light: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 105139462} - m_Enabled: 1 - serializedVersion: 7 - m_Type: 1 - m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} - m_Intensity: 1 - m_Range: 10 - m_SpotAngle: 30 - m_CookieSize: 10 - m_Shadows: - m_Type: 2 - m_Resolution: -1 - m_CustomResolution: -1 - m_Strength: 1 - m_Bias: 0.05 - m_NormalBias: 0.4 - m_NearPlane: 0.2 - m_Cookie: {fileID: 0} - m_DrawHalo: 0 - m_Flare: {fileID: 0} - m_RenderMode: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_Lightmapping: 4 - m_AreaSize: {x: 1, y: 1} - m_BounceIntensity: 1 - m_ShadowRadius: 0 - m_ShadowAngle: 0 ---- !u!4 &105139464 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 105139462} - m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} - m_LocalPosition: {x: 0, y: 3, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 --- !u!1 &114606470 GameObject: m_ObjectHideFlags: 0 @@ -162,6 +99,7 @@ GameObject: m_Component: - 4: {fileID: 114606472} - 114: {fileID: 114606471} + - 114: {fileID: 114606473} m_Layer: 0 m_Name: MapController m_TagString: Untagged @@ -175,7 +113,7 @@ MonoBehaviour: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 114606470} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: c57173fef834bb94098b65581fb4f0e4, type: 3} m_Name: @@ -198,7 +136,19 @@ Transform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 1 +--- !u!114 &114606473 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 114606470} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3fdc49f4b978b4412949e77a41421ee2, type: 3} + m_Name: + m_EditorClassIdentifier: + _mapController: {fileID: 114606471} --- !u!1 &354925210 GameObject: m_ObjectHideFlags: 0 @@ -323,7 +273,7 @@ Transform: - {fileID: 1628209263} - {fileID: 1649127106} m_Father: {fileID: 0} - m_RootOrder: 1 + m_RootOrder: 0 --- !u!1 &580608870 GameObject: m_ObjectHideFlags: 0 @@ -480,7 +430,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 60712efc3153a4819b0c79437175846d, type: 3} m_Name: m_EditorClassIdentifier: - _latitudeLongitude: 37.7648, -122.463 + _latitudeLongitude: 37.784328, -122.40364 _heading: 0 --- !u!4 &1628209263 Transform: @@ -566,6 +516,7 @@ MonoBehaviour: m_EditorClassIdentifier: _rotationFollowFactor: 2 _rotateZ: 0 + _useTransformLocationProvider: 0 --- !u!114 &1934621223 MonoBehaviour: m_ObjectHideFlags: 0 @@ -578,6 +529,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: _positionFollowFactor: 0.5 + _useTransformLocationProvider: 0 --- !u!4 &1934621224 Transform: m_ObjectHideFlags: 0 @@ -592,4 +544,4 @@ Transform: - {fileID: 354925211} - {fileID: 580608875} m_Father: {fileID: 0} - m_RootOrder: 3 + m_RootOrder: 2 diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/BuildMapAtLocation.cs b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/BuildMapAtLocation.cs new file mode 100644 index 000000000..8d73ef353 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/BuildMapAtLocation.cs @@ -0,0 +1,42 @@ +namespace Mapbox.Examples.LocationProvider +{ + using UnityEngine; + using Mapbox.Unity.MeshGeneration; + using Mapbox.Unity.Location; + + /// + /// Override the map center (latitude, longitude) for a MapController, based on the DefaultLocationProvider. + /// This will enable you to generate a map for your current location, for example. + /// + public class BuildMapAtLocation : MonoBehaviour + { + [SerializeField] + MapController _mapController; + + ILocationProvider _locationProvider; + ILocationProvider LocationProvider + { + get + { + if (_locationProvider == null) + { + _locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; + } + + return _locationProvider; + } + } + + void Start() + { + LocationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated; + } + + void LocationProvider_OnLocationUpdated(object sender, Unity.Location.LocationUpdatedEventArgs e) + { + LocationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated; + _mapController.LatLng = string.Format("{0}, {1}", e.Location.x, e.Location.y); + _mapController.enabled = true; + } + } +} \ No newline at end of file diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/BuildMapAtLocation.cs.meta b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/BuildMapAtLocation.cs.meta new file mode 100644 index 000000000..5c7bab472 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/BuildMapAtLocation.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3fdc49f4b978b4412949e77a41421ee2 +timeCreated: 1492184286 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs index a5f70db2b..84d5aaeb0 100644 --- a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/PositionWithLocationProvider.cs @@ -7,9 +7,23 @@ namespace Mapbox.Examples.LocationProvider public class PositionWithLocationProvider : MonoBehaviour { + /// + /// The rate at which the transform's position tries catch up to the provided location. + /// [SerializeField] float _positionFollowFactor; + /// + /// Use a mock , + /// rather than a . + /// + [SerializeField] + bool _useTransformLocationProvider; + + /// + /// The location provider. + /// This is public so you change which concrete to use at runtime. + /// ILocationProvider _locationProvider; public ILocationProvider LocationProvider { @@ -17,7 +31,8 @@ private get { if (_locationProvider == null) { - _locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; + _locationProvider = _useTransformLocationProvider ? + LocationProviderFactory.Instance.TransformLocationProvider : LocationProviderFactory.Instance.DefaultLocationProvider; } return _locationProvider; @@ -51,6 +66,11 @@ void OnDestroy() void LocationProvider_OnLocationUpdated(object sender, LocationUpdatedEventArgs e) { + if (MapController.ReferenceTileRect == null) + { + return; + } + _targetPosition = Conversions.GeoToWorldPosition(e.Location, MapController.ReferenceTileRect.Center, MapController.WorldScaleFactor).ToVector3xz(); diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs index c79947617..2459994be 100644 --- a/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/Scripts/RotateWithLocationProvider.cs @@ -5,12 +5,29 @@ public class RotateWithLocationProvider : MonoBehaviour { + /// + /// The rate at which the transform's rotation tries catch up to the provided heading. + /// [SerializeField] float _rotationFollowFactor; + /// + /// Set this to true if you'd like to adjust the rotation of a RectTransform (in a UI canvas) with the heading. + /// [SerializeField] bool _rotateZ; + /// + /// Use a mock , + /// rather than a . + /// + [SerializeField] + bool _useTransformLocationProvider; + + /// + /// The location provider. + /// This is public so you change which concrete to use at runtime. + /// ILocationProvider _locationProvider; public ILocationProvider LocationProvider { @@ -18,7 +35,8 @@ private get { if (_locationProvider == null) { - _locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; + _locationProvider = _useTransformLocationProvider ? + LocationProviderFactory.Instance.TransformLocationProvider : LocationProviderFactory.Instance.DefaultLocationProvider; } return _locationProvider; diff --git a/sdkproject/ProjectSettings/EditorBuildSettings.asset b/sdkproject/ProjectSettings/EditorBuildSettings.asset index 6dc24f7df..e8f9a8784 100644 --- a/sdkproject/ProjectSettings/EditorBuildSettings.asset +++ b/sdkproject/ProjectSettings/EditorBuildSettings.asset @@ -4,4 +4,6 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 - m_Scenes: [] + m_Scenes: + - enabled: 1 + path: Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity diff --git a/sdkproject/ProjectSettings/GraphicsSettings.asset b/sdkproject/ProjectSettings/GraphicsSettings.asset index 325937ca8..d10340e38 100644 --- a/sdkproject/ProjectSettings/GraphicsSettings.asset +++ b/sdkproject/ProjectSettings/GraphicsSettings.asset @@ -40,20 +40,20 @@ GraphicsSettings: m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} m_ShaderSettings_Tier1: - useCascadedShadowMaps: 1 - standardShaderQuality: 2 - useReflectionProbeBoxProjection: 1 - useReflectionProbeBlending: 1 + useCascadedShadowMaps: 0 + standardShaderQuality: 0 + useReflectionProbeBoxProjection: 0 + useReflectionProbeBlending: 0 m_ShaderSettings_Tier2: - useCascadedShadowMaps: 1 - standardShaderQuality: 2 - useReflectionProbeBoxProjection: 1 - useReflectionProbeBlending: 1 + useCascadedShadowMaps: 0 + standardShaderQuality: 1 + useReflectionProbeBoxProjection: 0 + useReflectionProbeBlending: 0 m_ShaderSettings_Tier3: - useCascadedShadowMaps: 1 - standardShaderQuality: 2 - useReflectionProbeBoxProjection: 1 - useReflectionProbeBlending: 1 + useCascadedShadowMaps: 0 + standardShaderQuality: 1 + useReflectionProbeBoxProjection: 0 + useReflectionProbeBlending: 0 m_BuildTargetShaderSettings: [] m_LightmapStripping: 0 m_FogStripping: 0 From 0750f74dd3e8906bfb182f2d62171bd335005d5d Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Fri, 14 Apr 2017 15:26:47 -0600 Subject: [PATCH 4/5] Added LocationProvider example documentation [publish docs] --- documentation/docs/03-examples.md | 58 ++++++++++++++----- .../LocationProvider/LocationProvider.unity | 2 +- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/documentation/docs/03-examples.md b/documentation/docs/03-examples.md index bfe692181..bcedf8a40 100644 --- a/documentation/docs/03-examples.md +++ b/documentation/docs/03-examples.md @@ -2,11 +2,11 @@ For each example, associated scripts and resources can be found in the same root directory as the scene itself. -### Playground +## Playground These examples demonstrate how to request specific Mapbox data using our C# library. -#### Forward Geocoder +### Forward Geocoder *ForwardGeocoder.unity* @@ -14,7 +14,7 @@ A forward geocoding request will fetch GeoJSON from a place name query. A new re Visit [our API documentation](https://www.mapbox.com/api-documentation/#geocoding) for more information. -#### Reverse Geocoder +### Reverse Geocoder *ReverseGeocoder.unity* @@ -22,7 +22,7 @@ A reverse geocoding request will fetch GeoJSON from a location query. The locati Visit [our API documentation](https://www.mapbox.com/api-documentation/#geocoding) for more information. -#### Directions +### Directions *Directions.unity* @@ -34,7 +34,7 @@ When the geocode requests have been completed, a directions request is executed. Directions results will be logged to the UI when they are available (in the form of JSON). -#### Raster Tile +### Raster Tile *RasterTile.unity* @@ -44,7 +44,7 @@ See: https://www.mapbox.com/help/define-style/ See: https://www.mapbox.com/api-documentation/#retrieve-raster-tiles-from-styles -#### Vector Tile +### Vector Tile *VectorTile.unity* @@ -54,7 +54,7 @@ In this example, the result is GeoJSON with a feature collection. Visit [our API documentation](https://www.mapbox.com/api-documentation/#retrieve-features-from-vector-tiles) for more information. -### Mesh Generation Basics +## Mesh Generation Basics *MeshGeneration.unity* @@ -68,7 +68,7 @@ See `MapImageFactory.asset` to customize the raster `MapId` you would like to us See `MeshFactory.asset` to see how specific layers are extracted from vector tiles. In this case, we are generating meshes for both `building` and `road`. Therefore, each layer has a `VectorLayerVisualizer` responsible for handling that layer's specific data (such as geometry). -### Mesh Generataion Pois +## Mesh Generataion Pois *PoiGeneration.unity* @@ -76,13 +76,13 @@ With the exception of a `PoiVisualizer ` (`PoiDemoPoiVisualizer`) being added to `PoiDemoPoiVisualizer.asset` allows you to override which prefab to spawn for each `po_label` contained in the vector tile. This prefab should have a component that implements `ILabelVisualizationHelper` attached to it. This exists to inject feature data into (such as label and `Maki` icon). -### Mesh Generation Styles +## Mesh Generation Styles *StylingDemoMeshGeneration.unity* This example demonstrates how to use `TypeFilters` to filter specific features for processing. In this case, we have chosen to exclude `schools` from mesh generation. Additionally, you can use `ModifierStacks` to further customize specific features (to color banks differently, for example). -### Drive +## Drive *Drive.unity* @@ -96,9 +96,9 @@ The ground layer was generated with a `flat` `TerrainFactory` and a `MapImageFac To understand 3D building generation, please see `Mesh Generation Basics`. One particular difference in this example, however, is the use of a `MergedModifierStack` for `DriveBuildingVisualizer.asset`. This `ModifierStack` is responsible for merging buildings during generation. This optimization reduces the number of transforms and draw calls in the scene, vastly improving the final frame rate. -### Slippy Vector Terrain +## Slippy Vector Terrain -*SlippyDemo.Unity* +*SlippyDemo.unity* This example demonstrates one way to create a [slippy map](http://wiki.openstreetmap.org/wiki/Slippy_Map). The `Slippy` component attached to the `MapController` game object is responsible for requesting new tiles as needed, based on the position of the camera relative to the map. This is achieved using `raycasting` and a dictionary of known (requested and fetched) tiles. @@ -106,7 +106,7 @@ Use W, A, S, D keyboard controls to navigate the map at runtime. Please see `Mesh Generation Basics` to understand how features are customized. -### Voxels +## Voxels *VoxelWorld.unity* @@ -124,4 +124,34 @@ This Minecraft-inspired example demonstrates a less traditional way to consume M `Voxel Batch Count`: How many voxels to spawn at once. Keep this number low to prevent locking the main thread during construction. -Please read [the blog post](https://www.mapbox.com/blog/how-to-minecraft-unity/) describing how this was made for more information. \ No newline at end of file +Please read [the blog post](https://www.mapbox.com/blog/how-to-minecraft-unity/) describing how this was made for more information. + +## LocationProvider + +*LocationProvider.unity* + +This example is to demonstrate how to: + +- Build a map for your current (device) location +- Update a virtual player's position and rotation based on a real or mock location and heading +- Use mock location providers to test in the Unity editor +- Convert between unity world space<—>earth space (latitude, longitude) + +The `LocationProvider` game object in this scene has three children. Each child corresponds to a specific type of `ILocationProvider`. Please [read more about LocationProviders](https://mapbox.github.io/mapbox-unity-sdk/api/unity/Mapbox.Unity.Location.html). + +The `MapController` game object has a `BuildMapAtLocation` component attached to it. This component is responsible for overriding the default center point of the `MapController` component, using the DefaultLocationProvider's location. In the Unity editor, this is the `EditorLocationProvider`—intended for mocking. On device, this is the `DeviceLocationProvider`—intended for real world location updates. + +To change the location for the map in the Editor, change `EditorLocationProvider`'s `LatitudeLongitude` field on the `Editor` game object. You can use the embedded `Search` button in the inspector to search for a place or address. The default location for this scene is the Metreon, in San Francisco, CA. + +**Note: It is important that the `MapController` component be disabled to begin with.** + +Press play and observe the map being constructed. Click on the `Player` game object and note the attached components: `PositionWithLocationProvider` and `RotateWithLocationProvider`. These are responsible for updating the transform's position and rotation based on a specified `ILocationProvider`. Again, in the `EditorLocationProvider`, search for `Yerba Buena Gardens` and select the top result. Watch as the player's position updates! + +If you check `Use Transform Location Provider` for `PositionWithLocationProvider` and `RotateWithLocationProvider`, the mock `ILocationProvider` will be represented by the `Transform` game object. Press play once more with this toggle checked for both components. In the scene view, move and rotate the `Transform` game object and observe as the `Player` tries to follow that target. It is important to note that the location returned by the `TransformLocationProvider` is actually converted from the transform's world position to latitude, longitude. This is what that conversion looks like: + +```cs +return _targetTransform.GetGeoPosition(MapController.ReferenceTileRect.Center, MapController.WorldScaleFactor); +``` + +If you build to device, you should see a familiar map and can observe the player update with your own location. Because the camera is a child of `Player`, you should always be centered on the map. + diff --git a/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity b/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity index 86c02a678..67eb06d75 100644 --- a/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity +++ b/sdkproject/Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity @@ -238,7 +238,7 @@ GameObject: - 4: {fileID: 433510108} - 114: {fileID: 433510107} m_Layer: 0 - m_Name: _LocationProviderFactory + m_Name: LocationProvider m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 From 1fa912bab3eb48e7141f30e34238a45489858b65 Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Fri, 14 Apr 2017 15:38:46 -0600 Subject: [PATCH 5/5] Fixed formatting and added link to Vector2d. [publish docs] --- .../Core/Unity/Location/ILocationProvider.cs | 35 ++++++++++--------- .../Unity/Location/LocationProviderFactory.cs | 23 ++++++------ 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs index d4fd570bd..d31c00327 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/ILocationProvider.cs @@ -6,29 +6,32 @@ namespace Mapbox.Unity.Location /// /// Implement ILocationProvider to send Heading and Location updates. /// - public interface ILocationProvider - { - event EventHandler OnLocationUpdated; - event EventHandler OnHeadingUpdated; - Vector2d Location { get; } - } + public interface ILocationProvider + { + event EventHandler OnLocationUpdated; + event EventHandler OnHeadingUpdated; + Vector2d Location { get; } + } /// /// Location updated event arguments. - /// Location.x represents Latitude. - /// Location.y represents Longitude. /// - public class LocationUpdatedEventArgs: EventArgs - { - public Vector2d Location; - } + public class LocationUpdatedEventArgs : EventArgs + { + /// + /// The location, as descibed by a . + /// Location.x represents Latitude. + /// Location.y represents Longitude. + /// + public Vector2d Location; + } /// /// Heading updated event arguments. /// Heading represents a facing angle, generally between 0-359. /// - public class HeadingUpdatedEventArgs : EventArgs - { - public float Heading; - } + public class HeadingUpdatedEventArgs : EventArgs + { + public float Heading; + } } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs index ea1061f3b..3d838dece 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Location/LocationProviderFactory.cs @@ -39,24 +39,25 @@ private set } } + ILocationProvider _defaultLocationProvider; + /// /// The default location provider. - /// Outside of the editor, this will be a . - /// In the Unity editor, this will be an + /// Outside of the editor, this will be a . + /// In the Unity editor, this will be an /// /// /// Fetch location to set a transform's position: /// /// void Update() /// { - /// var locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; - /// transform.position = Conversions.GeoToWorldPosition(locationProvider.Location, - /// MapController.ReferenceTileRect.Center, - /// MapController.WorldScaleFactor).ToVector3xz(); + /// var locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider; + /// transform.position = Conversions.GeoToWorldPosition(locationProvider.Location, + /// MapController.ReferenceTileRect.Center, + /// MapController.WorldScaleFactor).ToVector3xz(); /// } /// /// - ILocationProvider _defaultLocationProvider; public ILocationProvider DefaultLocationProvider { get @@ -70,7 +71,7 @@ public ILocationProvider DefaultLocationProvider } /// - /// Returns the serialized . + /// Returns the serialized . /// public TransformLocationProvider TransformLocationProvider { @@ -81,7 +82,7 @@ public TransformLocationProvider TransformLocationProvider } /// - /// Returns the serialized . + /// Returns the serialized . /// public EditorLocationProvider EditorLocationProvider { @@ -92,7 +93,7 @@ public EditorLocationProvider EditorLocationProvider } /// - /// Returns the serialized + /// Returns the serialized /// public DeviceLocationProvider DeviceLocationProvider { @@ -103,7 +104,7 @@ public DeviceLocationProvider DeviceLocationProvider } /// - /// Create singleton instance and inject the DefaulyLocationProvider upon initialization of this component. + /// Create singleton instance and inject the DefaultLocationProvider upon initialization of this component. /// private void Awake() {