场景加载处理一些卡顿的情况
This commit is contained in:
1 parent
e7a3214cb5
commit
65fc5b5c50
35 files changed
+8668
-2075
No files matched your search
@@ -28,6 +28,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
GameObject _directionsGO;
|
||||
GameObject _mipMapRoute;
|
||||
CyclingController cyclingCotroller;
|
||||
private bool initComplete = false;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
@@ -35,14 +36,41 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
_map = FindObjectOfType<AbstractMap>();
|
||||
}
|
||||
_map.OnInitialized += CreateRoute;
|
||||
_map.OnUpdated += CreateRoute;
|
||||
|
||||
// _map.OnInitialized += _map_OnInitialized; ;
|
||||
//_map.OnUpdated += _map_OnUpdated; ;
|
||||
//_map.OnTileFinished += _map_OnTileFinished; ;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void _map_OnUpdated()
|
||||
{
|
||||
Debug.Log("_map_OnUpdated");
|
||||
}
|
||||
|
||||
private void _map_OnInitialized()
|
||||
{
|
||||
Debug.Log("_map_OnInitialized");
|
||||
CreateRoute();
|
||||
}
|
||||
|
||||
private void _map_OnTileFinished(UnityTile obj)
|
||||
{
|
||||
|
||||
if (!initComplete)
|
||||
{
|
||||
Debug.Log(47);
|
||||
CreateRoute(obj);
|
||||
initComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PlayerController playerController;
|
||||
public void Start()
|
||||
{
|
||||
cyclingCotroller = transform.parent.GetComponent<CyclingController>();
|
||||
playerController = FindObjectOfType<PlayerController>();
|
||||
StartCoroutine(QueryTimer());
|
||||
//CreateRoute();
|
||||
}
|
||||
@@ -57,10 +85,54 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Debug.Log(88);
|
||||
yield return new WaitForSeconds(UpdateFrequency);
|
||||
CreateRoute();
|
||||
CreateRoute(null);
|
||||
}
|
||||
}
|
||||
|
||||
void CreateRoute(UnityTile tile)
|
||||
{
|
||||
{
|
||||
var meshData = new MeshData();
|
||||
var dat = new List<Vector3>();
|
||||
|
||||
var mapData = cyclingCotroller.GetMapData();
|
||||
if (mapData != null)
|
||||
{
|
||||
foreach (var mapDataItem in mapData.List)
|
||||
{
|
||||
var point = mapDataItem.Point;
|
||||
|
||||
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
|
||||
var distance = TurfCS.Turf.Distance(TurfCS.Turf.Point(new double[] { playerController.Nextlatlong.x, playerController.Nextlatlong.y }), TurfCS.Turf.Point(new double[] { point[0], point[1]}));
|
||||
if (distance<10)
|
||||
{
|
||||
item.y += 0.3f;
|
||||
dat.Add(item);
|
||||
}
|
||||
}
|
||||
var feat = new VectorFeatureUnity();
|
||||
feat.Points.Add(dat);
|
||||
//处理海拔高度的问题
|
||||
//SnapModifier.Run(feat, meshData, tile);
|
||||
CreatMapRoute(feat);//创建路线
|
||||
CreateMiniMapRoute(feat);//创建小地图路线
|
||||
}
|
||||
}
|
||||
}
|
||||
bool posInScreen(Vector3 position)
|
||||
{
|
||||
Transform camreatra = Camera.main.transform;
|
||||
Vector3 viewPos = Camera.main.WorldToViewportPoint(position);
|
||||
Vector3 dir = (position - camreatra.position).normalized;
|
||||
float dot = Vector3.Dot(camreatra.forward, dir);
|
||||
if (dot > 0 && viewPos.x > 0 && viewPos.x < 1 && viewPos.y > 0 && viewPos.y < 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void CreateRoute()
|
||||
{
|
||||
UnityTile tile;
|
||||
@@ -96,6 +168,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
_directionsGO.Destroy();
|
||||
}
|
||||
_directionsGO = new GameObject("MapRoute");
|
||||
_directionsGO.transform.parent = transform;
|
||||
var lineRender = _directionsGO.AddComponent<LineRenderer>();
|
||||
lineRender.material = new Material(Shader.Find("Sprites/Default"));
|
||||
var dat = feat.Points[0];
|
||||
@@ -124,6 +197,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
_mipMapRoute.Destroy();
|
||||
}
|
||||
_mipMapRoute = new GameObject("MiniMapRoute");
|
||||
_mipMapRoute.transform.parent = transform;
|
||||
var lineRender = _mipMapRoute.AddComponent<LineRenderer>();
|
||||
lineRender.material = new Material(Shader.Find("Sprites/Default"));
|
||||
var dat = feat.Points[0];
|
||||
|
||||
Reference in new issue
Block a user