/// <summary>
        /// Updates the positions of all markers
        /// </summary>
        private void UpdateMarkers()
        {
            double tly, brx, bry, tlx;

            map.GetCorners(out tlx, out tly, out brx, out bry);

            foreach (uGUICustomMarkerExample marker in markers)
            {
                UpdateMarker(marker, tlx, tly, brx, bry);
            }
        }
    /// <summary>
    /// Returns yScale for an area
    /// </summary>
    /// <returns>yScale for an area</returns>
    public static float GetBestElevationYScale()
    {
        double     tlx, tly, brx, bry;
        OnlineMaps map = _instance != null ? _instance.map : OnlineMaps.instance;

        if (map == null)
        {
            return(0);
        }

        map.GetCorners(out tlx, out tly, out brx, out bry);
        return(GetBestElevationYScale(tlx, tly, brx, bry));
    }
    public OnlineMapsBuffer(OnlineMaps map)
    {
        this.map = map;

        lastState = new StateProps
        {
            floatZoom = map.floatZoom,
            width     = map.width,
            height    = map.height
        };

        map.GetPosition(out lastState.longitude, out lastState.latitude);
        map.GetCorners(out lastState.leftLongitude, out lastState.topLatitude, out lastState.rightLongitude, out lastState.bottomLatitude);
        renderState = lastState;

        newTiles = new List <OnlineMapsTile>();
    }
