Esempio n. 1
0
 private void UpdateMarker()
 {
     if (_marker == null)
     {
         if (markerType == OnlineMapsLocationServiceMarkerType.twoD)
         {
             _marker = OnlineMaps.instance.AddMarker(position, marker2DTexture, markerTooltip);
             (_marker as OnlineMapsMarker).align = marker2DAlign;
             if (useCompassForMarker)
             {
                 (_marker as OnlineMapsMarker).rotation = trueHeading / 360;
             }
         }
         else
         {
             OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;
             if (control == null)
             {
                 Debug.LogError("You must use the 3D control (Texture or Tileset).");
                 createMarkerInUserPosition = false;
                 return;
             }
             _marker       = control.AddMarker3D(position, marker3DPrefab);
             _marker.label = markerTooltip;
             if (useCompassForMarker)
             {
                 (_marker as OnlineMapsMarker3D).rotationY = trueHeading;
             }
         }
     }
     else
     {
         _marker.position = position;
     }
 }
Esempio n. 2
0
        private void Start()
        {
            // Gets the current 3D control.
            OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

            if (control == null)
            {
                Debug.LogError("You must use the 3D control (Texture or Tileset).");
                return;
            }

            //Create a marker to show the current GPS coordinates.
            //Instead of "null", you can specify the texture desired marker.
            locationMarker = OnlineMapsMarker3DManager.CreateItem(Vector2.zero, prefab);

            //Hide handle until the coordinates are not received.
            locationMarker.enabled = false;

            // Gets Location Service Component.
            OnlineMapsLocationService ls = OnlineMapsLocationService.instance;

            if (ls == null)
            {
                Debug.LogError(
                    "Location Service not found.\nAdd Location Service Component (Component / Infinity Code / Online Maps / Plugins / Location Service).");
                return;
            }

            //Subscribe to the GPS coordinates change
            ls.OnLocationChanged += OnLocationChanged;
            ls.OnCompassChanged  += OnCompassChanged;

            //Subscribe to zoom change
            OnlineMaps.instance.OnChangeZoom += OnChangeZoom;
        }
    private void Update()
    {
        float latitudeSpeed  = Input.GetAxis("Vertical") * Time.deltaTime;
        float longitudeSpeed = Input.GetAxis("Horizontal") * Time.deltaTime;

        if (Math.Abs(latitudeSpeed) < float.Epsilon && Math.Abs(longitudeSpeed) < float.Epsilon)
        {
            return;
        }

        if (map.control is OnlineMapsControlBase3D)
        {
            OnlineMapsControlBase3D control = map.control as OnlineMapsControlBase3D;
            if (control.allowCameraControl)
            {
                Vector3 v = Quaternion.Euler(0, control.cameraRotation.y, 0) * new Vector3(longitudeSpeed, 0, latitudeSpeed);
                longitudeSpeed = v.x;
                latitudeSpeed  = v.z;
            }
        }

        tileX += longitudeSpeed * speed;
        tileY -= latitudeSpeed * speed;

        double lng, lat;

        map.projection.TileToCoordinates(tileX, tileY, map.zoom, out lng, out lat);

        ignoreChangePosition = true;
        map.SetPosition(lng, lat);
        ignoreChangePosition = false;
    }
Esempio n. 4
0
    private void Start()
    {
        StartCoroutine(changeFramerate());
        ForceLandscapeLeft();

        if ((!LocalizationSupport.StringsLoaded))
        {
            LocalizationSupport.LoadStrings();
        }

        HideDownloading();

        control = (OnlineMapsTileSetControl)OnlineMapsControlBase.instance;
        api     = OnlineMaps.instance;

        map = OnlineMaps.instance;

        OnlineMapsControlBase3D control2 = GetComponent <OnlineMapsControlBase3D>();

        if (control2 == null)
        {
            Debug.Log("You must use the 3D control (Texture or Tileset).");
            return;
        }

        m_ButtonReset.SetActive(false);

        //OnlineMapsControlBase.instance.allowUserControl = false;//true;//false;
        //	OnlineMaps.instance.OnChangeZoom += OnChangeZoom;
        OnlineMapsTile.OnTileDownloaded         += OnTileDownloaded;
        OnlineMaps.instance.OnStartDownloadTile += OnStartDownloadTile;

        control2.OnMapPress   += OnMapPress;
        control2.OnMapRelease += OnMapRelease;
        control2.OnMapZoom    += OnMapZoom;

        //----------------
        // Set 2d mode
        Camera c = Camera.main;

        c.orthographic = true;
        //---------------

/*		control2.setUpdateControl (true);
 *              control2.setAlwaysUpdateControl (true);
 *              control2.allowUserControl = true;
 */
        m_ButtonBack.GetComponentInChildren <UnityEngine.UI.Text>().text = LocalizationSupport.GetString("Back");
        m_ButtonNext.GetComponentInChildren <UnityEngine.UI.Text>().text = LocalizationSupport.GetString("BtnDownload");
        m_ExplanationText.GetComponent <UnityEngine.UI.Text>().text      = LocalizationSupport.GetString("ExplanationOfflineAccess");


        m_DownloadBtnStart.GetComponentInChildren <UnityEngine.UI.Text>().text     = LocalizationSupport.GetString("BtnDownloadNow");
        m_DownloadBtnCompleted.GetComponentInChildren <UnityEngine.UI.Text>().text = LocalizationSupport.GetString("Ok");
        m_ButtonNext.SetActive(false);
        //OnLocationChanged (new Vector2 (0.0f, 0.0f));

        toUserLocation();
    }
Esempio n. 5
0
    private void touchedPos(Vector3 pos)
    {
        Vector3 mouseGeoLocation = OnlineMapsControlBase.instance.GetCoords(pos);



        // Get the geographical coordinates of the cursor.
        //Vector2 cursorCoords = map.control.GetCoords();

        // Create a new marker at the specified coordinates.
        OnlineMapsControlBase3D control2 = GetComponent <OnlineMapsControlBase3D> ();

        if (m_bPin1Set == false)
        {
            OnlineMapsMarker3D marker = control2.AddMarker3D(mouseGeoLocation.x, mouseGeoLocation.y, m_PinPlane); //m_PinPlaneRed);
            // OnlineMapsMarker3D marker = control2.AddMarker3D (mouseGeoLocation, m_PinPlane);
            marker.scale   = 18.0f;                                                                               //30.0f;//18.0f;
            m_Pin1         = marker;
            m_Pin1Position = mouseGeoLocation;
            m_bPin1Set     = true;
        }
        else if (m_bPin2Set == false)
        {
            OnlineMapsMarker3D marker = control2.AddMarker3D(mouseGeoLocation.x, mouseGeoLocation.y, m_PinPlane); //m_PinPlaneRed);
            //   OnlineMapsMarker3D marker = control2.AddMarker3D (mouseGeoLocation, m_PinPlane);
            marker.scale   = 18.0f;                                                                               //30.0f;//18.0f;
            m_Pin2         = marker;
            m_Pin2Position = mouseGeoLocation;
            m_bPin2Set     = true;
        }

        //	OnlineMapsMarker marker = map.AddMarker(cursorCoords, m_PinPlane, "Marker " + (map.markers.Length + 1));

        // Save marker and coordinates.
        //	markerPositions.Add(mouseGeoLocation);
        //		markers.Add(marker);

        // Mark that markers changed.
        changed = true;


        m_ButtonReset.SetActive(true);

        addLineToPin();
        Debug.Log("Added marker at pos: " + mouseGeoLocation.x + " y: " + mouseGeoLocation.y);

        if (m_bPin1Set && m_bPin2Set)
        {
            m_ButtonNext.SetActive(true);
        }
        else
        {
            m_ButtonNext.SetActive(false);
        }

        m_ExplanationText.SetActive(false);
        m_ExplanationBack.SetActive(false);
    }
Esempio n. 6
0
        /// <summary>
        /// The event, which is called when the user clicked on the map.
        /// </summary>
        private void OnMapClick()
        {
            OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

            // Create new marker
            OnlineMapsMarker3D marker = control.AddMarker3D(control.GetCoords(), markerPrefab);

            marker.scale = markerScale;
        }
Esempio n. 7
0
    private void OnPinClick(GameObject go)
    {
        OnlineMapsControlBase3D control2 = GetComponent <OnlineMapsControlBase3D> ();

        if (m_bPin1Set)
        {
            if (m_Pin1.instance == go)
            {
                m_bPin1Set = false;
            }
        }
        if (m_bPin2Set)
        {
            if (m_Pin2.instance == go)
            {
                m_bPin2Set = false;
            }
        }

        api.RemoveAllMarkers();
        api.RemoveAllDrawingElements();
        if (control2 != null)
        {
            control2.RemoveAllMarker3D();
        }

        if (m_bPin1Set)
        {
            OnlineMapsMarker3D marker = control2.AddMarker3D(m_Pin1Position.x, m_Pin1Position.y, m_PinPlane); //m_PinPlaneRed);
            //OnlineMapsMarker3D marker = control2.AddMarker3D (m_Pin1Position, m_PinPlane);
            marker.scale = 18.0f;                                                                             //30.0f;//18.0f;
            m_Pin1       = marker;
        }
        if (m_bPin2Set)
        {
            OnlineMapsMarker3D marker = control2.AddMarker3D(m_Pin2Position.x, m_Pin2Position.y, m_PinPlane); //m_PinPlaneRed);
            //OnlineMapsMarker3D marker = control2.AddMarker3D (m_Pin2Position, m_PinPlane);
            marker.scale = 18.0f;                                                                             //30.0f;//18.0f;
            m_Pin2       = marker;
        }
        addLineToPin();

        if (m_bPin1Set == false && m_bPin2Set == false)
        {
            m_ButtonReset.SetActive(false);
        }
        if (m_bPin1Set && m_bPin2Set)
        {
            m_ButtonNext.SetActive(true);
        }
        else
        {
            m_ButtonNext.SetActive(false);
        }
    }
    public OnlineMapsMarker3D Create(double longitude, double latitude, GameObject prefab)
    {
        OnlineMapsMarker3D marker = _CreateItem(longitude, latitude);

        marker.prefab = prefab;
        OnlineMapsControlBase3D control = marker.control = OnlineMapsControlBase3D.instance;

        marker.scale = defaultScale;
        marker.Init(control.transform);
        Redraw();
        return(marker);
    }
Esempio n. 9
0
    private void Start()
    {
        // Get instance of OnlineMapsControlBase3D (Texture or Tileset)
        OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

        if (control == null)
        {
            Debug.LogError("You must use the 3D control (Texture or Tileset).");
            return;
        }

        // Subscribe to the click event.
        OnlineMapsControlBase.instance.OnMapDoubleClick += OnMapClick;
    }
