Example #1
0
    private void LoadTile(OnlineMapsTile tile, byte[] bytes)
    {
        Texture2D texture = new Texture2D(0, 0, TextureFormat.RGB24, false);

        texture.LoadImage(bytes);
        texture.wrapMode = TextureWrapMode.Clamp;

        if (map.target == OnlineMapsTarget.texture)
        {
            tile.ApplyTexture(texture);
            map.buffer.ApplyTile(tile);
            OnlineMapsUtils.DestroyImmediate(texture);
        }
        else
        {
            tile.texture = texture;
            tile.status  = OnlineMapsTileStatus.loaded;
        }

        if (map.traffic && !string.IsNullOrEmpty(tile.trafficURL))
        {
            if (!TryLoadTraffic(tile))
            {
                tile.trafficWWW             = OnlineMapsUtils.GetWWW(tile.trafficURL);
                tile.trafficWWW.customData  = tile;
                tile.trafficWWW.OnComplete += map.OnTrafficWWWComplete;
            }
        }
    }
Example #2
0
    /// <summary>
    /// Initialises this object.
    /// </summary>
    /// <param name="parent">
    /// The parent transform.
    /// </param>
    public void Init(Transform parent)
    {
        if (instance != null)
        {
            OnlineMapsUtils.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;
        visible = false;
        inited  = true;

        Update();
    }
Example #3
0
    public static void CheckMultipleInstances(OnlineMapsControlBase control, ref bool dirty)
    {
        OnlineMapsControlBase[] controls = control.GetComponents <OnlineMapsControlBase>();
        if (controls.Length > 1)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);

            EditorGUILayout.HelpBox("Problem detected:\nMultiple instances of controls.\nYou can use only one control.", MessageType.Error);

            int controlIndex = -1;

            for (int i = 0; i < controls.Length; i++)
            {
                if (GUILayout.Button("Use " + controls[i].GetType()))
                {
                    controlIndex = i;
                }
            }

            if (controlIndex != -1)
            {
                OnlineMapsControlBase activeControl = controls[controlIndex];
                foreach (OnlineMapsControlBase c in controls)
                {
                    if (c != activeControl)
                    {
                        OnlineMapsUtils.DestroyImmediate(c);
                    }
                }
                dirty = true;
            }

            EditorGUILayout.EndVertical();
        }
    }
Example #4
0
        private void OnUpdateLate()
        {
            OnlineMapsMarker tooltipMarker = OnlineMaps.instance.tooltipMarker as OnlineMapsMarker;

            if (tooltipMarker != null)
            {
                if (tooltip == null)
                {
                    tooltip = Instantiate(tooltipPrefab) as GameObject;
                    (tooltip.transform as RectTransform).SetParent(container.transform);
                }
                Vector2 screenPosition = OnlineMapsControlBase.instance.GetScreenPosition(tooltipMarker.position);
                screenPosition.y += tooltipMarker.height;
                Vector2 point;
                Camera  cam = container.renderMode == RenderMode.ScreenSpaceOverlay ? null : container.worldCamera;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(container.transform as RectTransform, screenPosition, cam, out point);
                (tooltip.transform as RectTransform).localPosition = point;
                tooltip.GetComponentInChildren <Text>().text       = tooltipMarker.label;
            }
            else
            {
                OnlineMapsUtils.DestroyImmediate(tooltip);
                tooltip = null;
            }
        }
Example #5
0
    public void LoadTexture()
    {
        if (status == OnlineMapsTileStatus.error)
        {
            return;
        }

        Texture2D texture = new Texture2D(OnlineMapsUtils.tileSize, OnlineMapsUtils.tileSize);

        if (map.useSoftwareJPEGDecoder)
        {
            LoadTexture(texture, data);
        }
        else
        {
            texture.LoadImage(data);
            texture.wrapMode = TextureWrapMode.Clamp;
        }

        CheckTextureSize(texture);

        if (status != OnlineMapsTileStatus.error)
        {
            ApplyTexture(texture);
            if (labelData != null)
            {
                ApplyLabelTexture();
            }
        }
        OnlineMapsUtils.DestroyImmediate(texture);
    }
