[TASK] Initial commit with basic product setup

This commit is contained in:
2019-08-18 13:50:14 +02:00
commit 01a66a8e1f
2548 changed files with 167528 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
namespace Mapbox.Examples
{
using UnityEngine;
public class CameraBillboard : MonoBehaviour
{
public Camera _camera;
public void Start()
{
_camera = Camera.main;
}
void Update()
{
transform.LookAt(transform.position + _camera.transform.rotation * Vector3.forward, _camera.transform.rotation * Vector3.up);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 22805dac1b8933d49b89c409a8903cde
timeCreated: 1510777606
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,139 @@
namespace Mapbox.Examples
{
using UnityEngine;
using UnityEngine.EventSystems;
using Mapbox.Unity.Map;
public class CameraMovement : MonoBehaviour
{
[SerializeField]
AbstractMap _map;
[SerializeField]
float _panSpeed = 20f;
[SerializeField]
float _zoomSpeed = 50f;
[SerializeField]
Camera _referenceCamera;
Quaternion _originalRotation;
Vector3 _origin;
Vector3 _delta;
bool _shouldDrag;
void HandleTouch()
{
float zoomFactor = 0.0f;
//pinch to zoom.
switch (Input.touchCount)
{
case 1:
{
HandleMouseAndKeyBoard();
}
break;
case 2:
{
// Store both touches.
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
// Find the position in the previous frame of each touch.
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
// Find the magnitude of the vector (the distance) between the touches in each frame.
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
// Find the difference in the distances between each frame.
zoomFactor = 0.05f * (touchDeltaMag - prevTouchDeltaMag);
}
ZoomMapUsingTouchOrMouse(zoomFactor);
break;
default:
break;
}
}
void ZoomMapUsingTouchOrMouse(float zoomFactor)
{
var y = zoomFactor * _zoomSpeed;
transform.localPosition += (transform.forward * y);
}
void HandleMouseAndKeyBoard()
{
if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
{
var mousePosition = Input.mousePosition;
mousePosition.z = _referenceCamera.transform.localPosition.y;
_delta = _referenceCamera.ScreenToWorldPoint(mousePosition) - _referenceCamera.transform.localPosition;
_delta.y = 0f;
if (_shouldDrag == false)
{
_shouldDrag = true;
_origin = _referenceCamera.ScreenToWorldPoint(mousePosition);
}
}
else
{
_shouldDrag = false;
}
if (_shouldDrag == true)
{
var offset = _origin - _delta;
offset.y = transform.localPosition.y;
transform.localPosition = offset;
}
else
{
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
var x = Input.GetAxis("Horizontal");
var z = Input.GetAxis("Vertical");
var y = Input.GetAxis("Mouse ScrollWheel") * _zoomSpeed;
if (!(Mathf.Approximately(x, 0) || Mathf.Approximately(y, 0) || Mathf.Approximately(z, 0)))
{
transform.localPosition += transform.forward * y + (_originalRotation * new Vector3(x * _panSpeed, 0, z * _panSpeed));
_map.UpdateMap();
}
}
}
void Awake()
{
_originalRotation = Quaternion.Euler(0, transform.eulerAngles.y, 0);
if (_referenceCamera == null)
{
_referenceCamera = GetComponent<Camera>();
if (_referenceCamera == null)
{
throw new System.Exception("You must have a reference camera assigned!");
}
}
}
void LateUpdate()
{
if (Input.touchSupported && Input.touchCount > 0)
{
HandleTouch();
}
else
{
HandleMouseAndKeyBoard();
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9527fd56bc6a0c549a1e550219f9b16e
timeCreated: 1485631502
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
namespace Mapbox.Examples
{
using UnityEngine;
public class ChangeShadowDistance : MonoBehaviour
{
public int ShadowDistance;
void Start()
{
QualitySettings.shadowDistance = ShadowDistance;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ce97be288e861a243b6c6df4cc790edc
timeCreated: 1501704587
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mapbox.Examples
{
public class DragableDirectionWaypoint : MonoBehaviour
{
public Transform MoveTarget;
private Vector3 screenPoint;
private Vector3 offset;
private Plane _yPlane;
public void Start()
{
_yPlane = new Plane(Vector3.up, Vector3.zero);
}
void OnMouseDrag()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float enter = 0.0f;
if (_yPlane.Raycast(ray, out enter))
{
MoveTarget.position = ray.GetPoint(enter);
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 9c39c383c96521a4083f7339972619c7
timeCreated: 1528989212
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
namespace Mapbox.Examples
{
using UnityEngine;
using Mapbox.Unity.MeshGeneration.Data;
public class FeatureSelectionDetector : MonoBehaviour
{
private FeatureUiMarker _marker;
private VectorEntity _feature;
public void OnMouseUpAsButton()
{
_marker.Show(_feature);
}
internal void Initialize(FeatureUiMarker marker, VectorEntity ve)
{
_marker = marker;
_feature = ve;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 010d94246aba24241a3b67f258407dab
timeCreated: 1499984096
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,78 @@
namespace Mapbox.Examples
{
using Mapbox.Unity.MeshGeneration.Data;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class FeatureUiMarker : MonoBehaviour
{
[SerializeField]
private Transform _wrapperMarker;
[SerializeField]
private Transform _infoPanel;
[SerializeField]
private Text _info;
private Vector3[] _targetVerts;
private VectorEntity _selectedFeature;
void Update()
{
Snap();
}
internal void Clear()
{
gameObject.SetActive(false);
}
internal void Show(VectorEntity selectedFeature)
{
if (selectedFeature == null)
{
Clear();
return;
}
_selectedFeature = selectedFeature;
transform.position = new Vector3(0, 0, 0);
var mesh = selectedFeature.MeshFilter;
if (mesh != null)
{
_targetVerts = mesh.mesh.vertices;
Snap();
}
gameObject.SetActive(true);
}
private void Snap()
{
if (_targetVerts == null || _selectedFeature == null)
return;
var left = float.MaxValue;
var right = float.MinValue;
var top = float.MinValue;
var bottom = float.MaxValue;
foreach (var vert in _targetVerts)
{
var pos = Camera.main.WorldToScreenPoint(_selectedFeature.Transform.position + (_selectedFeature.Transform.lossyScale.x * vert));
if (pos.x < left)
left = pos.x;
else if (pos.x > right)
right = pos.x;
if (pos.y > top)
top = pos.y;
else if (pos.y < bottom)
bottom = pos.y;
}
_wrapperMarker.position = new Vector2(left - 10, top + 10);
(_wrapperMarker as RectTransform).sizeDelta = new Vector2(right - left + 20, top - bottom + 20);
_infoPanel.position = new Vector2(right + 10, top + 10);
_info.text = string.Join(" \r\n ", _selectedFeature.Feature.Properties.Select(x => x.Key + " - " + x.Value.ToString()).ToArray());
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 742344d451cea414d878bf6ae3951a8e
timeCreated: 1499980961
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,80 @@
//-----------------------------------------------------------------------
// <copyright file="ForwardGeocodeUserInput.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Examples
{
using Mapbox.Unity;
using UnityEngine;
using UnityEngine.UI;
using System;
using Mapbox.Geocoding;
using Mapbox.Utils;
[RequireComponent(typeof(InputField))]
public class ForwardGeocodeUserInput : MonoBehaviour
{
InputField _inputField;
ForwardGeocodeResource _resource;
Vector2d _coordinate;
public Vector2d Coordinate
{
get
{
return _coordinate;
}
}
bool _hasResponse;
public bool HasResponse
{
get
{
return _hasResponse;
}
}
public ForwardGeocodeResponse Response { get; private set; }
//public event Action<> OnGeocoderResponse = delegate { };
public event Action<ForwardGeocodeResponse> OnGeocoderResponse = delegate { };
void Awake()
{
_inputField = GetComponent<InputField>();
_inputField.onEndEdit.AddListener(HandleUserInput);
_resource = new ForwardGeocodeResource("");
}
void HandleUserInput(string searchString)
{
_hasResponse = false;
if (!string.IsNullOrEmpty(searchString))
{
_resource.Query = searchString;
MapboxAccess.Instance.Geocoder.Geocode(_resource, HandleGeocoderResponse);
}
}
void HandleGeocoderResponse(ForwardGeocodeResponse res)
{
_hasResponse = true;
if (null == res)
{
_inputField.text = "no geocode response";
}
else if (null != res.Features && res.Features.Count > 0)
{
var center = res.Features[0].Center;
//_inputField.text = string.Format("{0},{1}", center.x, center.y);
_coordinate = res.Features[0].Center;
}
Response = res;
OnGeocoderResponse(res);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9bce9ff37f5964623a657f4003af54f2
timeCreated: 1480366442
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,89 @@
//-----------------------------------------------------------------------
// <copyright file="HeroBuildingSelectionUserInput.cs" company="Mapbox">
// Copyright (c) 2018 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Examples
{
using Mapbox.Unity;
using UnityEngine;
using UnityEngine.UI;
using System;
using Mapbox.Geocoding;
using Mapbox.Utils;
using Mapbox.Unity.Location;
using Mapbox.Unity.Utilities;
public class HeroBuildingSelectionUserInput : MonoBehaviour
{
[Geocode]
public string location;
[SerializeField]
private Vector3 _cameraPosition;
[SerializeField]
private Vector3 _cameraRotation;
private Camera _camera;
Button _button;
ForwardGeocodeResource _resource;
bool _hasResponse;
public bool HasResponse
{
get
{
return _hasResponse;
}
}
public ForwardGeocodeResponse Response { get; private set; }
//public event Action<> OnGeocoderResponse = delegate { };
public event Action<ForwardGeocodeResponse, bool> OnGeocoderResponse = delegate { };
void Awake()
{
_button = GetComponent<Button>();
_button.onClick.AddListener(HandleUserInput);
_resource = new ForwardGeocodeResource("");
_camera = Camera.main;
}
void TransformCamera()
{
_camera.transform.position = _cameraPosition;
_camera.transform.localEulerAngles = _cameraRotation;
}
void HandleUserInput()
{
_hasResponse = false;
if (!string.IsNullOrEmpty(location))
{
_resource.Query = location;
MapboxAccess.Instance.Geocoder.Geocode(_resource, HandleGeocoderResponse);
}
}
void HandleGeocoderResponse(ForwardGeocodeResponse res)
{
_hasResponse = true;
Response = res;
TransformCamera();
OnGeocoderResponse(res, false);
}
public void BakeCameraTransform()
{
_cameraPosition = _camera.transform.position;
_cameraRotation = _camera.transform.localEulerAngles;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 587b1db6b06084de28d873bfbbff270c
timeCreated: 1534461976
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
namespace Mapbox.Examples
{
using UnityEngine;
using System.Collections.Generic;
public class HighlightFeature : MonoBehaviour
{
static Material _highlightMaterial;
private List<Material> _materials = new List<Material>();
MeshRenderer _meshRenderer;
void Start()
{
if (_highlightMaterial == null)
{
_highlightMaterial = Instantiate(GetComponent<MeshRenderer>().material);
_highlightMaterial.color = Color.red;
}
_meshRenderer = GetComponent<MeshRenderer>();
foreach (var item in _meshRenderer.sharedMaterials)
{
_materials.Add(item);
}
}
public void OnMouseEnter()
{
_meshRenderer.sharedMaterial = _highlightMaterial;
}
public void OnMouseExit()
{
_meshRenderer.materials = _materials.ToArray();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 64cb1b303dc6db64aa28a4229e62e9ed
timeCreated: 1499987937
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
namespace Mapbox.Examples
{
using Mapbox.Unity.Location;
using Mapbox.Unity.Map;
using UnityEngine;
public class ImmediatePositionWithLocationProvider : MonoBehaviour
{
//[SerializeField]
//private UnifiedMap _map;
bool _isInitialized;
ILocationProvider _locationProvider;
ILocationProvider LocationProvider
{
get
{
if (_locationProvider == null)
{
_locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider;
}
return _locationProvider;
}
}
Vector3 _targetPosition;
void Start()
{
LocationProviderFactory.Instance.mapManager.OnInitialized += () => _isInitialized = true;
}
void LateUpdate()
{
if (_isInitialized)
{
var map = LocationProviderFactory.Instance.mapManager;
transform.localPosition = map.GeoToWorldPosition(LocationProvider.CurrentLocation.LatitudeLongitude);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7760043eea2cd452ba7117f2c97e0038
timeCreated: 1512235497
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
namespace Mapbox.Examples
{
using Mapbox.Unity.MeshGeneration.Interfaces;
using System.Collections.Generic;
using UnityEngine;
public class LabelTextSetter : MonoBehaviour, IFeaturePropertySettable
{
[SerializeField]
TextMesh _textMesh;
public void Set(Dictionary<string, object> props)
{
_textMesh.text = "";
if (props.ContainsKey("name"))
{
_textMesh.text = props["name"].ToString();
}
else if (props.ContainsKey("house_num"))
{
_textMesh.text = props["house_num"].ToString();
}
else if (props.ContainsKey("type"))
{
_textMesh.text = props["type"].ToString();
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 75f4a424246980d46a214433149ef222
timeCreated: 1510776694
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
namespace Mapbox.Examples
{
using UnityEngine;
using Mapbox.Unity.Map;
using UnityEngine.UI;
public class LoadingPanelController : MonoBehaviour
{
[SerializeField]
GameObject _content;
[SerializeField]
Text _text;
[SerializeField]
AnimationCurve _curve;
AbstractMap _map;
void Awake()
{
_map = FindObjectOfType<AbstractMap>();
_map.OnInitialized += _map_OnInitialized;
}
void _map_OnInitialized()
{
var visualizer = _map.MapVisualizer;
_text.text = "LOADING";
visualizer.OnMapVisualizerStateChanged += (s) =>
{
if (this == null)
return;
if (s == ModuleState.Finished)
{
_content.SetActive(false);
}
else if (s == ModuleState.Working)
{
// Uncommment me if you want the loading screen to show again
// when loading new tiles.
//_content.SetActive(true);
}
};
}
void Update()
{
var t = _curve.Evaluate(Time.time);
_text.color = Color.Lerp(Color.clear, Color.white, t);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 81f500634e518f74bbba30a8e7d186bd
timeCreated: 1495661022
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
namespace Mapbox.Examples
{
using Mapbox.Unity.Location;
using Mapbox.Utils;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LocationStatus : MonoBehaviour
{
[SerializeField]
Text _statusText;
private AbstractLocationProvider _locationProvider = null;
void Start()
{
if (null == _locationProvider)
{
_locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider as AbstractLocationProvider;
}
}
void Update()
{
Location currLoc = _locationProvider.CurrentLocation;
if (currLoc.IsLocationServiceInitializing)
{
_statusText.text = "location services are initializing";
}
else
{
if (!currLoc.IsLocationServiceEnabled)
{
_statusText.text = "location services not enabled";
}
else
{
if (currLoc.LatitudeLongitude.Equals(Vector2d.zero))
{
_statusText.text = "Waiting for location ....";
}
else
{
_statusText.text = string.Format("{0}", currLoc.LatitudeLongitude);
}
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 57387868ef277924ea4a999647c6db75
timeCreated: 1521423856
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
namespace Mapbox.Examples
{
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Mapbox.Unity.MeshGeneration.Interfaces;
public class MakiHelper : MonoBehaviour, IFeaturePropertySettable
{
public static RectTransform Parent;
public static GameObject UiPrefab;
private GameObject _uiObject;
public void Set(Dictionary<string, object> props)
{
if (Parent == null)
{
var canv = GameObject.Find("PoiCanvas");
var ob = new GameObject("PoiContainer");
ob.transform.SetParent(canv.transform);
Parent = ob.AddComponent<RectTransform>();
UiPrefab = Resources.Load<GameObject>("MakiUiPrefab");
}
if (props.ContainsKey("maki"))
{
_uiObject = Instantiate(UiPrefab);
_uiObject.transform.SetParent(Parent);
_uiObject.transform.Find("Image").GetComponent<Image>().sprite = Resources.Load<Sprite>("maki/" + props["maki"].ToString() + "-15");
if (props.ContainsKey("name"))
{
_uiObject.GetComponentInChildren<Text>().text = props["name"].ToString();
}
}
}
public void LateUpdate()
{
if (_uiObject)
_uiObject.transform.position = Camera.main.WorldToScreenPoint(transform.position);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0c96e6ca6f8915940b5a184409597ca6
timeCreated: 1483230584
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
namespace Mapbox.Examples
{
using Mapbox.Unity.MeshGeneration.Data;
using UnityEngine;
using Mapbox.Unity.MeshGeneration.Components;
using UnityEngine.UI;
using Mapbox.Unity.MeshGeneration.Modifiers;
using System.Collections.Generic;
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Object Inspector Modifier")]
public class ObjectInspectorModifier : GameObjectModifier
{
private Dictionary<GameObject, FeatureSelectionDetector> _detectors;
private FeatureUiMarker _marker;
private FeatureSelectionDetector _tempDetector;
public override void Initialize()
{
if (_detectors == null)
{
_detectors = new Dictionary<GameObject, FeatureSelectionDetector>();
}
if (_marker == null)
{
Canvas canvas;
var go = new GameObject("InteractiveSelectionCanvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
canvas = go.GetComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
var sel = Instantiate(Resources.Load<GameObject>("selector"));
sel.transform.SetParent(canvas.transform);
_marker = sel.GetComponent<FeatureUiMarker>();
}
}
public override void Run(VectorEntity ve, UnityTile tile)
{
if (_detectors.ContainsKey(ve.GameObject))
{
_detectors[ve.GameObject].Initialize(_marker, ve);
}
else
{
_tempDetector = ve.GameObject.AddComponent<FeatureSelectionDetector>();
_detectors.Add(ve.GameObject, _tempDetector);
_tempDetector.Initialize(_marker, ve);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 68e011ce2209f4df1b390a7750c33744
timeCreated: 1500570143
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
namespace Mapbox.Examples
{
using Mapbox.Unity.MeshGeneration.Interfaces;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PoiLabelTextSetter : MonoBehaviour, IFeaturePropertySettable
{
[SerializeField]
Text _text;
[SerializeField]
Image _background;
public void Set(Dictionary<string, object> props)
{
_text.text = "";
if (props.ContainsKey("name"))
{
_text.text = props["name"].ToString();
}
else if (props.ContainsKey("house_num"))
{
_text.text = props["house_num"].ToString();
}
else if (props.ContainsKey("type"))
{
_text.text = props["type"].ToString();
}
RefreshBackground();
}
public void RefreshBackground()
{
RectTransform backgroundRect = _background.GetComponent<RectTransform>();
LayoutRebuilder.ForceRebuildLayoutImmediate(backgroundRect);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: ba99666da3af044c0ae878f372ea4115
timeCreated: 1523999824
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
namespace Mapbox.Examples
{
using UnityEngine;
using Mapbox.Unity.MeshGeneration.Interfaces;
using System.Collections.Generic;
public class PoiMarkerHelper : MonoBehaviour, IFeaturePropertySettable
{
Dictionary<string, object> _props;
public void Set(Dictionary<string, object> props)
{
_props = props;
}
void OnMouseUpAsButton()
{
foreach (var prop in _props)
{
Debug.Log(prop.Key + ":" + prop.Value);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 73a4653526c970849afac4be5c5930ba
timeCreated: 1494886137
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,86 @@
namespace Mapbox.Examples
{
using Mapbox.Unity.Location;
using Mapbox.Unity.Utilities;
using Mapbox.Unity.Map;
using UnityEngine;
public class PositionWithLocationProvider : MonoBehaviour
{
[SerializeField]
private AbstractMap _map;
/// <summary>
/// The rate at which the transform's position tries catch up to the provided location.
/// </summary>
[SerializeField]
float _positionFollowFactor;
/// <summary>
/// Use a mock <see cref="T:Mapbox.Unity.Location.TransformLocationProvider"/>,
/// rather than a <see cref="T:Mapbox.Unity.Location.EditorLocationProvider"/>.
/// </summary>
[SerializeField]
bool _useTransformLocationProvider;
bool _isInitialized;
/// <summary>
/// The location provider.
/// This is public so you change which concrete <see cref="T:Mapbox.Unity.Location.ILocationProvider"/> to use at runtime.
/// </summary>
ILocationProvider _locationProvider;
public ILocationProvider LocationProvider
{
private get
{
if (_locationProvider == null)
{
_locationProvider = _useTransformLocationProvider ?
LocationProviderFactory.Instance.TransformLocationProvider : 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;
_map.OnInitialized += () => _isInitialized = true;
}
void OnDestroy()
{
if (LocationProvider != null)
{
LocationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated;
}
}
void LocationProvider_OnLocationUpdated(Location location)
{
if (_isInitialized && location.IsLocationUpdated)
{
_targetPosition = _map.GeoToWorldPosition(location.LatitudeLongitude);
}
}
void Update()
{
transform.localPosition = Vector3.Lerp(transform.localPosition, _targetPosition, Time.deltaTime * _positionFollowFactor);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4bb39d89f6f3742418be7c93b4259637
timeCreated: 1492115167
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,312 @@
namespace Mapbox.Examples
{
using Mapbox.Unity.Map;
using Mapbox.Unity.Utilities;
using Mapbox.Utils;
using UnityEngine;
using UnityEngine.EventSystems;
using System;
public class QuadTreeCameraMovement : MonoBehaviour
{
[SerializeField]
[Range(1, 20)]
public float _panSpeed = 1.0f;
[SerializeField]
float _zoomSpeed = 0.25f;
[SerializeField]
public Camera _referenceCamera;
[SerializeField]
AbstractMap _mapManager;
[SerializeField]
bool _useDegreeMethod;
private Vector3 _origin;
private Vector3 _mousePosition;
private Vector3 _mousePositionPrevious;
private bool _shouldDrag;
private bool _isInitialized = false;
private Plane _groundPlane = new Plane(Vector3.up, 0);
private bool _dragStartedOnUI = false;
void Awake()
{
if (null == _referenceCamera)
{
_referenceCamera = GetComponent<Camera>();
if (null == _referenceCamera) { Debug.LogErrorFormat("{0}: reference camera not set", this.GetType().Name); }
}
_mapManager.OnInitialized += () =>
{
_isInitialized = true;
};
}
public void Update()
{
if (Input.GetMouseButtonDown(0) && EventSystem.current.IsPointerOverGameObject())
{
_dragStartedOnUI = true;
}
if (Input.GetMouseButtonUp(0))
{
_dragStartedOnUI = false;
}
}
private void LateUpdate()
{
if (!_isInitialized) { return; }
if (!_dragStartedOnUI)
{
if (Input.touchSupported && Input.touchCount > 0)
{
HandleTouch();
}
else
{
HandleMouseAndKeyBoard();
}
}
}
void HandleMouseAndKeyBoard()
{
// zoom
float scrollDelta = 0.0f;
scrollDelta = Input.GetAxis("Mouse ScrollWheel");
ZoomMapUsingTouchOrMouse(scrollDelta);
//pan keyboard
float xMove = Input.GetAxis("Horizontal");
float zMove = Input.GetAxis("Vertical");
PanMapUsingKeyBoard(xMove, zMove);
//pan mouse
PanMapUsingTouchOrMouse();
}
void HandleTouch()
{
float zoomFactor = 0.0f;
//pinch to zoom.
switch (Input.touchCount)
{
case 1:
{
PanMapUsingTouchOrMouse();
}
break;
case 2:
{
// Store both touches.
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
// Find the position in the previous frame of each touch.
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
// Find the magnitude of the vector (the distance) between the touches in each frame.
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
// Find the difference in the distances between each frame.
zoomFactor = 0.01f * (touchDeltaMag - prevTouchDeltaMag);
}
ZoomMapUsingTouchOrMouse(zoomFactor);
break;
default:
break;
}
}
void ZoomMapUsingTouchOrMouse(float zoomFactor)
{
var zoom = Mathf.Max(0.0f, Mathf.Min(_mapManager.Zoom + zoomFactor * _zoomSpeed, 21.0f));
if (Math.Abs(zoom - _mapManager.Zoom) > 0.0f)
{
_mapManager.UpdateMap(_mapManager.CenterLatitudeLongitude, zoom);
}
}
void PanMapUsingKeyBoard(float xMove, float zMove)
{
if (Math.Abs(xMove) > 0.0f || Math.Abs(zMove) > 0.0f)
{
// Get the number of degrees in a tile at the current zoom level.
// Divide it by the tile width in pixels ( 256 in our case)
// to get degrees represented by each pixel.
// Keyboard offset is in pixels, therefore multiply the factor with the offset to move the center.
float factor = _panSpeed * (Conversions.GetTileScaleInDegrees((float)_mapManager.CenterLatitudeLongitude.x, _mapManager.AbsoluteZoom));
//MapLocationOptions locationOptions = new MapLocationOptions
//{
var latitudeLongitude = new Vector2d(_mapManager.CenterLatitudeLongitude.x + zMove * factor * 2.0f, _mapManager.CenterLatitudeLongitude.y + xMove * factor * 4.0f);
//};
_mapManager.UpdateMap(latitudeLongitude, _mapManager.Zoom);
}
}
void PanMapUsingTouchOrMouse()
{
if (_useDegreeMethod)
{
UseDegreeConversion();
}
else
{
UseMeterConversion();
}
}
void UseMeterConversion()
{
if (Input.GetMouseButtonUp(1))
{
var mousePosScreen = Input.mousePosition;
//assign distance of camera to ground plane to z, otherwise ScreenToWorldPoint() will always return the position of the camera
//http://answers.unity3d.com/answers/599100/view.html
mousePosScreen.z = _referenceCamera.transform.localPosition.y;
var pos = _referenceCamera.ScreenToWorldPoint(mousePosScreen);
var latlongDelta = _mapManager.WorldToGeoPosition(pos);
Debug.Log("Latitude: " + latlongDelta.x + " Longitude: " + latlongDelta.y);
//_mapManager.UpdateMap(latlongDelta, _mapManager.Zoom);
}
if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
{
var mousePosScreen = Input.mousePosition;
//assign distance of camera to ground plane to z, otherwise ScreenToWorldPoint() will always return the position of the camera
//http://answers.unity3d.com/answers/599100/view.html
mousePosScreen.z = _referenceCamera.transform.localPosition.y;
_mousePosition = _referenceCamera.ScreenToWorldPoint(mousePosScreen);
if (_shouldDrag == false)
{
_shouldDrag = true;
_origin = _referenceCamera.ScreenToWorldPoint(mousePosScreen);
}
}
else
{
_shouldDrag = false;
}
if (_shouldDrag == true)
{
var changeFromPreviousPosition = _mousePositionPrevious - _mousePosition;
if (Mathf.Abs(changeFromPreviousPosition.x) > 0.0f || Mathf.Abs(changeFromPreviousPosition.y) > 0.0f)
{
_mousePositionPrevious = _mousePosition;
var offset = _origin - _mousePosition;
if (Mathf.Abs(offset.x) > 0.0f || Mathf.Abs(offset.z) > 0.0f)
{
if (null != _mapManager)
{
float factor = _panSpeed * Conversions.GetTileScaleInMeters((float)0, _mapManager.AbsoluteZoom) / _mapManager.UnityTileSize;
var latlongDelta = Conversions.MetersToLatLon(new Vector2d(offset.x * factor, offset.z * factor));
//Debug.Log("LatLong Delta : " + latlongDelta);
var newLatLong = _mapManager.CenterLatitudeLongitude + latlongDelta;
//MapLocationOptions locationOptions = new MapLocationOptions
//{
// latitudeLongitude = String.Format("{0},{1}", newLatLong.x, newLatLong.y),
// zoom = _mapManager.Zoom
//};
_mapManager.UpdateMap(newLatLong, _mapManager.Zoom);
}
}
_origin = _mousePosition;
}
else
{
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
_mousePositionPrevious = _mousePosition;
_origin = _mousePosition;
}
}
}
void UseDegreeConversion()
{
if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
{
var mousePosScreen = Input.mousePosition;
//assign distance of camera to ground plane to z, otherwise ScreenToWorldPoint() will always return the position of the camera
//http://answers.unity3d.com/answers/599100/view.html
mousePosScreen.z = _referenceCamera.transform.localPosition.y;
_mousePosition = _referenceCamera.ScreenToWorldPoint(mousePosScreen);
if (_shouldDrag == false)
{
_shouldDrag = true;
_origin = _referenceCamera.ScreenToWorldPoint(mousePosScreen);
}
}
else
{
_shouldDrag = false;
}
if (_shouldDrag == true)
{
var changeFromPreviousPosition = _mousePositionPrevious - _mousePosition;
if (Mathf.Abs(changeFromPreviousPosition.x) > 0.0f || Mathf.Abs(changeFromPreviousPosition.y) > 0.0f)
{
_mousePositionPrevious = _mousePosition;
var offset = _origin - _mousePosition;
if (Mathf.Abs(offset.x) > 0.0f || Mathf.Abs(offset.z) > 0.0f)
{
if (null != _mapManager)
{
// Get the number of degrees in a tile at the current zoom level.
// Divide it by the tile width in pixels ( 256 in our case)
// to get degrees represented by each pixel.
// Mouse offset is in pixels, therefore multiply the factor with the offset to move the center.
float factor = _panSpeed * Conversions.GetTileScaleInDegrees((float)_mapManager.CenterLatitudeLongitude.x, _mapManager.AbsoluteZoom) / _mapManager.UnityTileSize;
//MapLocationOptions locationOptions = new MapLocationOptions
//{
// latitudeLongitude = String.Format("{0},{1}", _mapManager.CenterLatitudeLongitude.x + offset.z * factor, _mapManager.CenterLatitudeLongitude.y + offset.x * factor),
// zoom = _mapManager.Zoom
//};
var latitudeLongitude = new Vector2d(_mapManager.CenterLatitudeLongitude.x + offset.z * factor, _mapManager.CenterLatitudeLongitude.y + offset.x * factor);
_mapManager.UpdateMap(latitudeLongitude, _mapManager.Zoom);
}
}
_origin = _mousePosition;
}
else
{
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
_mousePositionPrevious = _mousePosition;
_origin = _mousePosition;
}
}
}
private Vector3 getGroundPlaneHitPoint(Ray ray)
{
float distance;
if (!_groundPlane.Raycast(ray, out distance)) { return Vector3.zero; }
return ray.GetPoint(distance);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2c699b8e1864b4b248acb7a04ede9480
timeCreated: 1508527204
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,98 @@
namespace Mapbox.Examples
{
using Mapbox.Geocoding;
using UnityEngine.UI;
using Mapbox.Unity.Map;
using UnityEngine;
using System;
using System.Collections;
public class ReloadMap : MonoBehaviour
{
Camera _camera;
Vector3 _cameraStartPos;
AbstractMap _map;
[SerializeField]
ForwardGeocodeUserInput _forwardGeocoder;
[SerializeField]
Slider _zoomSlider;
private HeroBuildingSelectionUserInput[] _heroBuildingSelectionUserInput;
Coroutine _reloadRoutine;
WaitForSeconds _wait;
void Awake()
{
_camera = Camera.main;
_cameraStartPos = _camera.transform.position;
_map = FindObjectOfType<AbstractMap>();
if(_map == null)
{
Debug.LogError("Error: No Abstract Map component found in scene.");
return;
}
if (_zoomSlider != null)
{
_map.OnUpdated += () => { _zoomSlider.value = _map.Zoom; };
_zoomSlider.onValueChanged.AddListener(Reload);
}
if(_forwardGeocoder != null)
{
_forwardGeocoder.OnGeocoderResponse += ForwardGeocoder_OnGeocoderResponse;
}
_heroBuildingSelectionUserInput = GetComponentsInChildren<HeroBuildingSelectionUserInput>();
if(_heroBuildingSelectionUserInput != null)
{
for (int i = 0; i < _heroBuildingSelectionUserInput.Length; i++)
{
_heroBuildingSelectionUserInput[i].OnGeocoderResponse += ForwardGeocoder_OnGeocoderResponse;
}
}
_wait = new WaitForSeconds(.3f);
}
void ForwardGeocoder_OnGeocoderResponse(ForwardGeocodeResponse response)
{
if (null != response.Features && response.Features.Count > 0)
{
int zoom = _map.AbsoluteZoom;
_map.UpdateMap(response.Features[0].Center, zoom);
}
}
void ForwardGeocoder_OnGeocoderResponse(ForwardGeocodeResponse response, bool resetCamera)
{
if (response == null)
{
return;
}
if (resetCamera)
{
_camera.transform.position = _cameraStartPos;
}
ForwardGeocoder_OnGeocoderResponse(response);
}
void Reload(float value)
{
if (_reloadRoutine != null)
{
StopCoroutine(_reloadRoutine);
_reloadRoutine = null;
}
_reloadRoutine = StartCoroutine(ReloadAfterDelay((int)value));
}
IEnumerator ReloadAfterDelay(int zoom)
{
yield return _wait;
_camera.transform.position = _cameraStartPos;
_map.UpdateMap(_map.CenterLatitudeLongitude, zoom);
_reloadRoutine = null;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c00b1c78fb49f4ebd834aac587275216
timeCreated: 1506100530
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,88 @@
//-----------------------------------------------------------------------
// <copyright file="ReverseGeocodeUserInput.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Examples
{
using Mapbox.Unity;
using System;
using UnityEngine;
using UnityEngine.UI;
using Mapbox.Geocoding;
using Mapbox.Utils;
using Mapbox.Unity.Utilities;
/// <summary>
/// Peforms a reverse geocoder request (search by latitude, longitude) whenever the InputField on *this*
/// gameObject is finished with an edit.
/// Expects input in the form of "latitude, longitude"
/// </summary>
[RequireComponent(typeof(InputField))]
public class ReverseGeocodeUserInput : MonoBehaviour
{
InputField _inputField;
ReverseGeocodeResource _resource;
Geocoder _geocoder;
Vector2d _coordinate;
bool _hasResponse;
public bool HasResponse
{
get
{
return _hasResponse;
}
}
public ReverseGeocodeResponse Response { get; private set;}
public event EventHandler<EventArgs> OnGeocoderResponse;
void Awake()
{
_inputField = GetComponent<InputField>();
_inputField.onEndEdit.AddListener(HandleUserInput);
_resource = new ReverseGeocodeResource(_coordinate);
}
void Start()
{
_geocoder = MapboxAccess.Instance.Geocoder;
}
/// <summary>
/// An edit was made to the InputField.
/// Unity will send the string from _inputField.
/// Make geocoder query.
/// </summary>
/// <param name="searchString">Search string.</param>
void HandleUserInput(string searchString)
{
_hasResponse = false;
if (!string.IsNullOrEmpty(searchString))
{
_coordinate = Conversions.StringToLatLon(searchString);
_resource.Query = _coordinate;
_geocoder.Geocode(_resource, HandleGeocoderResponse);
}
}
/// <summary>
/// Handles the geocoder response by updating coordinates and notifying observers.
/// </summary>
/// <param name="res">Res.</param>
void HandleGeocoderResponse(ReverseGeocodeResponse res)
{
_hasResponse = true;
Response = res;
if (OnGeocoderResponse != null)
{
OnGeocoderResponse(this, EventArgs.Empty);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 872cc2c04f0c94a39a7647e7ed7667e1
timeCreated: 1480366442
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,164 @@
namespace Mapbox.Examples
{
using Mapbox.Unity.Location;
using UnityEngine;
public class RotateWithLocationProvider : MonoBehaviour
{
/// <summary>
/// Location property used for rotation: false=Heading (default), true=Orientation
/// </summary>
[SerializeField]
[Tooltip("Per default 'UserHeading' (direction the device is moving) is used for rotation. Check to use 'DeviceOrientation' (where the device is facing)")]
bool _useDeviceOrientation;
/// <summary>
///
/// </summary>
[SerializeField]
[Tooltip("Only evaluated when 'Use Device Orientation' is checked. Subtracts UserHeading from DeviceOrientation. Useful if map is rotated by UserHeading and DeviceOrientation should be displayed relative to the heading.")]
bool _subtractUserHeading;
/// <summary>
/// The rate at which the transform's rotation tries catch up to the provided heading.
/// </summary>
[SerializeField]
[Tooltip("The rate at which the transform's rotation tries catch up to the provided heading. ")]
float _rotationFollowFactor = 1;
/// <summary>
/// Set this to true if you'd like to adjust the rotation of a RectTransform (in a UI canvas) with the heading.
/// </summary>
[SerializeField]
bool _rotateZ;
/// <summary>
/// <para>Set this to true if you'd like to adjust the sign of the rotation angle.</para>
/// <para>eg angle passed in 63.5, angle that should be used for rotation: -63.5.</para>
/// <para>This might be needed when rotating the map and not objects on the map.</para>
/// </summary>
[SerializeField]
[Tooltip("Set this to true if you'd like to adjust the sign of the rotation angle. eg angle passed in 63.5, angle that should be used for rotation: -63.5.")]
bool _useNegativeAngle;
/// <summary>
/// Use a mock <see cref="T:Mapbox.Unity.Location.TransformLocationProvider"/>,
/// rather than a <see cref="T:Mapbox.Unity.Location.EditorLocationProvider"/>.
/// </summary>
[SerializeField]
bool _useTransformLocationProvider;
Quaternion _targetRotation;
/// <summary>
/// The location provider.
/// This is public so you change which concrete <see cref="ILocationProvider"/> to use at runtime.
/// </summary>
ILocationProvider _locationProvider;
public ILocationProvider LocationProvider
{
private get
{
if (_locationProvider == null)
{
_locationProvider = _useTransformLocationProvider ?
LocationProviderFactory.Instance.TransformLocationProvider : 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(Location location)
{
float rotationAngle = _useDeviceOrientation ? location.DeviceOrientation : location.UserHeading;
if (_useNegativeAngle) { rotationAngle *= -1f; }
// 'Orientation' changes all the time, pass through immediately
if (_useDeviceOrientation)
{
if (_subtractUserHeading)
{
if (rotationAngle > location.UserHeading)
{
rotationAngle = 360 - (rotationAngle - location.UserHeading);
}
else
{
rotationAngle = location.UserHeading - rotationAngle + 360;
}
if (rotationAngle < 0) { rotationAngle += 360; }
if (rotationAngle >= 360) { rotationAngle -= 360; }
}
_targetRotation = Quaternion.Euler(getNewEulerAngles(rotationAngle));
}
else
{
// if rotating by 'Heading' only do it if heading has a new value
if (location.IsUserHeadingUpdated)
{
_targetRotation = Quaternion.Euler(getNewEulerAngles(rotationAngle));
}
}
}
private Vector3 getNewEulerAngles(float newAngle)
{
var localRotation = transform.localRotation;
var currentEuler = localRotation.eulerAngles;
var euler = Mapbox.Unity.Constants.Math.Vector3Zero;
if (_rotateZ)
{
euler.z = -newAngle;
euler.x = currentEuler.x;
euler.y = currentEuler.y;
}
else
{
euler.y = -newAngle;
euler.x = currentEuler.x;
euler.z = currentEuler.z;
}
return euler;
}
void Update()
{
transform.localRotation = Quaternion.Lerp(transform.localRotation, _targetRotation, Time.deltaTime * _rotationFollowFactor);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 061d2afb48ace4fd19611279b6cf732f
timeCreated: 1492115182
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mapbox.Examples
{
public class TrafficUvAnimator : MonoBehaviour
{
public Material[] Materials;
public float Speed;
private Vector2 _offset;
void Start()
{
}
void Update()
{
_offset.Set(_offset.x + Time.deltaTime * Speed, 0.2f);
foreach (var item in Materials)
{
item.SetTextureOffset("_MainTex", _offset);
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: e63ef20f8dd90df4789bc9f4d8d22083
timeCreated: 1528933518
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,114 @@
namespace Mapbox.Unity.Map
{
using System.Collections;
using Mapbox.Unity.Location;
using UnityEngine;
public class UpdateMapWithLocationProvider : MonoBehaviour
{
[SerializeField]
AbstractMap _map;
ILocationProvider _locationProvider;
Vector3 _targetPosition;
bool _isMapInitialized = false;
/// <summary>
/// The time taken to move from the start to finish positions
/// </summary>
public float timeTakenDuringLerp = 1f;
//Whether we are currently interpolating or not
private bool _isLerping;
//The start and finish positions for the interpolation
private Vector3 _startPosition;
private Vector3 _endPosition;
private Utils.Vector2d _startLatLong;
private Utils.Vector2d _endLatlong;
//The Time.time value when we started the interpolation
private float _timeStartedLerping;
private void Awake()
{
// Prevent double initialization of the map.
_map.InitializeOnStart = false;
}
IEnumerator Start()
{
yield return null;
_locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider;
_locationProvider.OnLocationUpdated += LocationProvider_OnFirstLocationUpdate;
}
void LocationProvider_OnFirstLocationUpdate(Unity.Location.Location location)
{
_locationProvider.OnLocationUpdated -= LocationProvider_OnFirstLocationUpdate;
_map.OnInitialized += () =>
{
_isMapInitialized = true;
_locationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated;
};
_map.Initialize(location.LatitudeLongitude, _map.AbsoluteZoom);
}
void LocationProvider_OnLocationUpdated(Unity.Location.Location location)
{
if (_isMapInitialized && location.IsLocationUpdated)
{
StartLerping(location);
}
}
/// <summary>
/// Called to begin the linear interpolation
/// </summary>
void StartLerping(Unity.Location.Location location)
{
_isLerping = true;
_timeStartedLerping = Time.time;
//Debug.Log(Time.deltaTime);
timeTakenDuringLerp = Time.deltaTime;
//We set the start position to the current position
_startLatLong = _map.CenterLatitudeLongitude;
_endLatlong = location.LatitudeLongitude;
_startPosition = _map.GeoToWorldPosition(_startLatLong, false);
_endPosition = _map.GeoToWorldPosition(_endLatlong, false);
}
//We do the actual interpolation in FixedUpdate(), since we're dealing with a rigidbody
void LateUpdate()
{
if (_isMapInitialized && _isLerping)
{
//We want percentage = 0.0 when Time.time = _timeStartedLerping
//and percentage = 1.0 when Time.time = _timeStartedLerping + timeTakenDuringLerp
//In other words, we want to know what percentage of "timeTakenDuringLerp" the value
//"Time.time - _timeStartedLerping" is.
float timeSinceStarted = Time.time - _timeStartedLerping;
float percentageComplete = timeSinceStarted / timeTakenDuringLerp;
//Perform the actual lerping. Notice that the first two parameters will always be the same
//throughout a single lerp-processs (ie. they won't change until we hit the space-bar again
//to start another lerp)
//_startPosition = _map.GeoToWorldPosition(_map.CenterLatitudeLongitude, false);
_startPosition = _map.GeoToWorldPosition(_startLatLong, false);
_endPosition = _map.GeoToWorldPosition(_endLatlong, false);
var position = Vector3.Lerp(_startPosition, _endPosition, percentageComplete);
var latLong = _map.WorldToGeoPosition(position);
_map.UpdateMap(latLong, _map.Zoom);
//When we've completed the lerp, we set _isLerping to false
if (percentageComplete >= 1.0f)
{
_isLerping = false;
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: b45b6cb0c94914eb6a1fac86abfc6aba
timeCreated: 1524787995
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: