private void DrawMarkerGUI(int i, ref int index, ref bool hasDeleted, OnlineMaps map, ref bool dirty)
    {
        EditorGUILayout.BeginVertical(GUI.skin.box);

        OnlineMapsMarker3D marker = control.markers3D[i];

        GUILayout.Label("Marker " + index);
        Vector2 oldPosition = marker.position;

        EditorGUI.BeginChangeCheck();

        marker.allowDefaultMarkerEvents = control.allowDefaultMarkerEvents;

        marker.position.y = EditorGUILayout.FloatField("Latitude: ", marker.position.y);
        marker.position.x = EditorGUILayout.FloatField("Longitude: ", marker.position.x);

        float min = marker.range.min;
        float max = marker.range.max;

        EditorGUILayout.MinMaxSlider(new GUIContent(string.Format("Zooms ({0}-{1}): ", marker.range.min, marker.range.max)), ref min, ref max, 3, 20);
        if (marker.range.Update(Mathf.RoundToInt(min), Mathf.RoundToInt(max)) && EditorApplication.isPlaying)
        {
            marker.Update(map.topLeftPosition, map.bottomRightPosition, map.zoom);
        }

        if (Application.isPlaying && marker.position != oldPosition)
        {
            marker.Update(map.topLeftPosition, map.bottomRightPosition, map.zoom);
        }

        marker.label = EditorGUILayout.TextField("Label: ", marker.label);
        marker.scale = EditorGUILayout.FloatField("Scale: ", marker.scale);
        GameObject prefab = marker.prefab;

        marker.prefab = (GameObject)EditorGUILayout.ObjectField("Prefab: ", marker.prefab, typeof(GameObject), false);

        if (Application.isPlaying && marker.prefab != prefab)
        {
            marker.Reinit(map.topLeftPosition, map.bottomRightPosition, map.zoom);
        }

        if (EditorGUI.EndChangeCheck())
        {
            dirty = true;
        }

        if (GUILayout.Button("Remove"))
        {
            control.markers3D[i] = null;
            hasDeleted           = true;
            if (Application.isPlaying)
            {
                Destroy(marker.instance);
            }
        }
        index++;
        EditorGUILayout.EndVertical();
    }
    protected void UpdateMarkers3D()
    {
        if (markers3D == null)
        {
            return;
        }

        int zoom = map.zoom;

        double tlx, tly, brx, bry;

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

        double ttlx, ttly, tbrx, tbry;

        map.projection.CoordinatesToTile(tlx, tly, zoom, out ttlx, out ttly);
        map.projection.CoordinatesToTile(brx, bry, zoom, out tbrx, out tbry);

        Bounds bounds     = cl.bounds;
        float  bestYScale = GetBestElevationYScale(tlx, tly, brx, bry);

        for (int i = 0; i < markers3D.Length; i++)
        {
            OnlineMapsMarker3D marker = markers3D[i];
            if (marker != null)
            {
                marker.Update(map, this, bounds, tlx, tly, brx, bry, zoom, ttlx, ttly, tbrx, tbry, bestYScale);
            }
        }
    }
    protected override void AfterUpdate()
    {
        base.AfterUpdate();

        if (api.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onHover)
        {
            OnlineMapsMarkerInstanceBase markerInstance = GetBillboardMarkerFromScreen(Input.mousePosition);
            if (markerInstance != null)
            {
                api.tooltip       = markerInstance.marker.label;
                api.tooltipMarker = markerInstance.marker;
            }
        }

        if (allowAddMarker3DByN && Input.GetKeyUp(KeyCode.N))
        {
            OnlineMapsMarker3D m = new OnlineMapsMarker3D
            {
                position = GetCoords(),
                scale    = marker3DScale,
                control  = this
            };
            m.Init(transform);
            double tlx, tly, brx, bry;
            api.GetTopLeftPosition(out tlx, out tly);
            api.GetBottomRightPosition(out brx, out bry);
            m.Update(tlx, tly, brx, bry, api.zoom);
            List <OnlineMapsMarker3D> markerList = markers3D.ToList();
            markerList.Add(m);
            markers3D = markerList.ToArray();
        }
    }
    protected override void AfterUpdate()
    {
        RaycastHit hit;
        if (Physics.Raycast(activeCamera.ScreenPointToRay(Input.mousePosition), out hit))
        {
            OnlineMapsMarker3DInstance instance = hit.collider.gameObject.GetComponent<OnlineMapsMarker3DInstance>();
            if (instance != null)
            {
                api.tooltip = instance.marker.label;
                api.tooltipMarker = instance.marker;
            }
        }

        if (allowAddMarker3DByN && Input.GetKeyUp(KeyCode.N))
        {
            OnlineMapsMarker3D m = new OnlineMapsMarker3D
            {
                position = GetCoords()
            };
            m.Init(transform);
            m.Update(api.topLeftPosition, api.bottomRightPosition, api.zoom);
            List<OnlineMapsMarker3D> markerList = markers3D.ToList();
            markerList.Add(m);
            markers3D = markerList.ToArray();
        }
    }