Esempio n. 10
0
    private static void LoadControl(OnlineMapsXML el, OnlineMaps api)
    {
        OnlineMapsControlBase control = api.GetComponent <OnlineMapsControlBase>();

        if (control == null)
        {
            return;
        }

        control.allowAddMarkerByM   = el.Get <bool>("AllowAddMarkerByM");
        control.allowZoom           = el.Get <bool>("AllowZoom");
        control.allowUserControl    = el.Get <bool>("AllowUserControl");
        control.zoomInOnDoubleClick = el.Get <bool>("ZoomInOnDoubleClick");

        if (control is OnlineMapsControlBase3D)
        {
            OnlineMapsControlBase3D control3D = control as OnlineMapsControlBase3D;

            control3D.allowAddMarker3DByN = el.Get <bool>("AllowAddMarker3DByN");
            control3D.allowCameraControl  = el.Get <bool>("AllowCameraControl");
            control3D.marker2DMode        = (OnlineMapsMarker2DMode)el.Get <int>("Marker2DMode");
            control3D.marker2DSize        = el.Get <float>("Marker2DSize");
            control3D.marker3DScale       = el.Get <float>("Marker3DScale");
            control3D.activeCamera        = GetObject(el.Get <int>("Camera")) as Camera;

            if (control3D.allowCameraControl)
            {
                control3D.cameraDistance = el.Get <float>("CameraDistance");
                control3D.cameraRotation = el.Get <Vector2>("CameraRotation");
                control3D.cameraSpeed    = el.Get <Vector2>("CameraSpeed");
            }
        }

        if (control is OnlineMapsTileSetControl)
        {
            OnlineMapsTileSetControl ts = control as OnlineMapsTileSetControl;

            ts.checkMarker2DVisibility = (OnlineMapsTilesetCheckMarker2DVisibility)el.Get <int>("CheckMarker2DVisibility");
            ts.smoothZoom     = el.Get <bool>("SmoothZoom");
            ts.useElevation   = el.Get <bool>("UseElevation");
            ts.tileMaterial   = GetObject(el.Get <int>("TileMaterial")) as Material;
            ts.tilesetShader  = GetObject(el.Get <int>("TileShader")) as Shader;
            ts.drawingShader  = GetObject(el.Get <int>("DrawingShader")) as Shader;
            ts.markerMaterial = GetObject(el.Get <int>("MarkerMaterial")) as Material;
            ts.markerShader   = GetObject(el.Get <int>("MarkerShader")) as Shader;
        }
    }
Esempio n. 11
0
    private static void LoadMarkers3D(OnlineMapsXML el, OnlineMaps api)
    {
        OnlineMapsControlBase3D   control = api.GetComponent <OnlineMapsControlBase3D>();
        List <OnlineMapsMarker3D> markers = new List <OnlineMapsMarker3D>();

        foreach (OnlineMapsXML m in el)
        {
            OnlineMapsMarker3D marker = new OnlineMapsMarker3D();
            marker.position = m.Get <Vector2>("Position");
            marker.range    = m.Get <OnlineMapsRange>("Range");
            marker.label    = m.Get <string>("Label");
            marker.prefab   = GetObject(m.Get <int>("Prefab")) as GameObject;
            marker.rotation = Quaternion.Euler(m.Get <Vector3>("Rotation"));
            markers.Add(marker);
        }
        control.markers3D = markers.ToArray();
    }
Esempio n. 12
0
    public void OnReset()
    {
        OnlineMapsControlBase3D control2 = GetComponent <OnlineMapsControlBase3D> ();

        api.RemoveAllMarkers();
        api.RemoveAllDrawingElements();
        if (control2 != null)
        {
            control2.RemoveAllMarker3D();
        }
        m_ButtonReset.SetActive(false);
        m_ButtonNext.SetActive(false);

        m_bPin1Set = false;
        m_bPin2Set = false;
        hideLine();
    }
    protected override void OnEnable()
    {
        base.OnEnable();

        OnlineMapsControlBase3D control = map.control as OnlineMapsControlBase3D;

        if (control != null)
        {
            foreach (OnlineMapsMarker3D item in _items)
            {
                bool isFirstStart = item.manager == null;
                item.manager = this;
                item.control = control;
                if (!isFirstStart)
                {
                    item.Update();
                }
            }
        }
    }
Esempio n. 14
0
        private void Start()
        {
            // Get instance of OnlineMapsControlBase3D (Texture or Tileset)
            OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

            if (control == null)
            {
                Debug.LogError("You must use the 3D control (Texture or Tileset).");
                return;
            }

            // Marker position. Geographic coordinates.
            Vector2 markerPosition = new Vector2(0, 0);

            // Create 3D marker
            marker3D = OnlineMapsMarker3DManager.CreateItem(markerPosition, markerPrefab);

            // Specifies that marker should be shown only when zoom from 1 to 10.
            marker3D.range = new OnlineMapsRange(1, 10);
        }
 private void UpdateMarker()
 {
     if (_marker == null)
     {
         if (markerType == OnlineMapsLocationServiceMarkerType.twoD)
         {
             OnlineMapsMarker m2d = OnlineMapsMarkerManager.CreateItem(position, marker2DTexture, markerTooltip);
             _marker   = m2d;
             m2d.align = marker2DAlign;
             m2d.scale = markerScale;
             if (useCompassForMarker)
             {
                 m2d.rotationDegree = trueHeading;
             }
         }
         else
         {
             OnlineMapsControlBase3D control = map.control as OnlineMapsControlBase3D;
             if (control == null)
             {
                 Debug.LogError("You must use the 3D control (Texture or Tileset).");
                 createMarkerInUserPosition = false;
                 return;
             }
             OnlineMapsMarker3D m3d = OnlineMapsMarker3DManager.CreateItem(position, marker3DPrefab);
             _marker      = m3d;
             m3d.sizeType = marker3DSizeType;
             m3d.scale    = markerScale;
             m3d.label    = markerTooltip;
             if (useCompassForMarker)
             {
                 m3d.rotationY = trueHeading;
             }
         }
     }
     else
     {
         _marker.position = position;
     }
 }
Esempio n. 16
0
    private static void LoadMarkers3D(OnlineMapsXML el, OnlineMaps api)
    {
        OnlineMapsControlBase3D   control = api.GetComponent <OnlineMapsControlBase3D>();
        List <OnlineMapsMarker3D> markers = new List <OnlineMapsMarker3D>();

        foreach (OnlineMapsXML m in el)
        {
            OnlineMapsMarker3D marker = new OnlineMapsMarker3D();

            double mx = m.Get <double>("Longitude");
            double my = m.Get <double>("Latitude");

            marker.SetPosition(mx, my);

            Debug.Log(m["Range"].outerXml);
            marker.range    = m.Get <OnlineMapsRange>("Range");
            marker.label    = m.Get <string>("Label");
            marker.prefab   = GetObject(m.Get <int>("Prefab")) as GameObject;
            marker.rotation = Quaternion.Euler(m.Get <Vector3>("Rotation"));
            markers.Add(marker);
        }
        control.markers3D = markers.ToArray();
    }
Esempio n. 17
0
    // Función principal inicia las instancias de OnlineMas, y carga los datos
    private void Start()
    {
        //Debug.Log("start method 1..... IN " + Time.time * 1000);
        //Update map labels;
        OnlineMaps.instance.language = I18N.instance.gameLang.ToString().ToLower(CultureInfo.InvariantCulture);


        // Get instance of OnlineMapsControlBase3D (Texture or Tileset)
        OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

        if (control == null)
        {
            Debug.LogError("You must use the 3D control (Texture or Tileset).");
            return;
        }


        SilkMap.Instance.init();
        Camera.main.orthographicSize            = 287;
        OnlineMapsCameraOrbit.instance.lockPan  = true;
        OnlineMapsCameraOrbit.instance.lockTilt = true;


        initMarkers();

        map.customMarkerCanvas     = customMarkerCanvas;
        map.customMarkerGameObject = customMarkerGameObject;
        map.customGroupPointMarker = customGroupPointMarker;
        categoriesDictionary       = new Dictionary <string, ScriptableCategory>();
        categoriesGroups           = Resources.LoadAll <ScriptableCategory>("ScriptableCategories").ToList();

        FillCategoriesDictionary();
        Resources.UnloadUnusedAssets();
        GC.Collect();
        //Debug.Log("start method 4..... IN " + Time.time * 1000);
    }
Esempio n. 18
0
    /// <summary>
    /// Initializes this object.
    /// </summary>
    /// <param name="parent">
    /// The parent transform.
    /// </param>
    public void Init(Transform parent)
    {
        if (instance != null)
        {
            OnlineMapsUtils.Destroy(instance);
        }

        if (prefab == null)
        {
            instance = GameObject.CreatePrimitive(PrimitiveType.Cube);
            instance.transform.localScale = Vector3.one;
        }
        else
        {
            instance = Object.Instantiate(prefab) as GameObject;
        }

        _prefab = prefab;

        instance.transform.parent        = parent;
        instance.transform.localRotation = Quaternion.Euler(0, _rotationY, 0);

        instance.layer = parent.gameObject.layer;
        instance.AddComponent <OnlineMapsMarker3DInstance>().marker = this;
        visible = false;
        inited  = true;

        control = map.control as OnlineMapsControlBase3D;

        Update();

        if (OnInitComplete != null)
        {
            OnInitComplete(this);
        }
    }
 private void OnEnable()
 {
     control = (OnlineMapsControlBase3D)target;
 }
