单人骑行
This commit is contained in:
1 parent
326b74bd03
commit
971a6f7e0e
2597 files changed
+427802
-4
No files matched your search
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
using Mapbox.Directions;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using Mapbox.Utils;
|
||||
using Mapbox.Unity.Utilities;
|
||||
using Mapbox.Unity;
|
||||
using System;
|
||||
|
||||
namespace Mapbox.Examples
|
||||
{
|
||||
public class AstronautDirections : MonoBehaviour
|
||||
{
|
||||
AbstractMap _map;
|
||||
Directions.Directions _directions;
|
||||
Action<List<Vector3>> callback;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_directions = MapboxAccess.Instance.Directions;
|
||||
}
|
||||
|
||||
public void Query(Action<List<Vector3>> vecs, Transform start, Transform end, AbstractMap map)
|
||||
{
|
||||
if (callback == null)
|
||||
callback = vecs;
|
||||
|
||||
_map = map;
|
||||
|
||||
var wp = new Vector2d[2];
|
||||
wp[0] = start.GetGeoPosition(_map.CenterMercator, _map.WorldRelativeScale);
|
||||
wp[1] = end.GetGeoPosition(_map.CenterMercator, _map.WorldRelativeScale);
|
||||
var _directionResource = new DirectionResource(wp, RoutingProfile.Walking);
|
||||
_directionResource.Steps = true;
|
||||
_directions.Query(_directionResource, HandleDirectionsResponse);
|
||||
}
|
||||
|
||||
void HandleDirectionsResponse(DirectionsResponse response)
|
||||
{
|
||||
if (null == response.Routes || response.Routes.Count < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dat = new List<Vector3>();
|
||||
foreach (var point in response.Routes[0].Geometry)
|
||||
{
|
||||
dat.Add(Conversions.GeoToWorldPosition(point.x, point.y, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz());
|
||||
}
|
||||
|
||||
callback(dat);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user