Code cleanup

This commit is contained in:
2025-11-15 20:05:19 +01:00
parent 0cb7d4b64d
commit 39b42e1e90
4 changed files with 37 additions and 51 deletions

View File

@@ -220,9 +220,9 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 1274200471} - component: {fileID: 1274200471}
- component: {fileID: 1274200470}
- component: {fileID: 1274200473} - component: {fileID: 1274200473}
- component: {fileID: 1274200472} - component: {fileID: 1274200472}
- component: {fileID: 1274200474}
m_Layer: 0 m_Layer: 0
m_Name: APIManager m_Name: APIManager
m_TagString: Untagged m_TagString: Untagged
@@ -230,29 +230,6 @@ GameObject:
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!114 &1274200470
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1274200469}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0c03158bf19bc8c4ab178ebaee653914, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Map
overpassUrl: https://mapz.honzuvkod.dev/api/interpreter
queryRadiusMeters: 200
latitude: 50.772789001464844
longitude: 15.076871871948242
buildingMaterial: {fileID: 2100000, guid: 283cf727b4c3ac64c94d59598e221b10, type: 2}
defaultFloorHeight: 3
defaultBuildingHeight: 6
roadMaterial: {fileID: 2100000, guid: 283cf727b4c3ac64c94d59598e221b10, type: 2}
defaultRoadWidth: 4
metersPerUnit: 1
autoStart: 1
--- !u!4 &1274200471 --- !u!4 &1274200471
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -324,6 +301,26 @@ MeshFilter:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1274200469} m_GameObject: {fileID: 1274200469}
m_Mesh: {fileID: 0} m_Mesh: {fileID: 0}
--- !u!114 &1274200474
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1274200469}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a58b19ca2646e434ea88b8112260362b, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::MapRenderer
queryRadiusMeters: 1000
buildingMaterial: {fileID: 2100000, guid: 283cf727b4c3ac64c94d59598e221b10, type: 2}
defaultFloorHeight: 3
defaultBuildingHeight: 6
roadMaterial: {fileID: 2100000, guid: 283cf727b4c3ac64c94d59598e221b10, type: 2}
defaultRoadWidth: 4
metersPerUnit: 1
autoStart: 1
--- !u!1 &1865882987 --- !u!1 &1865882987
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -11,12 +11,12 @@ using UnityEngine.Networking;
public class MapRenderer : MonoBehaviour public class MapRenderer : MonoBehaviour
{ {
[Header("Overpass settings")] [Header("Overpass settings")]
public string overpassUrl = "https://mapz.honzuvkod.dev/api/interpreter"; public const string overpassUrl = "https://mapz.honzuvkod.dev/api/interpreter";
public float queryRadiusMeters = 200f; // radius around lat/lon to query public float queryRadiusMeters = 200f; // radius around lat/lon to query
[Header("Location (lat, lon)")] [Header("Location (lat, lon)")]
public double latitude; // example Prague private double latitude = 50.7727878;
public double longitude; private double longitude = 15.0718625;
[Header("Building settings")] [Header("Building settings")]
public Material buildingMaterial; public Material buildingMaterial;
@@ -31,35 +31,27 @@ public class MapRenderer : MonoBehaviour
public float metersPerUnit = 1f; // scale: 1 unit = 1 meter public float metersPerUnit = 1f; // scale: 1 unit = 1 meter
public bool autoStart = true; public bool autoStart = true;
// Internal storage [Header("Storage")]
Dictionary<long, Vector2> nodes = new Dictionary<long, Vector2>(); // id -> latlon Dictionary<long, Vector2> nodes = new Dictionary<long, Vector2>(); // id -> latlon
List<Way> parsedWays = new List<Way>();
void Start() void Start()
{ {
if (autoStart) if (autoStart) { StartCoroutine(RenderMap()); }
StartCoroutine(GenerateForLocation(latitude, longitude));
} }
// Public entry for other scripts public void StartGenerating()
public void StartGenerating(double lat, double lon)
{ {
latitude = lat; longitude = lon; StartCoroutine(RenderMap());
StartCoroutine(GenerateForLocation(lat, lon));
} }
IEnumerator GenerateForLocation(double lat, double lon) IEnumerator RenderMap()
{ {
ClearChildren(); ClearChildren();
// compute bbox from radius //TODO: GPS update
float degPerMeter = 1f / 111000f; // approximate
double delta = queryRadiusMeters * degPerMeter;
double south = lat - delta;
double north = lat + delta;
double west = lon - delta;
double east = lon + delta;
string q = $"[out:xml][timeout:25];(way[\"building\"]({south.ToString().Replace(",",".")},{west.ToString().Replace(",", ".")},{north.ToString().Replace(",", ".")},{east.ToString().Replace(",", ".")});way[\"highway\"]({south.ToString().Replace(",", ".")},{west.ToString().Replace(",", ".")},{north.ToString().Replace(",", ".")},{east.ToString().Replace(",", ".")}););(._;>;);out body;"; string q = $"[out:xml][timeout:90];(way[\"building\"](around:{queryRadiusMeters.ToString().Replace(",", ".")},{latitude.ToString().Replace(",", ".")},{longitude.ToString().Replace(",", ".")});way[\"highway\"](around:{queryRadiusMeters.ToString().Replace(",", ".")},{latitude.ToString().Replace(",", ".")},{longitude.ToString().Replace(",", ".")}););(._;>;);out body;";
WWWForm form = new WWWForm(); WWWForm form = new WWWForm();
form.AddField("data", q); form.AddField("data", q);
@@ -78,14 +70,12 @@ public class MapRenderer : MonoBehaviour
string xml = www.downloadHandler.text; string xml = www.downloadHandler.text;
ParseOverpassXml(xml); ParseOverpassXml(xml);
// create separate GameObjects for buildings and roads
GameObject buildingsRoot = new GameObject("Buildings"); GameObject buildingsRoot = new GameObject("Buildings");
buildingsRoot.transform.parent = this.transform; buildingsRoot.transform.parent = this.transform;
GameObject roadsRoot = new GameObject("Roads"); GameObject roadsRoot = new GameObject("Roads");
roadsRoot.transform.parent = this.transform; roadsRoot.transform.parent = this.transform;
// iterate parsed ways
foreach (var w in parsedWays) foreach (var w in parsedWays)
{ {
if (w.tags.ContainsKey("building")) if (w.tags.ContainsKey("building"))
@@ -106,7 +96,6 @@ public class MapRenderer : MonoBehaviour
void ClearChildren() void ClearChildren()
{ {
// remove existing generated children
List<GameObject> toDestroy = new List<GameObject>(); List<GameObject> toDestroy = new List<GameObject>();
foreach (Transform t in transform) foreach (Transform t in transform)
toDestroy.Add(t.gameObject); toDestroy.Add(t.gameObject);
@@ -122,7 +111,7 @@ public class MapRenderer : MonoBehaviour
public Dictionary<string, string> tags = new Dictionary<string, string>(); public Dictionary<string, string> tags = new Dictionary<string, string>();
} }
List<Way> parsedWays = new List<Way>();
void ParseOverpassXml(string xmlText) void ParseOverpassXml(string xmlText)
{ {

View File

@@ -7,7 +7,7 @@ Material:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: New Material m_Name: TestMaterial
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0} m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0 m_ModifiedSerializedProperties: 0

View File

@@ -922,11 +922,11 @@ PlayerSettings:
captureStartupLogs: {} captureStartupLogs: {}
activeInputHandler: 2 activeInputHandler: 2
windowsGamepadBackendHint: 0 windowsGamepadBackendHint: 0
cloudProjectId: 8feb5b9d-fe4c-4652-bc44-283fb1a29892 cloudProjectId:
framebufferDepthMemorylessMode: 0 framebufferDepthMemorylessMode: 0
qualitySettingsNames: [] qualitySettingsNames: []
projectName: Game projectName:
organizationId: unity-tul-du organizationId:
cloudEnabled: 0 cloudEnabled: 0
legacyClampBlendShapeWeights: 0 legacyClampBlendShapeWeights: 0
hmiLoadingImage: {fileID: 0} hmiLoadingImage: {fileID: 0}