Esempio n. 20
0
    /// <summary>
    /// Updates marker instance.
    /// </summary>
    /// <param name="map">Reference to the map</param>
    /// <param name="control">Reference to the control</param>
    /// <param name="bounds">Bounds of the map mesh</param>
    /// <param name="tlx">Longitude of top-left corner of the map</param>
    /// <param name="tly">Latitude of top-left corner of the map</param>
    /// <param name="brx">Longitude of bottom-right corner of the map</param>
    /// <param name="bry">Latitude of bottom-right corner of the map</param>
    /// <param name="zoom">Zoom of the map</param>
    /// <param name="ttlx">Tile X of top-left corner of the map</param>
    /// <param name="ttly">Tile Y of top-left corner of the map</param>
    /// <param name="tbrx">Tile X of bottom-right corner of the map</param>
    /// <param name="tbry">Tile Y of bottom-right corner of the map</param>
    /// <param name="bestYScale">Best y scale for current map view</param>
    public void Update(OnlineMaps map, OnlineMapsControlBase3D control, Bounds bounds, double tlx, double tly, double brx, double bry, int zoom, double ttlx, double ttly, double tbrx, double tbry, float bestYScale)
    {
        if (!enabled)
        {
            return;
        }
        if (instance == null)
        {
            Init(map.transform);
        }

        if (!range.InRange(zoom))
        {
            visible = false;
        }
        else if (OnCheckMapBoundaries != null)
        {
            visible = OnCheckMapBoundaries();
        }
        else if (checkMapBoundaries)
        {
            if (latitude > tly || latitude < bry)
            {
                visible = false;
            }
            else if (tlx < brx && (longitude < tlx || longitude > brx))
            {
                visible = false;
            }
            else if (tlx > brx && longitude < tlx && longitude > brx)
            {
                visible = false;
            }
            else
            {
                visible = true;
            }
        }
        else
        {
            visible = true;
        }

        if (!visible)
        {
            return;
        }

        if (_prefab != prefab)
        {
            Reinit(tlx, tly, brx, bry, zoom);
        }

        double mx, my;

        map.projection.CoordinatesToTile(longitude, latitude, zoom, out mx, out my);

        int maxX = 1 << zoom;

        double sx  = tbrx - ttlx;
        double mpx = mx - ttlx;

        if (sx < 0)
        {
            sx += maxX;
        }

        if (checkMapBoundaries)
        {
            if (mpx < 0)
            {
                mpx += maxX;
            }
            else if (mpx > maxX)
            {
                mpx -= maxX;
            }
        }
        else
        {
            double dx1 = Math.Abs(mpx - ttlx);
            double dx2 = Math.Abs(mpx - tbrx);
            double dx3 = Math.Abs(mpx - tbrx + maxX);
            if (dx1 > dx2 && dx1 > dx3)
            {
                mpx += maxX;
            }
        }

        double px = mpx / sx;
        double pz = (ttly - my) / (ttly - tbry);

        _relativePosition = new Vector3((float)px, 0, (float)pz);

        OnlineMapsTileSetControl tsControl = control as OnlineMapsTileSetControl;

        if (tsControl != null)
        {
            px = -tsControl.sizeInScene.x / 2 - (px - 0.5) * tsControl.sizeInScene.x;
            pz = tsControl.sizeInScene.y / 2 + (pz - 0.5) * tsControl.sizeInScene.y;
        }
        else
        {
            Vector3 center = bounds.center;
            Vector3 size   = bounds.size;
            px = center.x - (px - 0.5) * size.x / map.transform.lossyScale.x - map.transform.position.x;
            pz = center.z + (pz - 0.5) * size.z / map.transform.lossyScale.z - map.transform.position.z;
        }

        Vector3 oldPosition = instance.transform.localPosition;
        float   y           = 0;

        if (altitude.HasValue)
        {
            float yScale = OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry);
            y = altitude.Value;
            if (altitudeType == OnlineMapsAltitudeType.relative && tsControl != null)
            {
                y += OnlineMapsElevationManagerBase.GetUnscaledElevation(px, pz, tlx, tly, brx, bry);
            }
            y *= yScale;

            if (tsControl != null)
            {
                if (OnlineMapsElevationManagerBase.instance.bottomMode == OnlineMapsElevationBottomMode.minValue)
                {
                    y -= OnlineMapsElevationManagerBase.instance.minValue * bestYScale;
                }
                y *= OnlineMapsElevationManagerBase.instance.scale;
            }
        }
        else if (tsControl != null)
        {
            y = OnlineMapsElevationManagerBase.GetElevation(px, pz, bestYScale, tlx, tly, brx, bry);
        }

        Vector3 newPosition = new Vector3((float)px, y, (float)pz);

        if (sizeType == SizeType.meters)
        {
            double dx, dy;
            OnlineMapsUtils.DistanceBetweenPoints(tlx, tly, brx, bry, out dx, out dy);
            dx = tsControl.sizeInScene.x / dx / 1000;
            dy = tsControl.sizeInScene.y / dy / 1000;

            double d  = (dx + dy) / 2 * scale;
            float  fd = (float)d;

            instance.transform.localScale = new Vector3(fd, fd, fd);
        }

        if (oldPosition != newPosition)
        {
            instance.transform.localPosition = newPosition;
        }
    }
    private void DrawTooltipForOtherControls(GUIStyle style)
    {
        foreach (OnlineMapsMarker marker in control.markerManager)
        {
            if (string.IsNullOrEmpty(marker.label))
            {
                continue;
            }

            Rect rect = marker.screenRect;

            if (rect.xMax > 0 && rect.xMin < Screen.width && rect.yMax > 0 && rect.yMin < Screen.height)
            {
                if (marker.OnDrawTooltip != null)
                {
                    marker.OnDrawTooltip(marker);
                }
                else if (OnlineMapsMarkerBase.OnMarkerDrawTooltip != null)
                {
                    OnlineMapsMarkerBase.OnMarkerDrawTooltip(marker);
                }
                else
                {
                    OnGUITooltip(style, marker.label, new Vector2(rect.x + rect.width / 2, rect.y + rect.height));
                }
            }
        }

        OnlineMapsControlBase3D control3D = control as OnlineMapsControlBase3D;

        if (control3D != null)
        {
            double tlx, tly, brx, bry;
            map.GetCorners(out tlx, out tly, out brx, out bry);
            if (brx < tlx)
            {
                brx += 360;
            }

            foreach (OnlineMapsMarker3D marker in control3D.marker3DManager)
            {
                if (string.IsNullOrEmpty(marker.label))
                {
                    continue;
                }

                double mx, my;
                marker.GetPosition(out mx, out my);

                if (!(((mx > tlx && mx < brx) || (mx + 360 > tlx && mx + 360 < brx) ||
                       (mx - 360 > tlx && mx - 360 < brx)) &&
                      my < tly && my > bry))
                {
                    continue;
                }

                if (marker.OnDrawTooltip != null)
                {
                    marker.OnDrawTooltip(marker);
                }
                else if (OnlineMapsMarkerBase.OnMarkerDrawTooltip != null)
                {
                    OnlineMapsMarkerBase.OnMarkerDrawTooltip(marker);
                }
                else
                {
                    double mx1, my1;
                    control3D.GetPosition(mx, my, out mx1, out my1);

                    double px = (-mx1 / map.width + 0.5) * control3D.cl.bounds.size.x;
                    double pz = (my1 / map.height - 0.5) * control3D.cl.bounds.size.z;

                    Vector3 offset = map.transform.rotation * new Vector3((float)px, 0, (float)pz);
                    offset.Scale(map.transform.lossyScale);

                    Vector3 p1 = map.transform.position + offset;
                    Vector3 p2 = p1 + new Vector3(0, 0, control3D.cl.bounds.size.z / map.height * marker.scale);

                    Vector2 screenPoint1 = control3D.activeCamera.WorldToScreenPoint(p1);
                    Vector2 screenPoint2 = control3D.activeCamera.WorldToScreenPoint(p2);

                    float yOffset = (screenPoint1.y - screenPoint2.y) * map.transform.localScale.x - 10;

                    OnGUITooltip(style, marker.label, screenPoint1 + new Vector2(0, yOffset));
                }
            }
        }
    }
 private void OnEnable()
 {
     control = (OnlineMapsControlBase3D) target;
 }
