예제 #1
0
    private GameObject InitGrid(Transform parent)
    {
        GameObject go = new GameObject();

        go.name = "Grid";
        go.transform.SetParent(parent, false);
        go.SetActive(showGrid);

        int width  = source.texture.width + 1;
        int height = source.texture.height + 1;

        // set dots texture
        Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false);

        texture.filterMode = FilterMode.Point;

        DrawUtils.ClearTexture(texture);
        DrawUtils.DrawGrid(texture, tileWidth, tileHeight, new Color(0, 0, 0, 0.1f));

        texture.Apply();

        // create sprite
        SpriteRenderer spriteRenderer = go.AddComponent <SpriteRenderer>();

        spriteRenderer.sortingOrder = 0;

        Sprite sprite = Sprite.Create(texture, new Rect(0, 0, width, height), new Vector2(0f, 1f), 1);

        sprite.name           = "DotsSprite";
        spriteRenderer.sprite = sprite;

        return(go);
    }
예제 #2
0
    private void DrawOverlay(int tileX = -1, int tileY = -1)
    {
        Texture2D texture = overlay.texture;

        DrawUtils.ClearTexture(texture);

        Vector2 coords;
        Color   color;

        // draw edited tiles
        foreach (TileRect tile in tiles)
        {
            color  = new Color(0, 1, 0, 0.3f);
            coords = DrawUtils.GetPixelPosInTexture(source.texture, tile.x, tile.y, tileWidth, tileHeight);
            DrawUtils.DrawSquare(texture, (int)coords.x, (int)coords.y, tileWidth - 1, tileHeight - 1, color, false);
            //DrawUtils.DrawSquare(texture, (int)coords.x, (int)coords.y, tileWidth, tileHeight, color, true);
        }

        // draw selected tile
        if (tileX >= 0 && tileY >= 0)
        {
            color  = new Color(1, 0, 0, 0.4f);
            coords = DrawUtils.GetPixelPosInTexture(source.texture, tileX, tileY, tileWidth, tileHeight);
            DrawUtils.DrawSquare(texture, (int)coords.x, (int)coords.y, tileWidth - 1, tileHeight - 1, color, false);
            //DrawUtils.DrawSquare(texture, (int)coords.x, (int)coords.y, tileWidth, tileHeight, color, true);
        }

        texture.Apply();

        Transform go     = transform.Find("Container/Overlay");
        Sprite    sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0f, 1f), 1);

        go.GetComponent <SpriteRenderer>().sprite = sprite;
    }
예제 #3
0
    private Texture2D DrawTileImage(int tileX, int tileY)
    {
        int width  = tileWidth;
        int height = tileHeight;

        Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false);

        texture.filterMode = FilterMode.Point;

        DrawUtils.ClearTexture(texture);

        Vector2 coords = DrawUtils.GetPixelPosInTexture(source.texture, tileX, tileY, tileWidth, tileHeight);

        Color[] colors = source.texture.GetPixels((int)coords.x, (int)coords.y, tileWidth, tileHeight);
        texture.SetPixels(0, 0, tileWidth, tileHeight, colors);

        texture.Apply();

        // create sprite and update hud image
        Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 1);
        Image  image  = transform.Find("Hud/Header/Tile/TileImage").GetComponent <Image>();

        image.sprite  = sprite;
        image.enabled = true;

        return(texture);
    }
예제 #4
0
    private Sprite InitOverlay(Transform parent)
    {
        GameObject go = new GameObject();

        go.name = "Overlay";
        go.transform.SetParent(parent, false);

        // set overlay texture
        Texture2D texture = new Texture2D(source.texture.width, source.texture.height, TextureFormat.ARGB32, false);

        texture.filterMode = FilterMode.Point;

        DrawUtils.ClearTexture(texture);
        texture.Apply();

        // create sprite
        SpriteRenderer spriteRenderer = go.AddComponent <SpriteRenderer>();

        spriteRenderer.sortingOrder = 2;

        Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0f, 1f), 1);

        sprite.name           = "OverlaySprite";
        spriteRenderer.sprite = sprite;

        return(sprite);
    }