/// <summary> /// Initialises this object. /// </summary> /// <param name="parent"> /// The parent transform. /// </param> public void Init(Transform parent) { if (instance != null) { Object.DestroyImmediate(instance); } if (prefab == null) { instance = GameObject.CreatePrimitive(PrimitiveType.Cube); instance.transform.localScale = Vector3.one; } else { instance = (GameObject)Object.Instantiate(prefab); } _prefab = prefab; instance.transform.parent = parent; instance.AddComponent <OnlineMapsMarker3DInstance>().marker = this; enabled = false; inited = true; OnlineMaps api = OnlineMaps.instance; double tlx, tly, brx, bry; api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); Update(tlx, tly, brx, bry, api.zoom); }
private void UpdateBaseProps() { double mx, my; marker.GetPosition(out mx, out my); if (_longitude != mx || _latitude != my) { _longitude = mx; _latitude = my; OnlineMaps map = OnlineMaps.instance; double tlx, tly, brx, bry; map.GetTopLeftPosition(out tlx, out tly); map.GetBottomRightPosition(out brx, out bry); marker.Update(tlx, tly, brx, bry, map.zoom); } if (_scale != marker.scale) { _scale = marker.scale; transform.localScale = new Vector3(_scale, _scale, _scale); } }
/// <summary> /// Create 3D marker from an existing GameObject. /// </summary> /// <param name="instance">GameObject to be used as a 3D marker.</param> public OnlineMapsMarker3D(GameObject instance) : this() { prefab = _prefab = instance; this.instance = instance; instance.AddComponent <OnlineMapsMarker3DInstance>().marker = this; OnlineMaps api = OnlineMaps.instance; double tlx, tly, brx, bry; api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); Update(tlx, tly, brx, bry, api.zoom); }
private void UpdateBaseProps() { if (_position != marker.position) { OnlineMaps map = OnlineMaps.instance; double tlx, tly, brx, bry; map.GetTopLeftPosition(out tlx, out tly); map.GetBottomRightPosition(out brx, out bry); marker.Update(tlx, tly, brx, bry, map.zoom); } if (_scale != marker.scale) { _scale = marker.scale; transform.localScale = new Vector3(_scale, _scale, _scale); } }
void Update() { const float maxTilt = 50; OnlineMaps api = OnlineMaps.instance; OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance; if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { tilt -= Time.deltaTime * tiltSpeed * maxTilt; } else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { tilt += Time.deltaTime * tiltSpeed * maxTilt; } else if (tilt != 0) { float tiltOffset = Time.deltaTime * tiltSpeed * maxTilt; if (Mathf.Abs(tilt) > tiltOffset) { tilt -= tiltOffset * Mathf.Sign(tilt); } else { tilt = 0; } } tilt = Mathf.Clamp(tilt, -maxTilt, maxTilt); container.transform.localRotation = Quaternion.Euler(tilt, 0, 0); if (tilt != 0) { transform.Rotate(Vector3.up, tilt * rotateSpeed * Time.deltaTime); } double tlx, tly, brx, bry, dx, dy; api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); OnlineMapsUtils.DistanceBetweenPoints(tlx, tly, brx, bry, out dx, out dy); double mx = (brx - tlx) / dx; double my = (tly - bry) / dy; double v = (double)speed * Time.deltaTime / 3600.0; double ox = mx * v * Math.Cos(transform.rotation.eulerAngles.y * OnlineMapsUtils.Deg2Rad); double oy = my * v * Math.Sin((360 - transform.rotation.eulerAngles.y) * OnlineMapsUtils.Deg2Rad); px += ox; py += oy; api.SetPosition(px, py); Vector3 pos = transform.position; pos.y = altitude * control.GetBestElevationYScale(tlx, tly, brx, bry) * control.elevationScale; transform.position = pos; Camera.main.transform.position = transform.position - transform.rotation * cameraOffset; Camera.main.transform.LookAt(transform); }
private void UpdateMesh() { OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance; if (tilesetCollider == null) { tilesetCollider = control.GetComponent <Collider>(); } Bounds bounds = tilesetCollider.bounds; // Clear overlay mesh overlayMesh.Clear(true); // Init verticles and normals float y = bounds.max.y + 0.5f; overlayMesh.vertices = new[] { new Vector3(bounds.min.x, y, bounds.min.z), new Vector3(bounds.min.x, y, bounds.max.z), new Vector3(bounds.max.x, y, bounds.max.z), new Vector3(bounds.max.x, y, bounds.min.z) }; overlayMesh.normals = new[] { Vector3.up, Vector3.up, Vector3.up, Vector3.up }; // Init overlay UV OnlineMaps api = OnlineMaps.instance; double tlx, tly, brx, bry; api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); api.projection.CoordinatesToTile(tlx, tly, api.zoom, out tlx, out tly); api.projection.CoordinatesToTile(brx, bry, api.zoom, out brx, out bry); int maxTileCount = 1 << api.zoom; float uvX1 = (float)(tlx / maxTileCount); float uvX2 = (float)(brx / maxTileCount); if (uvX1 > uvX2) { uvX2 += 1; } float uvY1 = (float)(1 - tly / maxTileCount); float uvY2 = (float)(1 - bry / maxTileCount); overlayMesh.uv = new[] { new Vector2(uvX2, uvY1), new Vector2(uvX2, uvY2), new Vector2(uvX1, uvY2), new Vector2(uvX1, uvY1) }; // Init triangles overlayMesh.SetTriangles(new[] { 0, 1, 2, 0, 2, 3 }, 0); overlayMesh.RecalculateBounds(); overlayMesh.RecalculateNormals(); }