Example #6
0
    private void ApplyLabelTexture()
    {
        Texture2D t = new Texture2D(OnlineMapsUtils.tileSize, OnlineMapsUtils.tileSize);

        t.LoadImage(labelData);
        labelData   = null;
        labelColors = t.GetPixels32();

        if (map.target == OnlineMapsTarget.texture)
        {
#if !UNITY_WEBGL
            if (map.renderInThread)
            {
                OnlineMapsThreadManager.AddThreadAction(MergeColors);
            }
            else
            {
                MergeColors();
            }
#else
            MergeColors();
#endif
            OnlineMapsUtils.DestroyImmediate(t);
        }
        else
        {
            _colors = texture.GetPixels32();
            MergeColors();
            t.SetPixels32(_colors);
            texture = t;
            _colors = null;
        }
    }
    /// <summary>
    /// Initialises this object.
    /// </summary>
    /// <param name="parent">
    /// The parent transform.
    /// </param>
    public void Init(Transform parent)
    {
        if (instance != null)
        {
            OnlineMapsUtils.DestroyImmediate(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;

        Update();

        if (OnInitComplete != null)
        {
            OnInitComplete(this);
        }
    }
Example #8
0
        /// <summary>
        /// This method is called when loading the tile.
        /// </summary>
        /// <param name="tile">Reference to tile</param>
        private void OnStartDownloadTile(OnlineMapsTile tile)
        {
            // Get local path.
            string path = GetTilePath(tile);

            // If the tile is cached.
            if (File.Exists(path))
            {
                // Load tile texture from cache.
                Texture2D tileTexture = new Texture2D(256, 256, TextureFormat.RGB24, false);
                tileTexture.LoadImage(File.ReadAllBytes(path));
                tileTexture.wrapMode = TextureWrapMode.Clamp;

                // Send texture to map.
                if (OnlineMaps.instance.target == OnlineMapsTarget.texture)
                {
                    tile.ApplyTexture(tileTexture);
                    OnlineMaps.instance.buffer.ApplyTile(tile);
                    OnlineMapsUtils.DestroyImmediate(tileTexture);
                }
                else
                {
                    tile.texture = tileTexture;
                    tile.status  = OnlineMapsTileStatus.loaded;
                }

                // Redraw map.
                OnlineMaps.instance.Redraw();
            }
            else
            {
                // If the tile is not cached, download tile with a standard loader.
                OnlineMaps.instance.StartDownloadTile(tile);
            }
        }
    private void Start()
    {
        rwt = GetComponent <RealWorldTerrainContainer>();
        if (rwt == null)
        {
            Debug.LogError("Real World Terrain Connector should be together c Real World Terrain Container.");
            OnlineMapsUtils.DestroyImmediate(this);
            return;
        }

        if (positionMode == OnlineMapsRWTConnectorPositionMode.transform && targetTransform == null)
        {
            Debug.LogError("Target Transform is not specified.");
            OnlineMapsUtils.DestroyImmediate(this);
            return;
        }

        api = OnlineMaps.instance;

        if (mode == OnlineMapsRWTConnectorMode.centerOnPosition)
        {
            api.position = currentPosition;
        }
        else if (mode == OnlineMapsRWTConnectorMode.markerOnPosition)
        {
            marker = api.AddMarker(currentPosition, markerTexture, markerLabel);
        }
    }
        private void OnUpdateLate()
        {
            OnlineMapsMarkerBase tooltipMarker = OnlineMaps.instance.tooltipMarker;

            if (tooltipMarker != null && !string.IsNullOrEmpty(tooltipMarker.label))
            {
                if (tooltip == null)
                {
                    tooltip = Instantiate(tooltipPrefab) as GameObject;
                    tooltip.transform.parent     = container.transform;
                    tooltip.transform.localScale = Vector3.one;
                    widget = tooltip.GetComponent <UIWidget>();
                    label  = widget.GetComponentInChildren <UILabel>();
                }

                Vector2 screenPosition = OnlineMapsControlBase.instance.GetScreenPosition(tooltipMarker.position);

                float ratio = (float)widget.root.activeHeight / Screen.height;
                float width = Mathf.Ceil(Screen.width * ratio);

                screenPosition.x = (screenPosition.x / Screen.width - 0.5f) * width;
                screenPosition.y = (screenPosition.y / Screen.height - 0.5f) * widget.root.activeHeight;

                label.text = tooltipMarker.label;

                Vector2 buttonOffset = new Vector2(-widget.width / 2, widget.height);
                widget.SetRect(screenPosition.x + buttonOffset.x, screenPosition.y + buttonOffset.y, widget.width, widget.height);
            }
            else if (tooltip != null)
            {
                OnlineMapsUtils.DestroyImmediate(tooltip);
                tooltip = null;
            }
        }
Example #11
0
    /// <summary>
    /// Initialises this object.
    /// </summary>
    /// <param name="parent">
    /// The parent transform.
    /// </param>
    public void Init(Transform parent)
    {
        if (instance != null)
        {
            OnlineMapsUtils.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;
        visible = 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);
    }
Example #12
0
    private void RemoveAllBuildings()
    {
        foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in buildings)
        {
            if (OnBuildingDispose != null)
            {
                OnBuildingDispose(building.Value);
            }
            building.Value.Dispose();
            OnlineMapsUtils.DestroyImmediate(building.Value.gameObject);
        }

        foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in unusedBuildings)
        {
            if (OnBuildingDispose != null)
            {
                OnBuildingDispose(building.Value);
            }
            building.Value.Dispose();
            OnlineMapsUtils.DestroyImmediate(building.Value.gameObject);
        }

        buildings.Clear();
        unusedBuildings.Clear();
    }