Exemplo n.º 4
0
        private void Start()
        {
            map              = OnlineMaps.instance;
            control          = OnlineMapsTileSetControl.instance;
            elevationManager = OnlineMapsElevationManagerBase.instance;

            double tlx, tly, brx, bry;

            map.GetCorners(out tlx, out tly, out brx, out bry);

            Vector3 position = control.GetWorldPosition(map.position);

            position.y = altitude;
            if (elevationManager != null)
            {
                position.y *= OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry) * elevationManager.scale;
            }

            gameObject.transform.position = position;
            map.GetPosition(out px, out py);
        }
    public void GenerateFrontBuffer()
    {
        try
        {
            lastState = new StateProps
            {
                floatZoom = map.floatZoom,
                width     = map.width,
                height    = map.height
            };

            map.GetPosition(out lastState.longitude, out lastState.latitude);
            map.GetCorners(out lastState.leftLongitude, out lastState.topLatitude, out lastState.rightLongitude, out lastState.bottomLatitude);

            while (!disposed)
            {
#if !UNITY_WEBGL
                while (status != OnlineMapsBufferStatus.start && map.renderInThread)
                {
                    if (disposed)
                    {
                        return;
                    }
                    OnlineMapsUtils.ThreadSleep(1);
                }
#endif

                status = OnlineMapsBufferStatus.working;

                renderState = new StateProps
                {
                    floatZoom = map.floatZoom,
                    width     = map.width,
                    height    = map.height
                };

                try
                {
                    map.GetPosition(out renderState.longitude, out renderState.latitude);
                    map.GetCorners(out renderState.leftLongitude, out renderState.topLatitude, out renderState.rightLongitude, out renderState.bottomLatitude);

                    if (newTiles != null && map.control.resultIsTexture)
                    {
                        ApplyNewTiles();
                    }

                    if (disposed)
                    {
                        return;
                    }

                    UpdateBackBuffer(renderState.longitude, renderState.latitude, renderState.zoom);
                    if (disposed)
                    {
                        return;
                    }

                    if (map.control.resultIsTexture)
                    {
                        GetFrontBufferPosition(renderState.longitude, renderState.latitude, bufferPosition, renderState.floatZoom, renderState.width, renderState.height);
                        UpdateFrontBuffer(renderState.width, renderState.height, renderState.floatZoom);

                        if (disposed)
                        {
                            return;
                        }

                        foreach (OnlineMapsDrawingElement element in OnlineMapsDrawingElementManager.instance)
                        {
                            if (disposed)
                            {
                                return;
                            }
                            element.Draw(frontBuffer, new Vector2(bufferPosition.x + (float)frontBufferPosition.x / OnlineMapsUtils.tileSize, bufferPosition.y + (float)frontBufferPosition.y / OnlineMapsUtils.tileSize), renderState.width, renderState.height, renderState.floatZoom);
                        }

                        if (map.control.OnDrawMarkers != null)
                        {
                            map.control.OnDrawMarkers();
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (disposed)
                    {
                        return;
                    }
                    Debug.Log(exception.Message + "\n" + exception.StackTrace);
                }

                status = OnlineMapsBufferStatus.complete;

                lastState = renderState;
#if !UNITY_WEBGL
                if (!map.renderInThread)
                {
                    break;
                }
#else
                break;
#endif
            }
        }
        catch
        {
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Updates camera position
    /// </summary>
    public void UpdateCameraPosition()
    {
        if (rotation.x > maxRotationX)
        {
            rotation.x = maxRotationX;
        }
        else if (rotation.x < 0)
        {
            rotation.x = 0;
        }

        float rx = 90 - rotation.x;

        if (rx > 89.9)
        {
            rx = 89.9f;
        }

        double px = Math.Cos(rx * Mathf.Deg2Rad) * distance;
        double py = Math.Sin(rx * Mathf.Deg2Rad) * distance;
        double pz = Math.Cos(rotation.y * Mathf.Deg2Rad) * px;

        px = Math.Sin(rotation.y * Mathf.Deg2Rad) * px;

        Vector3 targetPosition;

        if (adjustTo == OnlineMapsCameraAdjust.gameObject && adjustToGameObject != null)
        {
            targetPosition = adjustToGameObject.transform.position;
        }
        else
        {
            targetPosition = map.transform.position;
            Vector3 offset = new Vector3(sizeInScene.x / -2, 0, sizeInScene.y / 2);

            if (OnlineMapsElevationManagerBase.useElevation)
            {
                double tlx, tly, brx, bry;
                map.GetCorners(out tlx, out tly, out brx, out bry);
                float yScale = OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry);

                if (adjustTo == OnlineMapsCameraAdjust.maxElevationInArea)
                {
                    offset.y = OnlineMapsElevationManagerBase.instance.GetMaxElevation(yScale);
                }
                else if (adjustTo == OnlineMapsCameraAdjust.averageCenter)
                {
                    float ox = sizeInScene.x / 64;
                    float oz = sizeInScene.y / 64;
                    offset.y = OnlineMapsElevationManagerBase.GetElevation(targetPosition.x, targetPosition.z, yScale, tlx, tly, brx, bry) * 3;

                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x - ox, targetPosition.z - oz, yScale, tlx, tly, brx, bry) * 2;
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x, targetPosition.z - oz, yScale, tlx, tly, brx, bry) * 2;
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x + ox, targetPosition.z - oz, yScale, tlx, tly, brx, bry) * 2;
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x + ox, targetPosition.z, yScale, tlx, tly, brx, bry) * 2;
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x + ox, targetPosition.z + oz, yScale, tlx, tly, brx, bry) * 2;
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x, targetPosition.z + oz, yScale, tlx, tly, brx, bry) * 2;
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x - ox, targetPosition.z + oz, yScale, tlx, tly, brx, bry) * 2;
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x - ox, targetPosition.z, yScale, tlx, tly, brx, bry) * 2;

                    ox *= 2;
                    oz *= 2;

                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x - ox, targetPosition.z - oz, yScale, tlx, tly, brx, bry);
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x, targetPosition.z - oz, yScale, tlx, tly, brx, bry);
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x + ox, targetPosition.z - oz, yScale, tlx, tly, brx, bry);
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x + ox, targetPosition.z, yScale, tlx, tly, brx, bry);
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x + ox, targetPosition.z + oz, yScale, tlx, tly, brx, bry);
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x, targetPosition.z + oz, yScale, tlx, tly, brx, bry);
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x - ox, targetPosition.z + oz, yScale, tlx, tly, brx, bry);
                    offset.y += OnlineMapsElevationManagerBase.GetElevation(targetPosition.x - ox, targetPosition.z, yScale, tlx, tly, brx, bry);

                    offset.y /= 27;
                }
                else
                {
                    offset.y = OnlineMapsElevationManagerBase.GetElevation(targetPosition.x, targetPosition.z, yScale, tlx, tly, brx, bry);
                }
            }

            offset.Scale(map.transform.lossyScale);

            targetPosition += map.transform.rotation * offset;
        }

        Vector3 oldPosition = activeCamera.transform.position;
        Vector3 newPosition = map.transform.rotation * new Vector3((float)px, (float)py, (float)pz) + targetPosition;

        activeCamera.transform.position = newPosition;
        activeCamera.transform.LookAt(targetPosition);

        if (control.isMapDrag)
        {
            control.UpdateLastPosition();
        }

        if (oldPosition != newPosition && OnCameraControl != null)
        {
            OnCameraControl();
        }
    }
    public override void DrawOnTileset(OnlineMapsTileSetControl control, int index)
    {
        base.DrawOnTileset(control, index);

        if (!visible)
        {
            active = false;
            return;
        }

        InitMesh(control, "Rect", borderColor, backgroundColor);

        OnlineMaps map = api;

        map.GetCorners(out tlx, out tly, out brx, out bry);

        List <Vector2> localPoints = GetLocalPoints(points, true, false);

        Rect rect1 = new Rect(localPoints[0].x, localPoints[2].y, localPoints[2].x - localPoints[0].x, localPoints[0].y - localPoints[2].y);
        Rect rect2 = new Rect(0, 0, map.tilesetSize.x, map.tilesetSize.y);

        bool ignoreLeft   = false;
        bool ignoreRight  = false;
        bool ignoreTop    = false;
        bool ignoreBottom = false;
        int  countIgnore  = 0;

        if (checkMapBoundaries)
        {
            if (!rect2.Overlaps(rect1))
            {
                if (active)
                {
                    active = false;
                }
                return;
            }
            if (!active)
            {
                active = true;
            }

            for (int i = 0; i < localPoints.Count; i++)
            {
                Vector2 point = localPoints[i];
                if (point.x < 0)
                {
                    point.x = 0;
                    if (!ignoreLeft)
                    {
                        countIgnore++;
                    }
                    ignoreLeft = true;
                }
                if (point.y < 0)
                {
                    point.y = 0;
                    if (!ignoreTop)
                    {
                        countIgnore++;
                    }
                    ignoreTop = true;
                }
                if (point.x > map.tilesetSize.x)
                {
                    point.x = map.tilesetSize.x;
                    if (!ignoreRight)
                    {
                        countIgnore++;
                    }
                    ignoreRight = true;
                }
                if (point.y > map.tilesetSize.y)
                {
                    point.y = map.tilesetSize.y;
                    if (!ignoreBottom)
                    {
                        countIgnore++;
                    }
                    ignoreBottom = true;
                }

                localPoints[i] = point;
            }
        }


        if (vertices == null)
        {
            vertices = new List <Vector3>(16);
        }
        else
        {
            vertices.Clear();
        }

        if (normals == null)
        {
            normals = new List <Vector3>(16);
        }
        else
        {
            normals.Clear();
        }

        if (backTriangles == null)
        {
            backTriangles = new List <int>(6);
        }
        else
        {
            backTriangles.Clear();
        }

        if (borderTriangles == null)
        {
            borderTriangles = new List <int>();
        }
        else
        {
            borderTriangles.Clear();
        }

        if (uv == null)
        {
            uv = new List <Vector2>(16);
        }
        else
        {
            uv.Clear();
        }

        vertices.Add(new Vector3(-localPoints[0].x, -0.05f, localPoints[0].y));
        vertices.Add(new Vector3(-localPoints[1].x, -0.05f, localPoints[1].y));
        vertices.Add(new Vector3(-localPoints[2].x, -0.05f, localPoints[2].y));
        vertices.Add(new Vector3(-localPoints[3].x, -0.05f, localPoints[3].y));

        if (!ignoreTop)
        {
            vertices[2] += new Vector3(0, 0, borderWidth);
            vertices[3] += new Vector3(0, 0, borderWidth);
        }

        if (!ignoreBottom)
        {
            vertices[0] -= new Vector3(0, 0, borderWidth);
            vertices[1] -= new Vector3(0, 0, borderWidth);
        }

        if (!ignoreLeft)
        {
            vertices[0] -= new Vector3(borderWidth, 0, 0);
            vertices[3] -= new Vector3(borderWidth, 0, 0);
        }

        if (!ignoreRight)
        {
            vertices[1] += new Vector3(borderWidth, 0, 0);
            vertices[2] += new Vector3(borderWidth, 0, 0);
        }

        normals.Add(Vector3.up);
        normals.Add(Vector3.up);
        normals.Add(Vector3.up);
        normals.Add(Vector3.up);

        uv.Add(new Vector2(0, 0));
        uv.Add(new Vector2(0, 1));
        uv.Add(new Vector2(1, 1));
        uv.Add(new Vector2(1, 0));

        backTriangles.Add(0);
        backTriangles.Add(2);
        backTriangles.Add(1);
        backTriangles.Add(0);
        backTriangles.Add(3);
        backTriangles.Add(2);

        if (activePoints == null)
        {
            activePoints = new List <Vector2>();
        }
        else
        {
            activePoints.Clear();
        }

        if (countIgnore == 0)
        {
            activePoints.Add(localPoints[0] + new Vector2(borderWidth, 0));
            activePoints.Add(localPoints[1]);
            activePoints.Add(localPoints[2]);
            activePoints.Add(localPoints[3]);
            activePoints.Add(localPoints[0] + new Vector2(0, borderWidth));
            DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref borderTriangles, ref uv, borderWidth);
        }
        else if (countIgnore == 1)
        {
            int off = 0;
            if (ignoreTop)
            {
                off = 3;
            }
            else if (ignoreRight)
            {
                off = 2;
            }
            else if (ignoreBottom)
            {
                off = 1;
            }

            for (int i = 0; i < 4; i++)
            {
                int ci = i + off;
                if (ci > 3)
                {
                    ci -= 4;
                }
                activePoints.Add(localPoints[ci]);
            }
            DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref borderTriangles, ref uv, borderWidth);
        }
        else if (countIgnore == 2)
        {
            if (ignoreBottom && ignoreTop)
            {
                activePoints.Add(localPoints[1]);
                activePoints.Add(localPoints[2]);
                DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref borderTriangles, ref uv, borderWidth);
                activePoints.Add(localPoints[3]);
                activePoints.Add(localPoints[0]);
                DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref borderTriangles, ref uv, borderWidth);
            }
            else if (ignoreLeft && ignoreRight)
            {
                activePoints.Add(localPoints[0]);
                activePoints.Add(localPoints[1]);
                DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref borderTriangles, ref uv, borderWidth);
                activePoints.Add(localPoints[2]);
                activePoints.Add(localPoints[3]);
                DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref borderTriangles, ref uv, borderWidth);
            }
            else
            {
                DrawActivePointsCI3(control, ignoreTop, ignoreRight, ignoreBottom, activePoints, localPoints, ref vertices, ref normals, ref borderTriangles, ref uv);
            }
        }
        else if (countIgnore == 3)
        {
            DrawActivePointsCI3(control, ignoreTop, ignoreRight, ignoreBottom, activePoints, localPoints, ref vertices, ref normals, ref borderTriangles, ref uv);
        }
        else if (countIgnore == 4)
        {
            DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref borderTriangles, ref uv, borderWidth);
        }

        mesh.Clear();
#if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1
        mesh.vertices = vertices.ToArray();
        mesh.normals  = normals.ToArray();
        mesh.uv       = uv.ToArray();
#else
        mesh.SetVertices(vertices);
        mesh.SetNormals(normals);
        mesh.SetUVs(0, uv);
#endif
        mesh.subMeshCount = 2;

        mesh.SetTriangles(borderTriangles.ToArray(), 0);
        mesh.SetTriangles(backTriangles.ToArray(), 1);

        UpdateMaterialsQuote(control, index);
    }