Added test mode and manual positioning

This commit is contained in:
2026-03-21 22:40:20 +01:00
parent a1b40ad102
commit be595da357
7 changed files with 481 additions and 73 deletions

View File

@@ -89,7 +89,12 @@ namespace Subsystems{
foreach (var building in _gameClient.CurrentLobbyState.MapData.GetBuildings())
{
var buildingType = _gameClient.CurrentLobbyState.MapData.BuildingTypes[_gameClient.CurrentLobbyState.MapData.GetBuildings().IndexOf(building)];
string buildingType = "Unknown";
try
{
buildingType = _gameClient.CurrentLobbyState.MapData.BuildingTypes[_gameClient.CurrentLobbyState.MapData.GetBuildings().IndexOf(building)];
}
catch (Exception ex) { Debug.Log($"Error: {ex.Message}"); }
building.Name = buildingType;
GameObject b = BuildBuildingMesh(building);
b.transform.parent = buildingsRoot.transform;
@@ -106,6 +111,17 @@ namespace Subsystems{
}
//TODO: POIs
}
void ClearChildren()
{
List<GameObject> toDestroy = new List<GameObject>();
foreach (Transform t in _mapCenterPoint.transform)
toDestroy.Add(t.gameObject);
foreach (var g in toDestroy)
{
UnityEngine.Object.DestroyImmediate(g);
}
}
#region Mesh Building
GameObject BuildBuildingMesh(MapBuilding b)
{
var building = new GameObject($"Building_{b.Name ?? "Unknown"}");
@@ -210,7 +226,7 @@ namespace Subsystems{
line.positionCount = w.Points.Count;
for (int i = 0; i < w.Points.Count; i++)
{
Vector3 pos = LatLonToLocal(w.Points[i]);
Vector3 pos = w.Points[i].ToLocalVector3(_gameClient.CurrentLobbyState.MapData.Center);
pos.y = 0.1f; // Mírně nad zemí
line.SetPosition(i, pos);
}
@@ -261,44 +277,14 @@ namespace Subsystems{
return area;
}
//TODO: POIs
void ClearChildren()
{
List<GameObject> toDestroy = new List<GameObject>();
foreach (Transform t in _mapCenterPoint.transform)
toDestroy.Add(t.gameObject);
foreach (var g in toDestroy)
{
UnityEngine.Object.DestroyImmediate(g);
}
}
Vector3 LatLonToLocal(Position position)
{
if (_gameClient.CurrentLobbyState.MapData == null) return Vector3.zero;
// Výpočet vzdálenosti a směru od středu
// Zjednodušená verze - pro malé vzdálenosti je dost přesná
double latDiff = position.Lat - _gameClient.CurrentLobbyState.MapData.Center.Lat;
double lonDiff = position.Lon - _gameClient.CurrentLobbyState.MapData.Center.Lon;
// Převod stupňů na metry
// 1 stupeň latitude ≈ 111320 metrů
// 1 stupeň longitude závisí na latitude: 111320 * cos(latitude)
double metersPerDegreeLat = 111320.0;
double metersPerDegreeLon = 111320.0 * Math.Cos(_gameClient.CurrentLobbyState.MapData.Center.Lat * Math.PI / 180.0);
float x = (float)(lonDiff * metersPerDegreeLon);
float z = (float)(latDiff * metersPerDegreeLat);
return new Vector3(x, 0, z);
}
#endregion
#region Polygon Utils
private Vector3 CalculatePolygonCenter(List<Position> points)
{
Vector3 center = Vector3.zero;
foreach (var point in points)
{
center += LatLonToLocal(point);
center += point.ToLocalVector3(_gameClient.CurrentLobbyState.MapData.Center);
}
return center / points.Count;
}
@@ -314,7 +300,7 @@ namespace Subsystems{
for (int i = 0; i < vertexCount; i++)
{
Vector3 pos = LatLonToLocal(outline[i]) - center;
Vector3 pos = outline[i].ToLocalVector3(_gameClient.CurrentLobbyState.MapData.Center) - center;
vertices[i] = pos; // Spodní
vertices[i + vertexCount] = pos + Vector3.up * height; // Horní
}
@@ -364,7 +350,7 @@ namespace Subsystems{
for (int i = 0; i < vertexCount; i++)
{
vertices[i] = LatLonToLocal(outline[i]) - center;
vertices[i] = outline[i].ToLocalVector3(_gameClient.CurrentLobbyState.MapData.Center) - center;
}
// Triangulace - fan pattern