Пример #1
0
    public void FillTile(int x, int y, materialType toMat)
    {
        int fromMat = GetTileType(x, y);

        if (fromMat == (int)toMat)
        {
            return;
        }

        UpdateTile(x, y, toMat);

        StartCoroutine(FillLoop(x, y, (int)toMat, fromMat));
    }
Пример #2
0
    public void UpdateTile(int x, int y, materialType mat, bool lazy = false)
    {
        GameObject plot = getPlotTransform(x, y);

        if (!plot)
        {
            return;
        }

        Texture2D tex = plot.GetComponent <Renderer>().material.mainTexture as Texture2D;

        int tx = x % plotWidth;
        int ty = y % plotHeight;

        if (tx == 0)
        {
            tx = plotWidth;
        }
        if (ty == 0)
        {
            ty = plotHeight;
        }

        //Division and mod don't work with 0 index, so we were sent 1 index, now let's fix that.

        //We have to invert y for visual looks. the formula for ty below also properly moves it to 0 index.
        ty = -ty + plotHeight;
        tx--;

        //Texturesize info, getting starting points
        tx *= imageSize;
        ty *= imageSize;
        tex.SetPixels(tx, ty, imageSize, imageSize, colorsPreCalc[(int)mat]);

        if (!lazy)
        {
            tex.Apply();
        }

        //Again, working from 1 index back to 0 index.
        y--;
        x--;

        SaveFile.current.Tiles.TileTypes[(y) * SaveFile.current.Tiles.TilesWide + x] = (int)mat;
    }