Esempio n. 23
0
    private void CreateMap()
    {
        OnlineMaps map = CreateMapGameObject();
        GameObject go  = map.gameObject;

        if (use3DControl == 0)
        {
            Texture2D texture = CreateTexture(map);

            if (mapControl2D == 0)
            {
                go.AddComponent <OnlineMapsGUITextureControl>();
                GUITexture guiTexture = go.GetComponent <GUITexture>();
                guiTexture.texture         = texture;
                go.transform.localPosition = new Vector3(0.5f, 0.5f);
                go.transform.localScale    = Vector3.zero;
                guiTexture.pixelInset      = new Rect(textureWidth / -2, textureHeight / -2, textureWidth, textureHeight);
            }
            else if (mapControl2D == 1)
            {
                go.AddComponent <OnlineMapsSpriteRendererControl>();
                SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>();
                spriteRenderer.sprite = Sprite.Create(texture, new Rect(0, 0, textureWidth, textureHeight), Vector2.zero);
                go.AddComponent <BoxCollider>();
            }
#if !UNITY_4_3 && !UNITY_4_5
            else if (mapControl2D == 2 || mapControl2D == 3)
            {
                RectTransform rectTransform = go.AddComponent <RectTransform>();
                rectTransform.SetParent(uGUIParent.transform as RectTransform);
                go.AddComponent <CanvasRenderer>();
                rectTransform.localPosition = Vector3.zero;
                rectTransform.anchorMax     = rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
                rectTransform.pivot         = new Vector2(0.5f, 0.5f);
                rectTransform.sizeDelta     = new Vector2(textureWidth, textureHeight);

                if (mapControl2D == 2)
                {
                    go.AddComponent <OnlineMapsUIImageControl>();
                    Image image = go.AddComponent <Image>();
                    image.sprite = Sprite.Create(texture, new Rect(0, 0, textureWidth, textureHeight), Vector2.zero);
                }
                else
                {
                    go.AddComponent <OnlineMapsUIRawImageControl>();
                    RawImage image = go.AddComponent <RawImage>();
                    image.texture = texture;
                }
            }
#endif
#if NGUI
            else if (mapControl2D == 4)
            {
                go.layer = NGUIParent.layer;
                UITexture uiTexture = go.AddComponent <UITexture>();
                uiTexture.mainTexture      = texture;
                uiTexture.width            = textureWidth;
                uiTexture.height           = textureHeight;
                go.transform.parent        = NGUIParent.transform;
                go.transform.localPosition = Vector3.zero;
                go.transform.localScale    = Vector3.one;
                go.transform.localRotation = Quaternion.Euler(Vector3.zero);
                BoxCollider boxCollider = go.AddComponent <BoxCollider>();
                boxCollider.size = new Vector3(textureWidth, textureHeight, 0);
                go.AddComponent <OnlineMapsNGUITextureControl>();
            }
#endif
#if DFGUI
            else if (mapControl2D == 5)
            {
                go.transform.parent = DFGUIParent.transform;

                dfTextureSprite textureSprite = go.AddComponent <dfTextureSprite>();
                textureSprite.Texture = texture;
                textureSprite.Width   = textureWidth;
                textureSprite.Height  = textureHeight;
                textureSprite.Pivot   = dfPivotPoint.MiddleCenter;
                textureSprite.transform.localPosition = Vector3.zero;

                go.AddComponent <OnlineMapsDFGUITextureControl>();
            }
#endif
#if IGUI
            else if (mapControl2D == 6)
            {
                go.transform.parent = IGUIParent.transform;

                iGUIImage image = go.AddComponent <iGUIImage>();
                image.image           = texture;
                image.positionAndSize = new Rect(0, 0, 1, 1);

                go.AddComponent <OnlineMapsIGUITextureControl>();
            }
#endif

            map.useSmartTexture = smartTexture;
            map.redrawOnPlay    = true;
        }
        else
        {
            OnlineMapsControlBase3D control3D = null;

            if (mapControl3D == 0)
            {
                map.target        = OnlineMapsTarget.tileset;
                map.tilesetWidth  = tilesetWidth;
                map.tilesetHeight = tilesetHeight;
                map.tilesetSize   = tilesetSize;

                OnlineMapsTileSetControl ts = go.AddComponent <OnlineMapsTileSetControl>();
                control3D         = ts;
                ts.useElevation   = useElevation;
                ts.bingAPI        = bingAPI;
                ts.smoothZoom     = smoothZoom;
                ts.tileMaterial   = tileMaterial;
                ts.markerMaterial = markerMaterial;
                ts.tilesetShader  = tilesetShader;
                ts.drawingShader  = drawingShader;
                ts.markerShader   = markerShader;

                if (moveCameraToTileset)
                {
                    GameObject cameraGO = activeCamera.gameObject;
                    float      minSide  = Mathf.Min(tilesetSize.x, tilesetSize.y);
                    Vector3    position = new Vector3(tilesetSize.x / -2, minSide, tilesetSize.y / 2);
                    cameraGO.transform.position = position;
                    cameraGO.transform.rotation = Quaternion.Euler(90, 180, 0);
                }

                if (useBuildings)
                {
                    go.AddComponent <OnlineMapsBuildings>();
                }
            }
            else if (mapControl3D == 1)
            {
                control3D           = go.AddComponent <OnlineMapsTextureControl>();
                map.useSmartTexture = smartTexture;
                map.redrawOnPlay    = true;
            }

            if (control3D != null)
            {
                control3D.activeCamera       = activeCamera;
                control3D.allowCameraControl = allowCameraControl;
            }
        }

        if (useLocationService)
        {
            go.AddComponent <OnlineMapsLocationService>();
        }
        if (useRWT)
        {
            go.AddComponent <OnlineMapsRWTConnector>();
        }

        EditorGUIUtility.PingObject(go);
        Selection.activeGameObject = go;
    }
