海拔图和小地图
This commit is contained in:
1 parent
42fa59d103
commit
8ad36c965d
521 files changed
+1985033
-439
No files matched your search
@@ -6,6 +6,7 @@ using Mapbox.Utils;
|
||||
using System.Collections;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using Mapbox.Unity.Utilities;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
@@ -13,9 +14,8 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
[SerializeField]
|
||||
AbstractMap _map;
|
||||
|
||||
[SerializeField]
|
||||
MeshModifier[] MeshModifiers;
|
||||
MeshModifier SnapModifier;
|
||||
[SerializeField]
|
||||
Material _material;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
private int _counter;
|
||||
|
||||
GameObject _directionsGO;
|
||||
GameObject _mipMapRoute;
|
||||
MainController mainCotroller;
|
||||
|
||||
protected virtual void Awake()
|
||||
@@ -36,16 +37,12 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
_map.OnInitialized += CreateRoute;
|
||||
_map.OnUpdated += CreateRoute;
|
||||
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
mainCotroller = transform.parent.GetComponent<MainController>();
|
||||
foreach (var modifier in MeshModifiers)
|
||||
{
|
||||
modifier.Initialize();
|
||||
}
|
||||
|
||||
StartCoroutine(QueryTimer());
|
||||
}
|
||||
|
||||
@@ -65,60 +62,86 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
void CreateRoute()
|
||||
{
|
||||
var meshData = new MeshData();
|
||||
var dat = new List<Vector3>();
|
||||
|
||||
var mapData = mainCotroller.GetMapData();
|
||||
if (mapData != null)
|
||||
UnityTile tile;
|
||||
bool foundTile = _map.MapVisualizer.ActiveTiles.TryGetValue(Conversions.LatitudeLongitudeToTileId(_map.CenterLatitudeLongitude.x, _map.CenterLatitudeLongitude.y, (int)_map.Zoom), out tile);
|
||||
if (foundTile)
|
||||
{
|
||||
foreach (var mapDataItem in mapData.List)
|
||||
{
|
||||
var point = mapDataItem.Point;
|
||||
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
|
||||
item.y += 0.2f;
|
||||
dat.Add(item);
|
||||
}
|
||||
var feat = new VectorFeatureUnity();
|
||||
feat.Points.Add(dat);
|
||||
foreach (MeshModifier mod in MeshModifiers.Where(x => x.Active))
|
||||
{
|
||||
mod.Run(feat, meshData, _map.WorldRelativeScale * 8);
|
||||
var meshData = new MeshData();
|
||||
var dat = new List<Vector3>();
|
||||
|
||||
var mapData = mainCotroller.GetMapData();
|
||||
if (mapData != null)
|
||||
{
|
||||
foreach (var mapDataItem in mapData.List)
|
||||
{
|
||||
var point = mapDataItem.Point;
|
||||
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
|
||||
item.y += 0.3f;
|
||||
dat.Add(item);
|
||||
}
|
||||
var feat = new VectorFeatureUnity();
|
||||
feat.Points.Add(dat);
|
||||
//处理海拔高度的问题
|
||||
SnapModifier.Run(feat, meshData, tile);
|
||||
CreatMapRoute(feat);//创建路线
|
||||
CreateMiniMapRoute(feat);//创建小地图路线
|
||||
}
|
||||
CreateGameObject(meshData);
|
||||
}
|
||||
}
|
||||
|
||||
GameObject CreateGameObject(MeshData data)
|
||||
void CreatMapRoute(VectorFeatureUnity feat)
|
||||
{
|
||||
if (_directionsGO != null)
|
||||
{
|
||||
_directionsGO.Destroy();
|
||||
}
|
||||
_directionsGO = new GameObject("MapRoute");
|
||||
var mesh = _directionsGO.AddComponent<MeshFilter>().mesh;
|
||||
mesh.subMeshCount = data.Triangles.Count;
|
||||
var lineRender = _directionsGO.AddComponent<LineRenderer>();
|
||||
lineRender.material = new Material(Shader.Find("Sprites/Default"));
|
||||
var dat = feat.Points[0];
|
||||
ColorUtility.TryParseHtmlString("#FF2742", out Color c);
|
||||
lineRender.endColor = c;
|
||||
lineRender.startColor = c;
|
||||
//设置宽度
|
||||
lineRender.SetWidth(0.8f, 0.8f);
|
||||
lineRender.SetVertexCount(dat.Count);
|
||||
lineRender.SetPositions(feat.Points[0].ToArray());
|
||||
//lineRender.numCapVertices = 90;
|
||||
float alpha = 1.0f;
|
||||
//Gradient gradient = new Gradient();
|
||||
//gradient.SetKeys(
|
||||
// new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
|
||||
// new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
|
||||
//);
|
||||
//lineRender.colorGradient = gradient;
|
||||
lineRender.numCornerVertices = 90;
|
||||
|
||||
mesh.SetVertices(data.Vertices);
|
||||
_counter = data.Triangles.Count;
|
||||
for (int i = 0; i < _counter; i++)
|
||||
}
|
||||
void CreateMiniMapRoute(VectorFeatureUnity feat)
|
||||
{
|
||||
if (_mipMapRoute != null)
|
||||
{
|
||||
var triangle = data.Triangles[i];
|
||||
mesh.SetTriangles(triangle, i);
|
||||
_mipMapRoute.Destroy();
|
||||
}
|
||||
|
||||
_counter = data.UV.Count;
|
||||
for (int i = 0; i < _counter; i++)
|
||||
{
|
||||
var uv = data.UV[i];
|
||||
mesh.SetUVs(i, uv);
|
||||
}
|
||||
|
||||
mesh.RecalculateNormals();
|
||||
_directionsGO.AddComponent<MeshRenderer>().material = _material;
|
||||
|
||||
return _directionsGO;
|
||||
_mipMapRoute = new GameObject("MiniMapRoute");
|
||||
var lineRender = _mipMapRoute.AddComponent<LineRenderer>();
|
||||
lineRender.material = new Material(Shader.Find("Sprites/Default"));
|
||||
var dat = feat.Points[0];
|
||||
lineRender.endColor = Color.red;
|
||||
lineRender.startColor = Color.blue;
|
||||
//设置宽度
|
||||
lineRender.SetWidth(3f, 3f);
|
||||
lineRender.SetVertexCount(dat.Count);
|
||||
lineRender.SetPositions(feat.Points[0].ToArray());
|
||||
lineRender.numCapVertices = 90;
|
||||
float alpha = 1.0f;
|
||||
Gradient gradient = new Gradient();
|
||||
gradient.SetKeys(
|
||||
new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
|
||||
new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
|
||||
);
|
||||
lineRender.colorGradient = gradient;
|
||||
lineRender.numCornerVertices = 90;
|
||||
_mipMapRoute.layer = 9;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user