Beispiel #5
0
    private void Update3DMarkers()
    {
        OnlineMapsMarker3DManager manager = control.marker3DManager;

        if (manager == null || !manager.enabled)
        {
            return;
        }
        if (control.cl == null)
        {
            return;
        }

        int zoom = map.zoom;

        double tlx, tly, brx, bry;

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

        double ttlx, ttly, tbrx, tbry;

        map.projection.CoordinatesToTile(tlx, tly, zoom, out ttlx, out ttly);
        map.projection.CoordinatesToTile(brx, bry, zoom, out tbrx, out tbry);

        int maxX = 1 << zoom;

        bool isEntireWorld = map.buffer.renderState.width == maxX * OnlineMapsUtils.tileSize;

        if (isEntireWorld && Math.Abs(tlx - brx) < 180)
        {
            if (tlx < 0)
            {
                brx  += 360;
                tbrx += maxX;
            }
            else
            {
                tlx  -= 360;
                ttlx -= maxX;
            }
        }

        Bounds bounds     = control.meshFilter.sharedMesh.bounds;
        float  bestYScale = OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry);

        for (int i = manager.Count - 1; i >= 0; i--)
        {
            OnlineMapsMarker3D marker = manager[i];
            if (marker.manager == null)
            {
                marker.manager = manager;
            }
            marker.Update(bounds, tlx, tly, brx, bry, zoom, ttlx, ttly, tbrx, tbry, bestYScale);
        }
    }
    protected override void AfterUpdate()
    {
        base.AfterUpdate();

        Vector2 inputPosition = GetInputPosition();

        if (allowCameraControl)
        {
#if (!UNITY_ANDROID && !UNITY_IPHONE) || UNITY_EDITOR
            if (Input.GetMouseButton(1))
            {
                isCameraControl = true;
                if (lastInputPosition != inputPosition && lastInputPosition != Vector2.zero)
                {
                    Vector2 offset = lastInputPosition - inputPosition;
                    cameraRotation.x -= offset.y / 10f * cameraSpeed.x;
                    cameraRotation.y -= offset.x / 10f * cameraSpeed.y;
                }
                lastInputPosition = inputPosition;
            }
            else if (isCameraControl)
            {
                lastInputPosition = Vector2.zero;
                isCameraControl   = false;
            }
#else
            if (!allowZoom && allowCameraControl)
            {
                if (Input.touchCount == 2)
                {
                    Vector2 p1 = Input.GetTouch(0).position;
                    Vector2 p2 = Input.GetTouch(1).position;

                    Vector2 center = Vector2.Lerp(p1, p2, 0.5f);
                    if (lastGestureCenter == Vector2.zero)
                    {
                        lastGestureCenter = center;
                    }
                    else if (lastGestureCenter != center)
                    {
                        Vector2 offset = lastGestureCenter - center;
                        cameraRotation.x -= offset.y / 10f * cameraSpeed.x;
                        cameraRotation.y -= offset.x / 10f * cameraSpeed.y;
                        lastGestureCenter = center;
                    }

                    lastInputPosition = center;
                }
                else
                {
                    lastGestureCenter = Vector2.zero;
                }
            }
#endif

            UpdateCameraPosition();
        }

        if (map.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onHover)
        {
            OnlineMapsMarkerInstanceBase markerInstance = GetBillboardMarkerFromScreen(inputPosition);
            if (markerInstance != null)
            {
                map.tooltip       = markerInstance.marker.label;
                map.tooltipMarker = markerInstance.marker;
            }
        }

        if (allowAddMarker3DByN && Input.GetKeyUp(KeyCode.N))
        {
            OnlineMapsMarker3D m = new OnlineMapsMarker3D
            {
                position = GetCoords(),
                scale    = marker3DScale,
                prefab   = default3DMarker,
                instance = default3DMarker != null?Instantiate(default3DMarker) as GameObject : null,
                control  = this
            };
            m.Init(transform);
            m.Update();

            if (markers3D == null)
            {
                markers3D = new OnlineMapsMarker3D[0];
            }
            Array.Resize(ref markers3D, markers3D.Length + 1);
            markers3D[markers3D.Length - 1] = m;
        }
    }
    protected override void AfterUpdate()
    {
        base.AfterUpdate();

        if (api.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onHover)
        {
            OnlineMapsMarkerInstanceBase markerInstance = GetBillboardMarkerFromScreen(Input.mousePosition);
            if (markerInstance != null)
            {
                api.tooltip = markerInstance.marker.label;
                api.tooltipMarker = markerInstance.marker;
            }
        }

        if (allowAddMarker3DByN && Input.GetKeyUp(KeyCode.N))
        {
            OnlineMapsMarker3D m = new OnlineMapsMarker3D
            {
                position = GetCoords(),
                scale = marker3DScale,
                control = this
            };
            m.Init(transform);
            double tlx, tly, brx, bry;
            api.GetTopLeftPosition(out tlx, out tly);
            api.GetBottomRightPosition(out brx, out bry);
            m.Update(tlx, tly, brx, bry, api.zoom);
            List<OnlineMapsMarker3D> markerList = markers3D.ToList();
            markerList.Add(m);
            markers3D = markerList.ToArray();
        }
    }