Ejemplo n.º 1
0
    protected override IEnumerator CreateRoutine(Tile tile, Action <bool> finished)
    {
        var go = GameObject.CreatePrimitive(PrimitiveType.Quad).transform;

        go.name = "map";
        go.SetParent(tile.transform, true);
        go.localScale     = new Vector3((float)tile.Rect.Width, (float)tile.Rect.Width, 1);
        go.localRotation  = Quaternion.AngleAxis(90, new Vector3(1, 0, 0));
        go.localPosition  = Vector3.zero;
        go.localPosition -= new Vector3(0, 1, 0);
        var rend = go.GetComponent <Renderer>();

        rend.material            = tile.Material;
        TileProvider.TileService = TileService;
        TileProvider.GetTile(new Vector3d(tile.TileTms.x, tile.TileTms.y, tile.Zoom), (texture) =>
        {
            if (texture)
            {
                if (rend)
                {
                    rend.material.mainTexture = texture;
                    rend.material.color       = new Color(1f, 1f, 1f, 1f);

                    finished(true);
                }
            }
            else
            {
                finished(false);
            }
        });

        yield return(null);
    }
Ejemplo n.º 2
0
    /* -----------------------------
    *  Drawing methods
    *-----------------------------*/

    protected void DrawTiles(Rect area)
    {
        // Download and draw tiles
        var tile = GM.MetersToTile(GM.LatLonToMeters(Center.x, Center.y), Zoom);

        Vector2d topLeftCorner     = GM.PixelsToTile(centerPixel - new Vector2d(area.width / 2f, area.height / 2f)),
                 bottomRightCorner = GM.PixelsToTile(centerPixel + new Vector2d(area.width / 2f, area.height / 2f));

        for (double x = topLeftCorner.x; x <= bottomRightCorner.x; x++)
        {
            for (double y = topLeftCorner.y; y <= bottomRightCorner.y; y++)
            {
                var tp = TileProvider.GetTile(new Vector3d(x, y, Zoom), (texture) => { if (Repaint != null)
                                                                                       {
                                                                                           Repaint();
                                                                                       }
                                              });
                var tileBounds = GM.TileBounds(new Vector2d(x, y), Zoom);
                var tileRect   = ExtensionRect.FromCorners(
                    GM.MetersToPixels(tileBounds.Min, Zoom).ToVector2(),
                    GM.MetersToPixels(tileBounds.Min + tileBounds.Size, Zoom).ToVector2());

                var windowRect = new Rect(tileRect.position + PATR.ToVector2(), tileRect.size);
                var areaRect   = windowRect.Intersection(area);
                if (areaRect.width < 0 || areaRect.height < 0)
                {
                    continue;
                }

                GUI.DrawTextureWithTexCoords(areaRect, tp.Texture, windowRect.ToTexCoords(areaRect));
            }
        }
    }
Ejemplo n.º 3
0
        void CreateAllTiles()
        {
            if (tileProvider != null)
            {
                if (allTilesMeshObj != null)
                {
                    Destroy(allTilesMeshObj);
                }

                int tileX0, tileY0, tileX1, tileY1;
                tileProvider.GetAllTiles(out tileX0, out tileY0, out tileX1, out tileY1);

                allTilesMeshObj = new GameObject("All Tiles Mesh Object");
                allTilesMeshObj.transform.SetParent(transform, false);

                var xcount = tileX1 - tileX0;
                var ycount = tileY1 - tileY0;
                var mesh   = CreateMesh(xcount, ycount, "All Tiles Mesh");
                mesh.hideFlags = HideFlags.None;
                var materials = new Material[xcount * ycount];
                for (int j = 0; j < ycount; ++j)
                {
                    for (int i = 0; i < xcount; ++i)
                    {
                        var index = i + j * xcount;
                        materials[index]      = new Material(material);
                        materials[index].name = material.name + "(Clone)";
                        materials[index].SetTexture(ID_MainTex, tileProvider.GetTile(i, j));
                    }
                }

                var meshRenderer = allTilesMeshObj.AddComponent <MeshRenderer>();
                meshRenderer.sharedMaterials = materials;

                var meshFilter = allTilesMeshObj.AddComponent <MeshFilter>();
                meshFilter.sharedMesh = mesh;
            }
        }
Ejemplo n.º 4
0
    public void SetTileType(Vector2 position, TileType type)
    {
        if (!Tiles.ContainsKey(position))
        {
            Tiles[position] = TileProvider.GetTile(type);
            Tiles[position].transform.parent   = transform;
            Tiles[position].transform.position = GetPositionForCoordinate(position);
            Tiles[position].Position           = position;
            Tiles[position].Height             = baseHeight;
        }
        else
        {
            Tiles[position].Type = type;
            TileProvider.SetTileMaterial(Tiles[position]);
        }

        Tiles[position].name = "Tile [" + position.x + "," + position.y + "] " + type;

        // Check the fields around and create VOID tiles, if needed.
        if (type != TileType.Void)
        {
            foreach (NeighbourIndex idx in Enum.GetValues(typeof(NeighbourIndex)))
            {
                var ypos = GetNeighbourPosition(position, idx);
                if (!Tiles.ContainsKey(ypos))
                {
                    SetTileType(ypos, TileType.Void);
                }
            }
        }

        /*
         * // TODO: Path End, Path Start
         * if (type == TileType.Path)
         * {
         *  if (!Waypoints.ContainsKey(position))
         *  {
         *      Waypoints[position] = Instantiate(Resources.Load<WaypointBehaviour>(waypointPrefabPath));
         *      Waypoints[position].transform.SetParent(Tiles[position].transform);
         *      Waypoints[position].transform.position = Tiles[position].transform.position + new Vector3(0, 4, 0);
         *  }
         * }
         * //*/
        CleanupTilesAroundPosition(position);
    }