/// <summary> /// This method is called when each building is created /// </summary> /// <param name="building">The building that was created</param> private void OnBuildingCreated(OnlineMapsBuildingBase building) { // Subscribe to interaction events building.OnPress += OnBuildingPress; building.OnRelease += OnBuildingRelease; building.OnClick += OnBuildingClick; }
public void CreateBuilding(OnlineMapsBuildingsNodeData data) { if (OnCreateBuilding != null && !OnCreateBuilding(data)) { return; } if (buildings.ContainsKey(data.way.id) || unusedBuildings.ContainsKey(data.way.id)) { return; } int initialZoom = map.buffer.renderState.zoom; OnlineMapsBuildingBase building = OnlineMapsBuildingBuiltIn.Create(this, data.way, data.nodes); if (building != null) { building.LoadMeta(data.way); if (OnBuildingCreated != null) { OnBuildingCreated(building); } unusedBuildings.Add(data.way.id, building); if (Math.Abs(map.buffer.lastState.floatZoom - initialZoom) > float.Epsilon) { UpdateBuildingScale(building); } building.transform.localScale.Scale(new Vector3(1, heightScale, 1)); } else { //Debug.Log("Null building"); } }
public void CreateBuilding(OnlineMapsBuildingsNodeData data) { if (OnCreateBuilding != null && !OnCreateBuilding(data)) { return; } if (buildings.ContainsKey(data.way.id) || unusedBuildings.ContainsKey(data.way.id)) { return; } OnlineMapsBuildingBase building = null; building = OnlineMapsBuildingBuiltIn.Create(this, data.way, data.nodes); if (building != null) { building.LoadMeta(data.way); if (OnBuildingCreated != null) { OnBuildingCreated(building); } unusedBuildings.Add(data.way.id, building); } }
/// <summary> /// Creates a new building based on data /// </summary> /// <param name="data">Building data</param> public void CreateBuilding(OnlineMapsBuildingsNodeData data) { if (OnCreateBuilding != null && !OnCreateBuilding(data)) { return; } if (buildings.ContainsKey(data.way.id) || unusedBuildings.ContainsKey(data.way.id)) { return; } int initialZoom = map.buffer.apiZoom; OnlineMapsBuildingBase building = OnlineMapsBuildingBuiltIn.Create(this, data.way, data.nodes); if (building != null) { building.LoadMeta(data.way); if (OnBuildingCreated != null) { OnBuildingCreated(building); } unusedBuildings.Add(data.way.id, building); if (map.buffer.apiZoom != initialZoom) { UpdateBuildingScale(building); } } else { //Debug.Log("Null building"); } }
private string GetValue(OnlineMapsBuildingBase building, string attribute) { if (building.metaInfo.Count(p => p.title == attribute) == 1) { return(building.metaInfo.Single(p => p.title == attribute).info); } return(null); }
private void GenerateBuildings() { long startTicks = DateTime.Now.Ticks; const int maxTicks = 500000; lock (newBuildingsData) { while (newBuildingsData.Count > 0) { if (maxBuilding > 0 && unusedBuildings.Count + buildings.Count >= maxBuilding) { break; } OnlineMapsBuildingsNodeData data = newBuildingsData[0]; newBuildingsData.RemoveAt(0); if (OnCreateBuilding != null && !OnCreateBuilding(data)) { data.Dispose(); continue; } if (buildings.ContainsKey(data.way.id) || unusedBuildings.ContainsKey(data.way.id)) { data.Dispose(); continue; } OnlineMapsBuildingBase building = OnlineMapsBuildingBuiltIn.Create(this, data.way, data.nodes); if (building != null) { building.LoadMeta(data.way); if (OnBuildingCreated != null) { OnBuildingCreated(building); } unusedBuildings.Add(data.way.id, building); } data.Dispose(); if (DateTime.Now.Ticks - startTicks > maxTicks) { break; } } } OnlineMapsBuildingBuiltIn.usedNodes = null; OnlineMapsBuildingBuiltIn.roofIndices = null; }
private static void UpdateBuildingScale(OnlineMapsBuildingBase building) { if (building.initialZoom == map.zoom) { building.transform.localScale = Vector3.one; } else if (building.initialZoom < map.zoom) { building.transform.localScale = Vector3.one * (1 << map.zoom - building.initialZoom); } else if (building.initialZoom > map.zoom) { building.transform.localScale = Vector3.one / (1 << building.initialZoom - map.zoom); } }
private static void UpdateBuildingScale(OnlineMapsBuildingBase building) { if (Math.Abs(building.initialZoom - map.floatZoom) < float.Epsilon) { building.transform.localScale = Vector3.one; } else if (building.initialZoom < map.floatZoom) { building.transform.localScale = Vector3.one * Mathf.Pow(2, map.floatZoom - building.initialZoom); } else if (building.initialZoom > map.floatZoom) { building.transform.localScale = Vector3.one / Mathf.Pow(2, building.initialZoom - map.floatZoom); } }
private void InitializeBuilding(OnlineMapsBuildingBase building) { building.gameObject.layer = LayerMask.NameToLayer("Map"); building.gameObject.AddComponent <BuildingWeapon>(); building.gameObject.AddComponent <InteractibleBuilding>(); var buildingDisplay = building.gameObject.AddComponent <BuildingDisplay>(); buildingDisplay.SelectedBuildingColor = SelectedBuildingColor; buildingDisplay.ExplosionPrefab = ExplosionPrefab; buildingDisplay.RuinBuildingPrefab = RuinBuildingPrefab; var textHolder = Instantiate(TextPrefab, Vector3.zero, Quaternion.identity); textHolder.transform.parent = building.gameObject.transform; textHolder.transform.localPosition = new Vector3(0, 100, 0); textHolder.transform.localRotation = Quaternion.identity; textHolder.transform.localScale = Vector3.one; buildingDisplay.TextHolder = textHolder; if (BuildingManager.Instance.IsBuildingSelected && building.id == BuildingManager.Instance.SelectedBuildingId) { if (Contains(building.centerCoordinates)) { building.gameObject.SetActive(true); BuildingManager.Instance.ReselectBuilding(building.gameObject); } } if (building.metaInfo.Any(p => p.title == "name:en")) { UnityEvent ue = KeywordManager.Instance.myKeywordsAndResponses.Single(kar => kar.Keywords.Contains("uninitialized")).Response; var methodPurpost = building.metaInfo.Single(p => p.title == "name:en").info; List <string> lstKeywords = new List <string>(); lstKeywords.Add(building.metaInfo.Single(p => p.title == "name:en").info); // Todo - yariv disabled it since were now using a different foramt of keywords and responses, // which dosen't alloww us to add keywords on the fly without getting a tone of errors. // KeywordManager.Instance.AddKeywordAndResponse(methodPurpost, lstKeywords, ue); // building.OnDispose += (b) => KeywordManager.Instance.RemoveKeyword(lstKeywords); } }
private static void UpdateBuildingScale(OnlineMapsBuildingBase building) { Vector3 s = OnlineMapsTileSetControl.instance.sizeInScene; Vector3 c = new Vector3(s.x / building.initialSizeInScene.x, 1, s.y / building.initialSizeInScene.y); c.y = (c.x + c.z) / 2 * instance.heightScale; if (Math.Abs(building.initialZoom - map.floatZoom) < float.Epsilon) { s = c; } else if (building.initialZoom < map.floatZoom) { s = c * Mathf.Pow(2, map.floatZoom - building.initialZoom); } else if (building.initialZoom > map.floatZoom) { s = c / Mathf.Pow(2, building.initialZoom - map.floatZoom); } building.transform.localScale = s; }
private void UpdateBuildingsScale() { UpdateBuildings(); foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in buildings) { OnlineMapsBuildingBase value = building.Value; if (value.initialZoom == api.zoom) { value.transform.localScale = Vector3.one; } else if (value.initialZoom < api.zoom) { value.transform.localScale = Vector3.one * (1 << api.zoom - value.initialZoom); } else if (value.initialZoom > api.zoom) { value.transform.localScale = Vector3.one / (1 << value.initialZoom - api.zoom); } } foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in unusedBuildings) { OnlineMapsBuildingBase value = building.Value; if (value.initialZoom == api.zoom) { value.transform.localScale = Vector3.one; } else if (value.initialZoom < api.zoom) { value.transform.localScale = Vector3.one * (1 << api.zoom - value.initialZoom); } else if (value.initialZoom > api.zoom) { value.transform.localScale = Vector3.one / (1 << value.initialZoom - api.zoom); } } }
private void OnEnable() { building = target as OnlineMapsBuildingBase; }
private static void UpdateBuildingPosition(OnlineMapsBuildingBase building, OnlineMapsTileSetControl control, double tlx, double tly, double brx, double bry) { Vector3 newPosition = control.GetWorldPositionWithElevation(building.centerCoordinates.x, building.centerCoordinates.y, tlx, tly, brx, bry); building.transform.position = newPosition; }
private void UpdateBuildingsPosition() { OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance; Bounds bounds = new Bounds(); double tlx, tly, brx, bry; map.GetCorners(out tlx, out tly, out brx, out bry); bounds.min = new Vector3((float)tlx, (float)bry); bounds.max = new Vector3((float)brx, (float)tly); List <string> unusedKeys = new List <string>(); foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in buildings) { if (!bounds.Intersects(building.Value.boundsCoords)) { unusedKeys.Add(building.Key); } else { UpdateBuildingPosition(building.Value, control, tlx, tly, brx, bry); } } List <string> usedKeys = new List <string>(); List <string> destroyKeys = new List <string>(); double px, py; map.GetTilePosition(out px, out py); float maxDistance = (Mathf.Pow((map.width / OnlineMapsUtils.tileSize) >> 1, 2) + Mathf.Pow((map.height / OnlineMapsUtils.tileSize) >> 1, 2)) * 4; foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in unusedBuildings) { OnlineMapsBuildingBase value = building.Value; if (bounds.Intersects(value.boundsCoords)) { usedKeys.Add(building.Key); UpdateBuildingPosition(value, control, tlx, tly, brx, bry); } else { double bx, by; map.projection.CoordinatesToTile(value.centerCoordinates.x, value.centerCoordinates.y, map.zoom, out bx, out @by); if (OnlineMapsUtils.SqrMagnitude(0, 0, bx - px, @by - py) > maxDistance) { destroyKeys.Add(building.Key); } } } for (int i = 0; i < unusedKeys.Count; i++) { string key = unusedKeys[i]; OnlineMapsBuildingBase value = buildings[key]; value.gameObject.SetActive(false); unusedBuildings.Add(key, value); buildings.Remove(key); } for (int i = 0; i < usedKeys.Count; i++) { if (maxActiveBuildings > 0 && buildings.Count >= maxActiveBuildings) { break; } string key = usedKeys[i]; OnlineMapsBuildingBase value = unusedBuildings[key]; if (OnShowBuilding != null && !OnShowBuilding(value)) { continue; } value.gameObject.SetActive(true); buildings.Add(key, value); unusedBuildings.Remove(key); } for (int i = 0; i < destroyKeys.Count; i++) { string key = destroyKeys[i]; OnlineMapsBuildingBase value = unusedBuildings[key]; if (OnBuildingDispose != null) { OnBuildingDispose(value); } value.Dispose(); OnlineMapsUtils.Destroy(value.gameObject); unusedBuildings.Remove(key); } }
private void SetGameObjectScale(OnlineMapsBuildingBase b) { transform.FindChild("Buildings").localScale = Vector3.one; onlineMapsBuildings.OnBuildingCreated -= SetGameObjectScale; }
/// <summary> /// This method is called when click on building /// </summary> /// <param name="building">The building on which clicked</param> private void OnBuildingClick(OnlineMapsBuildingBase building) { Debug.Log("click: " + building.id); }
private void UpdateBuildingsPosition() { Bounds bounds = new Bounds(); Vector2 topLeftPosition = OnlineMaps.instance.topLeftPosition; Vector2 bottomRightPosition = OnlineMaps.instance.bottomRightPosition; bounds.min = new Vector3(topLeftPosition.x, bottomRightPosition.y); bounds.max = new Vector3(bottomRightPosition.x, topLeftPosition.y); List <string> unusedKeys = new List <string>(); bool useElevation = OnlineMapsTileSetControl.instance.useElevation; foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in buildings) { if (!bounds.Intersects(building.Value.boundsCoords)) { unusedKeys.Add(building.Key); } else { if (useElevation) { Vector3 newPosition = OnlineMapsTileSetControl.instance.GetWorldPositionWithElevation(building.Value.centerCoordinates, topLeftPosition, bottomRightPosition); building.Value.transform.position = newPosition; } else { Vector3 newPosition = OnlineMapsTileSetControl.instance.GetWorldPosition(building.Value.centerCoordinates); building.Value.transform.position = newPosition; } } } List <string> usedKeys = new List <string>(); List <string> destroyKeys = new List <string>(); double px, py; api.GetPosition(out px, out py); OnlineMapsUtils.LatLongToTiled(px, py, api.zoom, out px, out py); float maxDistance = Mathf.Sqrt(Mathf.Pow(api.width / 2 / OnlineMapsUtils.tileSize, 2) + Mathf.Pow(api.height / 2 / OnlineMapsUtils.tileSize, 2)) * 2; foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in unusedBuildings) { OnlineMapsBuildingBase value = building.Value; if (bounds.Intersects(value.boundsCoords)) { usedKeys.Add(building.Key); Vector3 newPosition = OnlineMapsTileSetControl.instance.GetWorldPosition(value.centerCoordinates); value.transform.position = newPosition; } else { Vector2 buildingTilePos = OnlineMapsUtils.LatLongToTilef(value.centerCoordinates, api.zoom); if ((buildingTilePos - new Vector2((float)px, (float)py)).magnitude > maxDistance) { destroyKeys.Add(building.Key); } } } foreach (string key in unusedKeys) { OnlineMapsBuildingBase value = buildings[key]; value.gameObject.SetActive(false); unusedBuildings.Add(key, value); buildings.Remove(key); } foreach (string key in usedKeys) { OnlineMapsBuildingBase value = unusedBuildings[key]; if (maxActiveBuildings > 0 && buildings.Count >= maxActiveBuildings) { break; } if (OnShowBuilding != null && !OnShowBuilding(value)) { continue; } value.gameObject.SetActive(true); buildings.Add(key, value); unusedBuildings.Remove(key); } foreach (string key in destroyKeys) { OnlineMapsBuildingBase value = unusedBuildings[key]; if (OnBuildingDispose != null) { OnBuildingDispose(value); } DestroyImmediate(value.gameObject); unusedBuildings.Remove(key); } if (destroyKeys.Count > 0) { OnlineMaps.instance.needGC = true; } }
private void SetBuildingScale(OnlineMapsBuildingBase b) { b.transform.localScale = Vector3.one; }
/// <summary> /// This method is called when press on building /// </summary> /// <param name="building">The building on which pressed</param> private void OnBuildingPress(OnlineMapsBuildingBase building) { Debug.Log("Press: " + building.id); }
private void UpdateBuildingsPosition() { OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance; Bounds bounds = new Bounds(); double tlx, tly, brx, bry; api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); bounds.min = new Vector3((float)tlx, (float)bry); bounds.max = new Vector3((float)brx, (float)tly); List <string> unusedKeys = new List <string>(); bool useElevation = control.useElevation; foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in buildings) { if (!bounds.Intersects(building.Value.boundsCoords)) { unusedKeys.Add(building.Key); } else { if (useElevation) { Vector3 newPosition = control.GetWorldPositionWithElevation(building.Value.centerCoordinates.x, building.Value.centerCoordinates.y, tlx, tly, brx, bry); building.Value.transform.position = newPosition; } else { Vector3 newPosition = control.GetWorldPosition(building.Value.centerCoordinates.x, building.Value.centerCoordinates.y); building.Value.transform.position = newPosition; } } } List <string> usedKeys = new List <string>(); List <string> destroyKeys = new List <string>(); double px, py; api.GetPosition(out px, out py); api.projection.CoordinatesToTile(px, py, api.zoom, out px, out py); float maxDistance = Mathf.Sqrt(Mathf.Pow(api.width / 2 / OnlineMapsUtils.tileSize, 2) + Mathf.Pow(api.height / 2 / OnlineMapsUtils.tileSize, 2)) * 2; foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in unusedBuildings) { OnlineMapsBuildingBase value = building.Value; if (bounds.Intersects(value.boundsCoords)) { usedKeys.Add(building.Key); if (useElevation) { Vector3 newPosition = control.GetWorldPositionWithElevation(building.Value.centerCoordinates, tlx, tly, brx, bry); building.Value.transform.position = newPosition; } else { Vector3 newPosition = control.GetWorldPosition(building.Value.centerCoordinates.x, building.Value.centerCoordinates.y); building.Value.transform.position = newPosition; } } else { double bx, by; api.projection.CoordinatesToTile(value.centerCoordinates.x, value.centerCoordinates.y, api.zoom, out bx, out by); if (OnlineMapsUtils.Magnitude(0, 0, bx - px, by - py) > maxDistance) { destroyKeys.Add(building.Key); } } } foreach (string key in unusedKeys) { OnlineMapsBuildingBase value = buildings[key]; value.gameObject.SetActive(false); unusedBuildings.Add(key, value); buildings.Remove(key); } foreach (string key in usedKeys) { OnlineMapsBuildingBase value = unusedBuildings[key]; if (maxActiveBuildings > 0 && buildings.Count >= maxActiveBuildings) { break; } if (OnShowBuilding != null && !OnShowBuilding(value)) { continue; } value.gameObject.SetActive(true); buildings.Add(key, value); unusedBuildings.Remove(key); } foreach (string key in destroyKeys) { OnlineMapsBuildingBase value = unusedBuildings[key]; if (OnBuildingDispose != null) { OnBuildingDispose(value); } OnlineMapsUtils.DestroyImmediate(value.gameObject); unusedBuildings.Remove(key); } if (destroyKeys.Count > 0) { OnlineMaps.instance.needGC = true; } }
/// <summary> /// This method is called when release on building /// </summary> /// <param name="building">The building on which released</param> private void OnBuildingRelease(OnlineMapsBuildingBase building) { Debug.Log("Release: " + building.id); }
private void buildingDisposed(OnlineMapsBuildingBase building) { selectedBuilding = null; }