单人骑行
This commit is contained in:
1 parent
326b74bd03
commit
971a6f7e0e
2597 files changed
+427802
-4
No files matched your search
@@ -0,0 +1,131 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Factories
|
||||
{
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Mapbox.Unity.Map;
|
||||
using Data;
|
||||
using Modifiers;
|
||||
using Mapbox.Utils;
|
||||
using Mapbox.Unity.Utilities;
|
||||
using System.Collections;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
|
||||
public class RouteController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
AbstractMap _map;
|
||||
|
||||
[SerializeField]
|
||||
MeshModifier[] MeshModifiers;
|
||||
[SerializeField]
|
||||
Material _material;
|
||||
|
||||
[SerializeField]
|
||||
[Range(1, 10)]
|
||||
private float UpdateFrequency = 2;
|
||||
|
||||
private int _counter;
|
||||
|
||||
GameObject _directionsGO;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
if (_map == null)
|
||||
{
|
||||
_map = FindObjectOfType<AbstractMap>();
|
||||
}
|
||||
_map.OnInitialized += CreateRoute;
|
||||
_map.OnUpdated += CreateRoute;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
foreach (var modifier in MeshModifiers)
|
||||
{
|
||||
modifier.Initialize();
|
||||
}
|
||||
|
||||
StartCoroutine(QueryTimer());
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
_map.OnInitialized -= CreateRoute;
|
||||
_map.OnUpdated -= CreateRoute;
|
||||
}
|
||||
|
||||
public IEnumerator QueryTimer()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForSeconds(UpdateFrequency);
|
||||
CreateRoute();
|
||||
}
|
||||
}
|
||||
void CreateRoute()
|
||||
{
|
||||
var meshData = new MeshData();
|
||||
var dat = new List<Vector3>();
|
||||
|
||||
List<Vector2d> points = MockData.vl;
|
||||
if (points == null)
|
||||
{
|
||||
points = MockData.GetRideList();
|
||||
}
|
||||
{
|
||||
foreach (var point in points)
|
||||
{
|
||||
Vector3 item = _map.GeoToWorldPosition(point);//point.x, point.y, _map.CenterMercator, _map.WorldRelativeScale);
|
||||
//item.y = (float)(_map.QueryElevationInUnityUnitsAt(point))+0.3f;
|
||||
item.y += 0.5f;
|
||||
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);
|
||||
|
||||
}
|
||||
CreateGameObject(meshData);
|
||||
}
|
||||
}
|
||||
|
||||
GameObject CreateGameObject(MeshData data)
|
||||
{
|
||||
if (_directionsGO != null)
|
||||
{
|
||||
_directionsGO.Destroy();
|
||||
}
|
||||
_directionsGO = new GameObject("direction waypoint " + " entity");
|
||||
var mesh = _directionsGO.AddComponent<MeshFilter>().mesh;
|
||||
mesh.subMeshCount = data.Triangles.Count;
|
||||
|
||||
mesh.SetVertices(data.Vertices);
|
||||
_counter = data.Triangles.Count;
|
||||
for (int i = 0; i < _counter; i++)
|
||||
{
|
||||
var triangle = data.Triangles[i];
|
||||
mesh.SetTriangles(triangle, i);
|
||||
}
|
||||
|
||||
_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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user