/// <summary> /// Returns a list of provinces that are visible and overlaps the rectangle defined by two given sphere points /// </summary> public List <Province> GetVisibleProvinces(Vector3 rectTopLeft, Vector3 rectBottomRight) { Vector2 latlon0, latlon1; latlon0 = Conversion.GetBillboardPosFromSpherePoint(rectTopLeft); latlon1 = Conversion.GetBillboardPosFromSpherePoint(rectBottomRight); Rect rect = new Rect(latlon0.x, latlon1.y, latlon1.x - latlon0.x, latlon0.y - latlon1.y); List <Province> selectedProvinces = new List <Province>(); if (_provinces == null) { ReadProvincesPackedString(); } List <Country> countries = GetVisibleCountries(rectTopLeft, rectBottomRight); for (int k = 0; k < countries.Count; k++) { Country country = countries[k]; if (country.hidden) { continue; } if (country.provinces == null) { continue; } for (int p = 0; p < country.provinces.Length; p++) { Province province = country.provinces[p]; if (selectedProvinces.Contains(province)) { continue; } // Check if any of province's regions is inside rect if (province.regions == null) { ReadProvincePackedString(province); } if (province.regions == null) { continue; } int crc = province.regions.Count; for (int cr = 0; cr < crc; cr++) { Region region = province.regions[cr]; if (rect.Overlaps(region.rect2Dbillboard)) { selectedProvinces.Add(province); break; } } } } return(selectedProvinces); }
/// <summary> /// Returns a list of cities that are visible and located inside the rectangle defined by two given sphere points /// </summary> public List<City>GetVisibleCities(Vector3 rectTopLeft, Vector3 rectBottomRight) { Vector2 latlon0, latlon1; latlon0 = Conversion.GetBillboardPosFromSpherePoint(rectTopLeft); latlon1 = Conversion.GetBillboardPosFromSpherePoint(rectBottomRight); Rect rect = new Rect(latlon0.x, latlon1.y, latlon1.x - latlon0.x, latlon0.y - latlon1.y); List<City> selectedCities = new List<City>(); int cityCount = visibleCities.Length; for (int k=0;k<cityCount;k++) { City city = visibleCities[k]; Vector2 bpos = Conversion.GetBillboardPosFromSpherePoint(city.unitySphereLocation); if (rect.Contains(bpos)) { selectedCities.Add (city); } } return selectedCities; }
/// <summary> /// Returns a list of mount points that are visible and located inside the rectangle defined by two given sphere points /// </summary> public List <MountPoint> GetVisibleMountPoints(Vector3 rectTopLeft, Vector3 rectBottomRight) { Vector2 latlon0, latlon1; latlon0 = Conversion.GetBillboardPosFromSpherePoint(rectTopLeft); latlon1 = Conversion.GetBillboardPosFromSpherePoint(rectBottomRight); Rect rect = new Rect(latlon0.x, latlon1.y, latlon1.x - latlon0.x, latlon0.y - latlon1.y); List <MountPoint> selectedMountPoints = new List <MountPoint>(); int mpCount = mountPoints.Count; for (int k = 0; k < mpCount; k++) { MountPoint mp = mountPoints[k]; Vector2 bpos = Conversion.GetBillboardPosFromSpherePoint(mp.unitySphereLocation); if (rect.Contains(bpos)) { selectedMountPoints.Add(mp); } } return(selectedMountPoints); }
public static GameObject CreateSurface(string name, Vector3[] surfPoints, int maxIndex, Material material, Rect rect, Vector2 textureScale, Vector2 textureOffset, float textureRotation) { GameObject hexa = new GameObject(name, typeof(MeshRenderer), typeof(MeshFilter)); hexa.hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy; int pointCount = maxIndex + 1; List <Vector3> newPoints = new List <Vector3> (pointCount); int[] triNew = new int[pointCount]; int newPointsCount = -1; if (hit == null) { hit = new Dictionary <Vector3, int> (20000); } else { hit.Clear(); } for (int k = 0; k <= maxIndex; k++) { Vector3 p = surfPoints [k]; if (hit.ContainsKey(p)) { triNew [k] = hit [p]; } else { newPoints.Add(p); hit.Add(p, ++newPointsCount); triNew [k] = newPointsCount; } } Mesh mesh = new Mesh(); mesh.hideFlags = HideFlags.DontSave; Vector3[] newPoints2 = newPoints.ToArray(); mesh.vertices = newPoints2; // uv mapping if (material.mainTexture != null) { Vector2[] uv = new Vector2[newPoints2.Length]; for (int k = 0; k < uv.Length; k++) { Vector2 coor = Conversion.GetBillboardPosFromSpherePoint(newPoints2 [k]); coor.x /= textureScale.x; coor.y /= textureScale.y; if (textureRotation != 0) { coor = RotatePoint(coor, Misc.Vector2zero, textureRotation); } coor += textureOffset; Vector2 normCoor = new Vector2((coor.x - rect.xMin) / rect.width, (coor.y - rect.yMax) / rect.height); uv [k] = normCoor; } mesh.uv = uv; } mesh.triangles = triNew; mesh.RecalculateNormals(); mesh.RecalculateBounds(); #if !UNITY_5_5_OR_NEWER mesh.Optimize(); #endif MeshFilter meshFilter = hexa.GetComponent <MeshFilter> (); meshFilter.mesh = mesh; hexa.GetComponent <Renderer> ().sharedMaterial = material; return(hexa); }