Esempio n. 24
0
    /// <summary>
    /// Updates marker instance.
    /// </summary>
    /// <param name="map">Reference to the map</param>
    /// <param name="control">Reference to the control</param>
    /// <param name="bounds">Bounds of the map mesh</param>
    /// <param name="tlx">Longitude of top-left corner of the map</param>
    /// <param name="tly">Latitude of top-left corner of the map</param>
    /// <param name="brx">Longitude of botton-right corner of the map</param>
    /// <param name="bry">Latitude of botton-right corner of the map</param>
    /// <param name="zoom">Zoom of the map</param>
    /// <param name="ttlx">Tile X of top-left corner of the map</param>
    /// <param name="ttly">Tile Y of top-left corner of the map</param>
    /// <param name="tbrx">Tile X of botton-right corner of the map</param>
    /// <param name="tbry">Tile Y of botton-right corner of the map</param>
    /// <param name="bestYScale">Best y scale for current map view</param>
    public void Update(OnlineMaps map, OnlineMapsControlBase3D control, Bounds bounds, double tlx, double tly, double brx, double bry, int zoom, double ttlx, double ttly, double tbrx, double tbry /*, float bestYScale*/)
    {
        // if (!enabled) return;
        //   if (instance == null) Init(map.transform);

        /*
         * if (!range.InRange(zoom)) visible = false;
         * else if (checkMapBoundaries)
         * {
         *  if (latitude > tly || latitude < bry) visible = false;
         *  else if (tlx < brx && (longitude < tlx || longitude > brx)) visible = false;
         *  else if (tlx > brx && longitude < tlx && longitude > brx) visible = false;
         *  else visible = true;
         * }
         * else visible = true;
         *
         * if (!visible) return;*/

        //  if (_prefab != prefab) Reinit(tlx, tly, brx, bry, zoom);

        double mx, my;

        map.projection.CoordinatesToTile(longitude, latitude, zoom, out mx, out my);

        int maxX = 1 << zoom;

        double sx  = tbrx - ttlx;
        double mpx = mx - ttlx;

        if (sx < 0)
        {
            sx += maxX;
        }

        if (checkMapBoundaries)
        {
            if (mpx < 0)
            {
                mpx += maxX;
            }
            else if (mpx > maxX)
            {
                mpx -= maxX;
            }
        }
        else
        {
            double dx1 = Math.Abs(mpx - ttlx);
            double dx2 = Math.Abs(mpx - tbrx);
            double dx3 = Math.Abs(mpx - tbrx + maxX);
            if (dx1 > dx2 && dx1 > dx3)
            {
                mpx += maxX;
            }
        }

        double px = mpx / sx;
        double pz = (ttly - my) / (ttly - tbry);

        _relativePosition = new Vector3((float)px, 0, (float)pz);

        OnlineMapsTileSetControl tsControl = control as OnlineMapsTileSetControl;

        //  if (tsControl != null)
        {
            px = -tsControl.sizeInScene.x / 2 - (px - 0.5) * tsControl.sizeInScene.x;
            pz = tsControl.sizeInScene.y / 2 + (pz - 0.5) * tsControl.sizeInScene.y;
        }

        /*   else
         * {
         *     Vector3 center = bounds.center;
         *     Vector3 size = bounds.size;
         *     px = center.x - (px - 0.5) * size.x / map.transform.lossyScale.x - map.transform.position.x;
         *     pz = center.z + (pz - 0.5) * size.z / map.transform.lossyScale.z - map.transform.position.z;
         * }*/

        Vector3 oldPosition = instance.transform.localPosition;

        /*  float y = 0;
         *
         * if (altitude.HasValue)
         * {
         *    float yScale = OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry);
         *    y = altitude.Value * yScale;
         *    if (tsControl != null)
         *    {
         *        if (OnlineMapsElevationManagerBase.instance.bottomMode == OnlineMapsElevationBottomMode.minValue) y -= OnlineMapsElevationManagerBase.instance.minValue * bestYScale;
         *        y *= OnlineMapsElevationManagerBase.instance.scale;
         *    }
         * }
         * else if (tsControl != null)
         * {
         *    y = OnlineMapsElevationManagerBase.GetElevation(px, pz, bestYScale, tlx, tly, brx, bry);
         * }*/

        //   Vector3 newPosition = new Vector3((float)px, y, (float)pz);
        Vector3 newPosition = new Vector3((float)px, 0, (float)pz);

        if (oldPosition != newPosition)
        {
            instance.transform.localPosition = newPosition;
        }
    }
Esempio n. 25
0
 public override void Dispose()
 {
     control.OnUpdate3DMarkers -= Update3DMarkers;
     control = null;
 }
Esempio n. 26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="control">Reference to 3D control</param>
 public OnlineMapsMarker3DDrawer(OnlineMapsControlBase3D control)
 {
     this.control = control;
     control.OnUpdate3DMarkers += Update3DMarkers;
 }
 protected virtual void OnEnable()
 {
     control = target as OnlineMapsControlBase3D;
     CacheSerializedProperties();
 }
