public virtual void DestroyInstance() { if (gameObject != null) { OnlineMapsUtils.Destroy(gameObject); gameObject = null; } if (mesh != null) { OnlineMapsUtils.Destroy(mesh); mesh = null; } if (materials != null) { for (int i = 0; i < materials.Length; i++) { Material material = materials[i]; if (material != null) { OnlineMapsUtils.Destroy(material); } } materials = null; } }
private void OnStartDownloadTile(OnlineMapsTile tile) { Texture2D tileTexture = new Texture2D(256, 256); // Here your code to load tile texture from any source. // Apply your texture in the buffer and redraws the map. if (map.control.resultIsTexture) { // Apply tile texture (tile as OnlineMapsRasterTile).ApplyTexture(tileTexture as Texture2D); // Send tile to buffer map.buffer.ApplyTile(tile); // Destroy the texture, because it is no longer needed. OnlineMapsUtils.Destroy(tileTexture); } else { // Send tile texture tile.texture = tileTexture; // Change tile status tile.status = OnlineMapsTileStatus.loaded; } // Redraw map (using best redraw type) map.Redraw(); }
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.Destroy(texture); }
private void RemoveAllBuildings() { foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in buildings) { if (OnBuildingDispose != null) { OnBuildingDispose(building.Value); } building.Value.Dispose(); OnlineMapsUtils.Destroy(building.Value.gameObject); } foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in unusedBuildings) { if (OnBuildingDispose != null) { OnBuildingDispose(building.Value); } building.Value.Dispose(); OnlineMapsUtils.Destroy(building.Value.gameObject); } buildings.Clear(); unusedBuildings.Clear(); }
private 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.Destroy(c); } } dirty = true; } EditorGUILayout.EndVertical(); } }
private void LoadTile(OnlineMapsTile tile, byte[] bytes) { Texture2D texture = new Texture2D(1, 1, TextureFormat.ARGB32, map.control.mipmapForTiles); texture.LoadImage(bytes); texture.wrapMode = TextureWrapMode.Clamp; if (map.control.resultIsTexture) { (tile as OnlineMapsRasterTile).ApplyTexture(texture); map.buffer.ApplyTile(tile); OnlineMapsUtils.Destroy(texture); } else { tile.texture = texture; tile.status = OnlineMapsTileStatus.loaded; } OnlineMapsRasterTile rTile = tile as OnlineMapsRasterTile; if (map.traffic && !string.IsNullOrEmpty(rTile.trafficURL)) { if (map.traffic && !string.IsNullOrEmpty(rTile.trafficURL)) { rTile.trafficWWW = new OnlineMapsWWW(rTile.trafficURL); rTile.trafficWWW["tile"] = tile; rTile.trafficWWW.OnComplete += OnlineMapsTileManager.OnTrafficWWWComplete; } } }
/// <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 (OnlineMapsControlBase.instance.resultIsTexture) { (tile as OnlineMapsRasterTile).ApplyTexture(tileTexture); OnlineMaps.instance.buffer.ApplyTile(tile); OnlineMapsUtils.Destroy(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. OnlineMapsTileManager.StartDownloadTile(tile); } }
private void OnUpdateLate() { OnlineMapsMarker tooltipMarker = OnlineMapsTooltipDrawerBase.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.Destroy(tooltip); tooltip = null; } }
private void CreateTexture() { string texturePath = string.Format("Assets/{0}.png", textureFilename); Texture2D texture = new Texture2D(textureWidth, textureHeight); File.WriteAllBytes(texturePath, texture.EncodeToPNG()); AssetDatabase.Refresh(); TextureImporter textureImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter; if (textureImporter != null) { textureImporter.mipmapEnabled = false; textureImporter.isReadable = true; textureImporter.textureCompression = TextureImporterCompression.Uncompressed; textureImporter.maxTextureSize = Mathf.Max(textureWidth, textureHeight); OnlineMapsControlBase control = map.GetComponent <OnlineMapsControlBase>(); if (control is OnlineMapsUIImageControl || control is OnlineMapsSpriteRendererControl) { textureImporter.spriteImportMode = SpriteImportMode.Single; textureImporter.npotScale = TextureImporterNPOTScale.None; } AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate); Texture2D newTexture = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D; pTexture.objectReferenceValue = newTexture; if (control is OnlineMapsSpriteRendererControl) { SpriteRenderer spriteRenderer = map.GetComponent <SpriteRenderer>(); spriteRenderer.sprite = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Sprite)) as Sprite; } else if (control is OnlineMapsUIImageControl) { Image img = map.GetComponent <Image>(); img.sprite = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Sprite)) as Sprite; } else if (control is OnlineMapsUIRawImageControl) { RawImage img = map.GetComponent <RawImage>(); img.texture = newTexture; } else if (control is OnlineMapsTextureControl) { Renderer renderer = map.GetComponent <Renderer>(); renderer.sharedMaterial.mainTexture = texture; } else if (control is OnlineMapsNGUITextureControl) { #if NGUI UITexture uiTexture = map.GetComponent <UITexture>(); uiTexture.mainTexture = newTexture; #endif } } OnlineMapsUtils.Destroy(texture); EditorUtility.UnloadUnusedAssetsImmediate(); }
public override void Dispose() { control.OnDrawMarkers -= OnDrawMarkers; control = null; if (markerBillboards != null) { foreach (KeyValuePair <int, OnlineMapsMarkerBillboard> pair in markerBillboards) { if (pair.Value != null) { pair.Value.Dispose(); } } } if (markersGameObjects != null) { foreach (GameObject go in markersGameObjects) { OnlineMapsUtils.Destroy(go); } } markerBillboards = null; markersGameObjects = null; markersMeshes = null; markersRenderers = null; markerBillboards = null; }
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.Destroy(tooltip); tooltip = null; } }
/// <summary> /// Initialises 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 = true; inited = true; Update(); if (OnInitComplete != null) { OnInitComplete(this); } }
public override void Dispose() { control.OnDrawMarkers -= OnDrawMarkers; control = null; if (markersGameObjects != null) { foreach (GameObject go in markersGameObjects) { OnlineMapsUtils.Destroy(go); } } if (usedMarkers != null) { foreach (FlatMarker flatMarker in usedMarkers) { flatMarker.Dispose(); } } markerComparer = null; markersGameObjects = null; markersMeshes = null; markersRenderers = null; markersVertices = null; usedMarkers = null; OnCheckMarker2DVisibility = null; OnGenerateMarkerVertices = null; OnGetFlatMarkerOffsetY = null; OnSetMarkersMesh = null; }
private void OnEnable() { _instance = this; dragMarker = null; if (map == null) { Debug.LogError("Can not find a script OnlineMaps."); OnlineMapsUtils.Destroy(this); return; } drawingElementManager = GetComponent <OnlineMapsDrawingElementManager>(); if (drawingElementManager == null) { drawingElementManager = gameObject.AddComponent <OnlineMapsDrawingElementManager>(); } markerManager = GetComponent <OnlineMapsMarkerManager>(); activeTexture = map.texture; OnlineMapsMarkerManager.Init(); OnlineMapsDrawingElementManager.Init(); if (resultIsTexture) { markerDrawer = new OnlineMapsMarkerBufferDrawer(this); } OnEnableLate(); }
protected virtual void Destroy() { lock (lockTiles) { tiles.Remove(this); } if (texture != null) { OnlineMapsUtils.Destroy(texture); } if (overlayBackTexture != null) { OnlineMapsUtils.Destroy(overlayBackTexture); } if (overlayFrontTexture != null) { OnlineMapsUtils.Destroy(overlayFrontTexture); } texture = null; overlayBackTexture = null; overlayFrontTexture = null; _customFields = null; _url = null; data = null; blockers = null; if (hasChilds) { foreach (OnlineMapsTile child in childs) { if (child != null) { child.parent = null; } } } if (parent != null) { if (parent.childs != null) { for (int i = 0; i < 4; i++) { if (parent.childs[i] == this) { parent.childs[i] = null; break; } } } } parent = null; childs = null; hasChilds = false; hasColors = false; OnDisposed = null; }
private void ApplyLabelTexture() { Texture2D t = new Texture2D(OnlineMapsUtils.tileSize, OnlineMapsUtils.tileSize); t.LoadImage(labelData); labelData = null; labelColors = t.GetPixels32(); if (map.control.resultIsTexture) { #if !UNITY_WEBGL if (map.renderInThread) { OnlineMapsThreadManager.AddThreadAction(MergeColors); } else { MergeColors(); } #else MergeColors(); #endif OnlineMapsUtils.Destroy(t); } else { _colors = texture.GetPixels32(); MergeColors(); t.SetPixels32(_colors); texture = t; _colors = null; } }
private void Start() { rwt = GetComponent <RealWorldTerrainContainer>(); if (rwt == null) { Debug.LogError("Real World Terrain Connector should be together c Real World Terrain Container."); OnlineMapsUtils.Destroy(this); return; } if (positionMode == PositionMode.transform && targetTransform == null) { Debug.LogError("Target Transform is not specified."); OnlineMapsUtils.Destroy(this); return; } map = OnlineMaps.instance; if (mode == Mode.centerOnPosition) { map.position = currentPosition; } else if (mode == Mode.markerOnPosition) { marker = map.AddMarker(currentPosition, markerTexture, markerLabel); } }
/// <summary> /// This method is called by clicking on the marker /// </summary> /// <param name="marker">The marker on which clicked</param> private void OnMarkerClick(OnlineMapsMarkerBase marker) { // Set active marker reference targetMarker = marker as OnlineMapsMarker; // Get a result item from instance of the marker CData data = marker["data"] as CData; if (data == null) { return; } // Show the popup bubble.SetActive(true); // Set title and address title.text = data.title; address.text = data.address; // Destroy the previous photo if (photo.texture != null) { OnlineMapsUtils.Destroy(photo.texture); photo.texture = null; } OnlineMapsWWW www = new OnlineMapsWWW(data.photo_url); www.OnComplete += OnDownloadPhotoComplete; // Initial update position UpdateBubblePosition(); }
protected override void OnEnableLate() { spriteRenderer = GetComponent <SpriteRenderer>(); if (spriteRenderer == null) { Debug.LogError("Can not find SpriteRenderer."); OnlineMapsUtils.Destroy(this); } }
/// <summary> /// Removes all markers /// </summary> public static void RemoveAllMarkers() { foreach (uGUICustomMarkerExample marker in markers) { marker.Dispose(); OnlineMapsUtils.Destroy(marker.gameObject); } markers.Clear(); }
public override void Dispose() { base.Dispose(); if (instance != null) { OnlineMapsUtils.Destroy(instance); } }
protected override void OnEnableLate() { uiWidget = GetComponent <UIWidget>(); uiTexture = GetComponent <UITexture>(); if (uiTexture == null) { Debug.LogError("Can not find UITexture."); OnlineMapsUtils.Destroy(this); } }
private void LateUpdate() { if (marker as OnlineMapsMarker3D == null) { OnlineMapsUtils.Destroy(gameObject); return; } UpdateBaseProps(); }
/// <summary> /// Dispose billboard instance /// </summary> public void Dispose() { if (gameObject != null) { OnlineMapsUtils.Destroy(gameObject); } if (marker != null) { marker.OnInitComplete -= OnInitComplete; } marker = null; }
private void OnTileDisposed(OnlineMapsTile tile) { if (!overlays.ContainsKey(tile.key)) { return; } if (overlays[tile.key] != null) { OnlineMapsUtils.Destroy(overlays[tile.key]); } overlays.Remove(tile.key); }
/// <summary> /// Removes a marker by index /// </summary> /// <param name="index">Index of marker</param> public static void RemoveMarkerAt(int index) { if (index < 0 || index >= markers.Count) { return; } uGUICustomMarkerExample marker = markers[index]; OnlineMapsUtils.Destroy(marker.gameObject); marker.Dispose(); markers.RemoveAt(index); }
protected override void OnEnableLate() { image = GetComponent <T>(); if (image == null) { Debug.LogError("Can not find " + typeof(T)); OnlineMapsUtils.Destroy(this); } #if CURVEDUI curvedUI = image.canvas.GetComponent <CurvedUISettings>(); #endif }
/// <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.Destroy(instance); Init(parent); } Update(tlx, tly, brx, bry, zoom); if (OnInitComplete != null) { OnInitComplete(this); } }
public void RemoveAllMarker3D() { for (int i = 0; i < OnlineMapsMarker3DManager.instance.Count; i++) { OnlineMapsMarker3D marker = OnlineMapsMarker3DManager.instance[i]; if (marker.instance != null) { OnlineMapsUtils.Destroy(marker.instance); } marker.Dispose(); } OnlineMapsMarker3DManager.RemoveAllItems(); }
protected override void Destroy() { base.Destroy(); if (trafficTexture != null) { OnlineMapsUtils.Destroy(trafficTexture); trafficTexture = null; } _colors = null; labelData = null; labelColors = null; OnSetColor = null; }