/// <summary> /// Gets a tile by its URL, the main texture of the material is assigned if successful. /// </summary> /// <param name="url">URL.</param> /// <param name="tile">Tile.</param> public void Get(string url, TileBehaviour tile) { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Get: url: " + url); #endif tileURLLookedFor = url; if (tilesToLoad.Exists(tileURLMatchPredicate)) { #if DEBUG_LOG Debug.LogWarning("WARNING: TileDownloader.Get: already asked for url: " + url); #endif return; } if (tilesLoading.Exists(tileURLMatchPredicate)) { #if DEBUG_LOG Debug.LogWarning("WARNING: TileDownloader.Get: already downloading url: " + url); #endif return; } #if !UNITY_WEBPLAYER TileEntry cachedEntry = tiles.Find(tileURLMatchPredicate); if (cachedEntry == null) #endif { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Get: adding '" + url + "' to loading list"); #endif tilesToLoad.Add(new TileEntry(url, tile)); } #if !UNITY_WEBPLAYER else { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Get: adding '" + url + "' to loading list (cached)"); #endif cachedEntry.cached = true; cachedEntry.tile = tile; //cachedEntry.Complete = material; tilesToLoad.Add(cachedEntry); } #endif }
public static TileBehaviour CreateTileTemplate(string tileName) { GameObject tileTemplate = new GameObject(tileName); TileBehaviour tile = tileTemplate.AddComponent <TileBehaviour>(); MeshFilter meshFilter = tileTemplate.AddComponent <MeshFilter>(); MeshRenderer meshRenderer = tileTemplate.AddComponent <MeshRenderer>(); BoxCollider boxCollider = tileTemplate.AddComponent <BoxCollider>(); // add the geometry Mesh mesh = meshFilter.mesh; mesh.vertices = new Vector3[] { new Vector3(0.5f, 0.0f, 0.5f), new Vector3(0.5f, 0.0f, -0.5f), new Vector3(-0.5f, 0.0f, -0.5f), new Vector3(-0.5f, 0.0f, 0.5f) }; mesh.triangles = new int[] { 0, 1, 2, 0, 2, 3 }; // add normals mesh.normals = new Vector3[] { Vector3.up, Vector3.up, Vector3.up, Vector3.up }; // add uv coordinates mesh.uv = new Vector2[] { new Vector2(1.0f, 1.0f), new Vector2(1.0f, 0.0f), new Vector2(0.0f, 0.0f), new Vector2(0.0f, 1.0f) }; // add a material string shaderName = "Larku/UnlitTransparent"; Shader shader = Shader.Find(shaderName); tile.material = meshRenderer.material = new Material(shader); // setup the collider boxCollider.size = new Vector3(1.0f, 0.0f, 1.0f); return(tile); }
/// <summary> /// Gets a tile by its URL, the main texture of the material is assigned if successful. /// </summary> /// <param name="url">URL.</param> /// <param name="tile">Tile.</param> public void Get(int x, int y, int zoom, string url, TileBehaviour tile) { if (tilesToLoad.Exists(t => t.url == url) || tilesLoading.Exists(t => t.url == url)) { return; } TileEntry cachedEntry = tiles.Find(t => t.url == url); if (cachedEntry == null) { tilesToLoad.Add(new TileEntry(x, y, zoom, url, tile)); } else { cachedEntry.tile = tile; tilesToLoad.Add(cachedEntry); } }
/// <summary> /// Requests the tile's texture and assign it. /// </summary> /// <param name="tileX">Tile x.</param> /// <param name="tileY">Tile y.</param> /// <param name="roundedZoom">Rounded zoom.</param> /// <param name="tile">Tile.</param> protected override void RequestTile (int tileX, int tileY, int roundedZoom, TileBehaviour tile) { if (db == null) { throw new NullReferenceException ("db"); } DataTable dt = db.ExecuteQuery ("SELECT tile_data FROM tiles WHERE zoom_level=" + roundedZoom + " AND tile_column=" + tileX + " AND tile_row=" + tileY); if (dt.Rows.Count == 0) { #if DEBUG_LOG Debug.LogWarning("WARNING: no rows in MBTiles db for tile: " + tileX + "," + tileY + "," + roundedZoom); #endif return; } Texture2D tex = new Texture2D ((int)Map.TileResolution, (int)Map.TileResolution); if (tex.LoadImage ((byte[])dt.Rows [0] ["tile_data"])) tile.SetTexture (tex); else { #if DEBUG_LOG Debug.LogError("ERROR: MBTilesLayer.RequestTile: couldn't load image for: " + tileX + "," + tileY + "," + roundedZoom); #endif } }
/// <summary> /// Requests the tile's texture and assign it. See <see cref="UnitySlippyMap.Layers.TileLayerBehaviour.RequestTile"/>. /// </summary> /// <param name="tileX">Tile x.</param> /// <param name="tileY">Tile y.</param> /// <param name="roundedZoom">Rounded zoom.</param> /// <param name="tile">Tile.</param> protected override void RequestTile (int tileX, int tileY, int roundedZoom, TileBehaviour tile) { TileDownloaderBehaviour.Instance.Get (GetTileURL (tileX, tileY, roundedZoom), tile); }
/// <summary> /// Creates a tile template GameObject. /// </summary> /// <returns>The tile template.</returns> /// <param name="tileName">Tile name.</param> /// <param name="anchorPoint">Anchor point.</param> public static TileBehaviour CreateTileTemplate(string tileName, AnchorPoint anchorPoint) { GameObject tileTemplate = new GameObject(tileName); TileBehaviour tile = tileTemplate.AddComponent <TileBehaviour> (); MeshFilter meshFilter = tileTemplate.AddComponent <MeshFilter> (); MeshRenderer meshRenderer = tileTemplate.AddComponent <MeshRenderer> (); BoxCollider boxCollider = tileTemplate.AddComponent <BoxCollider> (); // add the geometry Mesh mesh = meshFilter.mesh; switch (anchorPoint) { case AnchorPoint.TopLeft: mesh.vertices = new Vector3[] { new Vector3(1.0f, 0.0f, 0.0f), new Vector3(1.0f, 0.0f, -1.0f), new Vector3(0.0f, 0.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f) }; break; case AnchorPoint.TopCenter: mesh.vertices = new Vector3[] { new Vector3(0.5f, 0.0f, 0.0f), new Vector3(0.5f, 0.0f, -1.0f), new Vector3(-0.5f, 0.0f, -1.0f), new Vector3(-0.5f, 0.0f, 0.0f) }; break; case AnchorPoint.TopRight: mesh.vertices = new Vector3[] { new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, -1.0f), new Vector3(-1.0f, 0.0f, -1.0f), new Vector3(-1.0f, 0.0f, 0.0f) }; break; case AnchorPoint.MiddleLeft: mesh.vertices = new Vector3[] { new Vector3(1.0f, 0.0f, 0.5f), new Vector3(1.0f, 0.0f, -0.5f), new Vector3(0.0f, 0.0f, -0.5f), new Vector3(0.0f, 0.0f, 0.5f) }; break; case AnchorPoint.MiddleRight: mesh.vertices = new Vector3[] { new Vector3(0.0f, 0.0f, 0.5f), new Vector3(0.0f, 0.0f, -0.5f), new Vector3(-1.0f, 0.0f, -0.5f), new Vector3(-1.0f, 0.0f, 0.5f) }; break; case AnchorPoint.BottomLeft: mesh.vertices = new Vector3[] { new Vector3(1.0f, 0.0f, 1.0f), new Vector3(1.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f) }; break; case AnchorPoint.BottomCenter: mesh.vertices = new Vector3[] { new Vector3(0.5f, 0.0f, 1.0f), new Vector3(0.5f, 0.0f, 0.0f), new Vector3(-0.5f, 0.0f, 0.0f), new Vector3(-0.5f, 0.0f, 1.0f) }; break; case AnchorPoint.BottomRight: mesh.vertices = new Vector3[] { new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(-1.0f, 0.0f, 0.0f), new Vector3(-1.0f, 0.0f, 1.0f) }; break; default: // MiddleCenter mesh.vertices = new Vector3[] { new Vector3(0.5f, 0.0f, 0.5f), new Vector3(0.5f, 0.0f, -0.5f), new Vector3(-0.5f, 0.0f, -0.5f), new Vector3(-0.5f, 0.0f, 0.5f) }; break; } mesh.triangles = new int[] { 0, 1, 2, 0, 2, 3 }; // add normals mesh.normals = new Vector3[] { Vector3.up, Vector3.up, Vector3.up, Vector3.up }; // add uv coordinates mesh.uv = new Vector2[] { new Vector2(1.0f, 1.0f), new Vector2(1.0f, 0.0f), new Vector2(0.0f, 0.0f), new Vector2(0.0f, 1.0f) }; // add a material string shaderName = "Somian/Unlit/Transparent"; Shader shader = Shader.Find(shaderName); #if DEBUG_LOG Debug.Log("DEBUG: shader for tile template: " + shaderName + ", exists: " + (shader != null)); #endif tile.material = meshRenderer.material = new Material(shader); // setup the collider boxCollider.size = new Vector3(1.0f, 0.0f, 1.0f); return(tile); }
/// <summary> /// Initializes a new instance of the <see cref="UnitySlippyMap.Map.TileDownloader+TileEntry"/> class. /// </summary> /// <param name="url">URL.</param> /// <param name="tile">Tile.</param> public TileEntry(int x, int y, int zoom, string url, TileBehaviour tile) : this(x, y, zoom, url) { this.tile = tile; }
/// <summary> /// Requests the tile's texture and assign it. /// </summary> /// <param name='tileX'> /// Tile x. /// </param> /// <param name='tileY'> /// Tile y. /// </param> /// <param name='roundedZoom'> /// Rounded zoom. /// </param> /// <param name='tile'> /// Tile. /// </param> protected abstract void RequestTile (int tileX, int tileY, int roundedZoom, TileBehaviour tile);
/// <summary> /// Implementation of <see cref="http://docs.unity3d.com/ScriptReference/MonoBehaviour.html">MonoBehaviour</see>.Awake(). /// </summary> protected void Awake () { // create the tile template if needed if (tileTemplate == null) { tileTemplate = TileBehaviour.CreateTileTemplate (); tileTemplate.hideFlags = HideFlags.HideAndDontSave; tileTemplate.renderer.enabled = false; } ++tileTemplateUseCount; }
/// <summary> /// Gets a tile by its URL, the main texture of the material is assigned if successful. /// </summary> /// <param name="url">URL.</param> /// <param name="tile">Tile.</param> public void Get(string url, TileBehaviour tile) { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Get: url: " + url); #endif tileURLLookedFor = url; if (tilesToLoad.Exists(tileURLMatchPredicate)) { #if DEBUG_LOG Debug.LogWarning("WARNING: TileDownloader.Get: already asked for url: " + url); #endif return ; } if (tilesLoading.Exists(tileURLMatchPredicate)) { #if DEBUG_LOG Debug.LogWarning("WARNING: TileDownloader.Get: already downloading url: " + url); #endif return ; } #if !UNITY_WEBPLAYER TileEntry cachedEntry = tiles.Find(tileURLMatchPredicate); if (cachedEntry == null) #endif { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Get: adding '" + url + "' to loading list"); #endif tilesToLoad.Add(new TileEntry(url, tile)); } #if !UNITY_WEBPLAYER else { #if DEBUG_LOG Debug.Log("DEBUG: TileDownloader.Get: adding '" + url + "' to loading list (cached)"); #endif cachedEntry.cached = true; cachedEntry.tile = tile; //cachedEntry.Complete = material; tilesToLoad.Add(cachedEntry); } #endif }
/// <summary> /// Initializes a new instance of the <see cref="UnitySlippyMap.Map.TileDownloader+TileEntry"/> class. /// </summary> /// <param name="url">URL.</param> /// <param name="tile">Tile.</param> public TileEntry(string url, TileBehaviour tile) { this.url = url; if (tile == null) throw new ArgumentNullException("tile"); this.tile = tile; this.jobCompleteHandler = new Job.JobCompleteHandler(TileDownloaderBehaviour.Instance.JobTerminationEvent); }