Esempio n. 28
0
    // Use this for initialization
    void Start()
    {
        if (!started)
        {
            started = true;
            UnityEngine.Debug.Log(Player.playerID);
            try
            {
                locService = Input.location;
                if (locService.status == LocationServiceStatus.Stopped)
                {
                    if (!locService.isEnabledByUser)
                    {
                        //display some sort of error message telling user location services must be enabled
                    }

                    locService.Start();

                    //isnt working so remove location startup stuff so dont have to wait
                    //MAKE SURE YOU CHANGE BACK LATER (SHOULD BE 30)
                    int timeout = 30;

                    //potentially display some sort of loading screen while waiting for location services, etc.
                    while (Input.location.status == LocationServiceStatus.Initializing && timeout > 0)
                    {
                        Thread.Sleep(1000);
                        timeout--;
                    }

                    if (timeout < 1 || Input.location.status == LocationServiceStatus.Failed)
                    {
                        //display some sort of error message, failed to start location services
                    }
                }

                //DontDestroyOnLoad(gameObject);

                coords = new byte[UPDATE_SIZE];
                size   = new byte[4];

                //remote endpoint of the server
                IPEndPoint remoteEP = new IPEndPoint(IP, OVERWORLD_PORT);

                //create TCP socket
                client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                //connect to remote endpoint
                client.Connect(remoteEP);

                UnityEngine.Debug.Log("Connect Overworld Successful");

                //send the players id to the server
                client.Send(Player.playerID.ToByteArray());

                //upNearbyObj = false;
                waitUpdate = new ManualResetEvent(false);
                rand       = new System.Random();

                UnityEngine.Debug.Log("Connect Successful");


                t = new Timer(setUpdate, null, 0, 12000);

                //start receiving updates from server
                client.BeginReceive(size, 0, 4, 0, new AsyncCallback(updateDriver), null);

                // Gets the current 3D control.
                control = OnlineMapsControlBase3D.instance;
                if (control == null)
                {
                    UnityEngine.Debug.LogError("You must use the 3D control (Texture or Tileset).");
                    return;
                }
                //Create a marker to show the current GPS coordinates.
                //Instead of "null", you can specify the texture desired marker.
                locationMarker = control.AddMarker3D(Vector2.zero, prefab);

                //Hide handle until the coordinates are not received.
                locationMarker.enabled = true;

                // Gets Location Service Component.
                OnlineMapsLocationService ls = OnlineMapsLocationService.instance;

                if (ls == null)
                {
                    UnityEngine.Debug.LogError(
                        "Location Service not found.\nAdd Location Service Component (Component / Infinity Code / Online Maps / Plugins / Location Service).");
                    return;
                }

                //Subscribe to the GPS coordinates change
                ls.OnLocationChanged += OnLocationChanged;
                ls.OnCompassChanged  += OnCompassChanged;
            }
            //catch exception if fail to connect
            catch (Exception e)
            {
                UnityEngine.Debug.Log(e.ToString());
                UnityEngine.Debug.Log("Connection Failure");
            }
        }
    }
    /// <summary>
    /// Updates marker instance.
    /// </summary>
    /// <param name="map">Reference to the map</param>
    /// <param name="control">Reference to the control</param>
    /// <param name="bounds">Bounds of the map mesh</param>
    /// <param name="tlx">Longitude of top-left corner of the map</param>
    /// <param name="tly">Latitude of top-left corner of the map</param>
    /// <param name="brx">Longitude of botton-right corner of the map</param>
    /// <param name="bry">Latitude of botton-right corner of the map</param>
    /// <param name="zoom">Zoom of the map</param>
    /// <param name="ttlx">Tile X of top-left corner of the map</param>
    /// <param name="ttly">Tile Y of top-left corner of the map</param>
    /// <param name="tbrx">Tile X of botton-right corner of the map</param>
    /// <param name="tbry">Tile Y of botton-right corner of the map</param>
    /// <param name="bestYScale">Best y scale for current map view</param>
    public void Update(OnlineMaps map, OnlineMapsControlBase3D control, Bounds bounds, double tlx, double tly, double brx, double bry, int zoom, double ttlx, double ttly, double tbrx, double tbry, float bestYScale)
    {
        if (!enabled)
        {
            return;
        }
        if (instance == null)
        {
            Init(map.transform);
        }

        if (!range.InRange(zoom))
        {
            visible = false;
        }
        else if (checkMapBoundaries)
        {
            if (latitude > tly || latitude < bry)
            {
                visible = false;
            }
            else if (tlx < brx && (longitude < tlx || longitude > brx))
            {
                visible = false;
            }
            else if (tlx > brx && longitude < tlx && longitude > brx)
            {
                visible = false;
            }
            else
            {
                visible = true;
            }
        }
        else
        {
            visible = true;
        }

        if (!visible)
        {
            return;
        }

        if (_prefab != prefab)
        {
            Reinit(tlx, tly, brx, bry, zoom);
        }

        double mx, my;

        map.projection.CoordinatesToTile(longitude, latitude, zoom, out mx, out my);

        int maxX = 1 << zoom;

        double sx  = tbrx - ttlx;
        double mpx = mx - ttlx;

        if (sx < 0)
        {
            sx += maxX;
        }

        if (checkMapBoundaries)
        {
            if (mpx < 0)
            {
                mpx += maxX;
            }
            else if (mpx > maxX)
            {
                mpx -= maxX;
            }
        }
        else
        {
            double dx1 = Math.Abs(mpx - ttlx);
            double dx2 = Math.Abs(mpx - tbrx);
            double dx3 = Math.Abs(mpx - tbrx + maxX);
            if (dx1 > dx2 && dx1 > dx3)
            {
                mpx += maxX;
            }
        }

        double px = mpx / sx;
        double pz = (ttly - my) / (ttly - tbry);

        _relativePosition = new Vector3((float)px, 0, (float)pz);

        OnlineMapsTileSetControl tsControl = control as OnlineMapsTileSetControl;

        if (tsControl != null)
        {
            px = -map.tilesetSize.x / 2 - (px - 0.5) * map.tilesetSize.x;
            pz = map.tilesetSize.y / 2 + (pz - 0.5) * map.tilesetSize.y;
        }
        else
        {
            Vector3 center = bounds.center;
            Vector3 size   = bounds.size;
            px = center.x - (px - 0.5) * size.x / map.transform.lossyScale.x - map.transform.position.x;
            pz = center.z + (pz - 0.5) * size.z / map.transform.lossyScale.z - map.transform.position.z;
        }

        Vector3 oldPosition = instance.transform.localPosition;
        float   y           = 0;

        if (altitude.HasValue)
        {
            y = altitude.Value * bestYScale;
            if (tsControl != null)
            {
                if (tsControl.elevationBottomMode == OnlineMapsTileSetControl.ElevationBottomMode.minValue)
                {
                    y -= tsControl.elevationMinValue * bestYScale;
                }
                y *= tsControl.elevationScale;
            }
        }
        else if (tsControl != null)
        {
            y = tsControl.GetElevationValue((float)px, (float)pz, bestYScale, tlx, tly, brx, bry);
        }

        Vector3 newPosition = new Vector3((float)px, y, (float)pz);

        if (oldPosition != newPosition)
        {
            instance.transform.localPosition = newPosition;
        }
    }
Esempio n. 30
0
 /// <summary>
 /// Updates marker instance.
 /// </summary>
 /// <param name="map">Reference to the map</param>
 /// <param name="control">Reference to the control</param>
 /// <param name="bounds">Bounds of the map mesh</param>
 /// <param name="tlx">Longitude of top-left corner of the map</param>
 /// <param name="tly">Latitude of top-left corner of the map</param>
 /// <param name="brx">Longitude of bottom-right corner of the map</param>
 /// <param name="bry">Latitude of bottom-right corner of the map</param>
 /// <param name="zoom">Zoom of the map</param>
 /// <param name="ttlx">Tile X of top-left corner of the map</param>
 /// <param name="ttly">Tile Y of top-left corner of the map</param>
 /// <param name="tbrx">Tile X of bottom-right corner of the map</param>
 /// <param name="tbry">Tile Y of bottom-right corner of the map</param>
 /// <param name="bestYScale">Best y scale for current map view</param>
 public void Update(OnlineMaps map, OnlineMapsControlBase3D control, Bounds bounds, double tlx, double tly, double brx, double bry, int zoom, double ttlx, double ttly, double tbrx, double tbry, float bestYScale)
 {
     Update(bounds, tlx, tly, brx, bry, zoom, ttlx, ttly, tbrx, tbry, bestYScale);
 }