예제 #1
0
        private IEnumerator DrawTiles(TileGrid tileGrid)
        {
            Rectangle clippedRenderTiles = tileGrid.GetClippedRenderTiles();
            int       count = 0;

            for (int left = clippedRenderTiles.Left; left < clippedRenderTiles.Right; ++left)
            {
                for (int top = clippedRenderTiles.Top; top < clippedRenderTiles.Bottom; ++top)
                {
                    MTexture mTexture = tileGrid.Tiles[left, top];
                    if (mTexture == null)
                    {
                        continue;
                    }
                    count++;
                    GameObject gb = Instantiate(spritePrefab);
                    gb.transform.SetParent(this.transform, false);
                    gb.GetComponent <SpriteRenderer>().sprite = mTexture.GetSprite();
                    gb.transform.position = new Vector3((float)(left * tileGrid.TileWidth), -(float)(top * tileGrid.TileHeight), 0);
                    //backgroundTiles.Tiles.Tiles[left, top].USprite;
                    //backgroundTiles.Tiles.Tiles[left, top]?.Draw(new Vector2((float)(left * backgroundTiles.Tiles.TileWidth), (float)(top * backgroundTiles.Tiles.TileHeight))), Vector2.zero, color);
                    //Debug.Log(left+","+top);
                    yield return(null);
                }
            }
        }
예제 #2
0
    private IEnumerator DrawTiles(TileGrid tileGrid, Vector3 offset)
    {
        Rectangle clippedRenderTiles = tileGrid.GetClippedRenderTiles();
        int       count = 0;

        for (int left = clippedRenderTiles.Left; left < clippedRenderTiles.Right; ++left)
        {
            for (int top = clippedRenderTiles.Top; top < clippedRenderTiles.Bottom; ++top)
            {
                MTexture mTexture = tileGrid.Tiles[left, top];
                if (mTexture == null)
                {
                    continue;
                }
                mTexture = tileGrid.Tiles[left, top];
                count++;
                GameObject gb = Instantiate(spritePrefab);
                gb.transform.SetParent(this.transform, false);
                gb.GetComponent <SpriteRenderer>().sprite = mTexture.GetSprite();
                gb.transform.position = new Vector3((float)(left * tileGrid.TileWidth) / 100f, -(float)(top * tileGrid.TileHeight) / 100f, 0);
                yield return(null);
            }
        }
    }