Example #13
0
        private void OnStartDownloadTile(OnlineMapsTile tile)
        {
            Texture tileTexture = new Texture();

            // Here your code to load tile texture from any source.

            // Apply your texture in the buffer and redraws the map.
            if (map.target == OnlineMapsTarget.texture)
            {
                // Apply tile texture
                tile.ApplyTexture(tileTexture as Texture2D);

                // Send tile to buffer
                map.buffer.ApplyTile(tile);

                // Destroy the texture, because it is no longer needed.
                OnlineMapsUtils.DestroyImmediate(tileTexture);
            }
            else
            {
                // Send tile texture
                tile.texture = tileTexture as Texture2D;

                // Change tile status
                tile.status = OnlineMapsTileStatus.loaded;
            }

            // Redraw map (using best redraw type)
            map.CheckRedrawType();
        }
Example #14
0
 protected override void OnEnableLate()
 {
     if (gTexture == null)
     {
         Debug.LogError("Can not find GUITexture.");
         OnlineMapsUtils.DestroyImmediate(this);
     }
 }
Example #15
0
 /// <summary>
 /// Dispose billboard instance
 /// </summary>
 public void Dispose()
 {
     if (gameObject != null)
     {
         OnlineMapsUtils.DestroyImmediate(gameObject);
     }
     marker = null;
 }
 protected override void OnEnableLate()
 {
     image = GetComponent <iGUIImage>();
     if (image == null)
     {
         Debug.LogError("Can not find iGUIImage.");
         OnlineMapsUtils.DestroyImmediate(this);
     }
 }
 public static void RemoveAllMarkers()
 {
     foreach (uGUICustomMarkerExample marker in markers)
     {
         marker.Dispose();
         OnlineMapsUtils.DestroyImmediate(marker.gameObject);
     }
     markers.Clear();
 }
Example #18
0
    public override void OnInspectorGUI()
    {
        GUILayout.Label("Please do not use this Control.\nIt is the base class for other Controls.", OnlineMapsEditor.warningStyle);

        if (GUILayout.Button("Remove"))
        {
            OnlineMapsUtils.DestroyImmediate(target);
        }
    }
Example #19
0
 protected override void OnEnableLate()
 {
     sprite = GetComponent <dfTextureSprite>();
     if (sprite == null)
     {
         Debug.LogError("Can not find dfTextureSprite.");
         OnlineMapsUtils.DestroyImmediate(this);
     }
 }
 protected override void OnEnableLate()
 {
     spriteRenderer = GetComponent <SpriteRenderer>();
     if (spriteRenderer == null)
     {
         Debug.LogError("Can not find SpriteRenderer.");
         OnlineMapsUtils.DestroyImmediate(this);
     }
 }
Example #21
0
    /// <summary>
    /// Method thats called when drawing element remove from map.
    /// </summary>
    public void OnRemoveFromMap()
    {
        if (mesh == null)
        {
            return;
        }

        OnlineMapsUtils.DestroyImmediate(gameObject);
        mesh = null;
    }
Example #22
0
 /// <summary>
 /// Reinitialises this object.
 /// </summary>
 /// <param name="tlx">Top-left longitude of map</param>
 /// <param name="tly">Top-left latitude of map</param>
 /// <param name="brx">Bottom-right longitude of map</param>
 /// <param name="bry">Bottom-right latitude of map</param>
 /// <param name="zoom">Map zoom</param>
 public void Reinit(double tlx, double tly, double brx, double bry, int zoom)
 {
     if (instance)
     {
         Transform parent = instance.transform.parent;
         OnlineMapsUtils.DestroyImmediate(instance);
         Init(parent);
     }
     Update(tlx, tly, brx, bry, zoom);
 }
 protected override void OnEnableLate()
 {
     uiWidget  = GetComponent <UIWidget>();
     uiTexture = GetComponent <UITexture>();
     if (uiTexture == null)
     {
         Debug.LogError("Can not find UITexture.");
         OnlineMapsUtils.DestroyImmediate(this);
     }
 }
Example #24
0
    private void Update()
    {
        if (marker as OnlineMapsMarker3D == null)
        {
            OnlineMapsUtils.DestroyImmediate(gameObject);
            return;
        }

        UpdateBaseProps();
    }
 /// <summary>
 /// Remove all 3D markers from map.
 /// </summary>
 public void RemoveAllMarker3D()
 {
     foreach (OnlineMapsMarker3D marker in markers3D)
     {
         if (marker.instance != null)
         {
             OnlineMapsUtils.DestroyImmediate(marker.instance);
         }
     }
     markers3D = new OnlineMapsMarker3D[0];
 }
Example #26
0
 /// <summary>
 /// Dispose billboard instance
 /// </summary>
 public void Dispose()
 {
     if (gameObject != null)
     {
         OnlineMapsUtils.DestroyImmediate(gameObject);
     }
     if (marker != null)
     {
         marker.OnInitComplete -= OnInitComplete;
     }
     marker = null;
 }
Example #27
0
    protected override void OnEnableLate()
    {
        image = GetComponent <RawImage>();
        if (image == null)
        {
            Debug.LogError("Can not find Image.");
            OnlineMapsUtils.DestroyImmediate(this);
        }

#if CURVEDUI
        curvedUI = image.canvas.GetComponent <CurvedUISettings>();
#endif
    }
        public static void RemoveMarkerAt(int index)
        {
            if (index < 0 || index >= markers.Count)
            {
                return;
            }

            uGUICustomMarkerExample marker = markers[index];

            OnlineMapsUtils.DestroyImmediate(marker.gameObject);
            marker.Dispose();
            markers.RemoveAt(index);
        }
 private void OnEnable()
 {
     _instance     = this;
     dragMarker    = null;
     map           = GetComponent <OnlineMaps>();
     activeTexture = map.texture;
     if (map == null)
     {
         Debug.LogError("Can not find a script OnlineMaps.");
         OnlineMapsUtils.DestroyImmediate(this);
         return;
     }
     map.control = this;
     OnEnableLate();
 }
    /// <summary>
    /// Removes the specified 3D marker.
    /// </summary>
    /// <param name="marker">3D marker</param>
    public void RemoveMarker3D(OnlineMapsMarker3D marker)
    {
        if (OnRemoveMarker3D != null && OnRemoveMarker3D(marker))
        {
            return;
        }

        List <OnlineMapsMarker3D> ms = markers3D.ToList();

        ms.Remove(marker);
        markers3D = ms.ToArray();
        if (marker.instance != null)
        {
            OnlineMapsUtils.DestroyImmediate(marker.instance);
        }
    }