public static PaintContext.TerrainTile Make(Terrain terrain, int tileOriginPixelsX, int tileOriginPixelsY, RectInt pixelRect, int targetTextureWidth, int targetTextureHeight) { PaintContext.TerrainTile terrainTile = new PaintContext.TerrainTile { terrain = terrain, gatherEnable = true, scatterEnable = true, tileOriginPixels = new Vector2Int(tileOriginPixelsX, tileOriginPixelsY), clippedTerrainPixels = new RectInt { x = Mathf.Max(0, pixelRect.x - tileOriginPixelsX), y = Mathf.Max(0, pixelRect.y - tileOriginPixelsY), xMax = Mathf.Min(targetTextureWidth, pixelRect.xMax - tileOriginPixelsX), yMax = Mathf.Min(targetTextureHeight, pixelRect.yMax - tileOriginPixelsY) } }; terrainTile.clippedPCPixels = new RectInt(terrainTile.clippedTerrainPixels.x + terrainTile.tileOriginPixels.x - pixelRect.x, terrainTile.clippedTerrainPixels.y + terrainTile.tileOriginPixels.y - pixelRect.y, terrainTile.clippedTerrainPixels.width, terrainTile.clippedTerrainPixels.height); bool flag = terrainTile.clippedTerrainPixels.width == 0 || terrainTile.clippedTerrainPixels.height == 0; if (flag) { terrainTile.gatherEnable = false; terrainTile.scatterEnable = false; UnityEngine.Debug.LogError("PaintContext.ClipTerrainTiles found 0 content rect"); } return(terrainTile); }
private static void OnTerrainPainted(PaintContext.TerrainTile tile, ToolAction action) { for (int i = 0; i < s_PaintedTerrain.Count; ++i) { if (tile.terrain == s_PaintedTerrain[i].terrain) { s_PaintedTerrain[i].action |= action; return; } } s_PaintedTerrain.Add(new PaintedTerrain { terrain = tile.terrain, action = action }); }
internal void FindTerrainTiles() { m_TerrainTiles = new List <PaintContext.TerrainTile>(); Terrain left = originTerrain.leftNeighbor; Terrain right = originTerrain.rightNeighbor; Terrain top = originTerrain.topNeighbor; Terrain bottom = originTerrain.bottomNeighbor; bool wantLeft = (pixelRect.x < 0); bool wantRight = (pixelRect.xMax > (targetTextureWidth - 1)); bool wantTop = (pixelRect.yMax > (targetTextureHeight - 1)); bool wantBottom = (pixelRect.y < 0); if (wantLeft && wantRight) { Debug.LogWarning("PaintContext pixelRect is too large! It should touch a maximum of 2 Terrains horizontally."); wantRight = false; } if (wantTop && wantBottom) { Debug.LogWarning("PaintContext pixelRect is too large! It should touch a maximum of 2 Terrains vertically."); wantBottom = false; } // add center tile TerrainTile tile = new TerrainTile(originTerrain, 0, 0); m_TerrainTiles.Add(tile); // add horizontal and vertical neighbors Terrain horiz = null; Terrain vert = null; Terrain cornerTerrain = null; int horizTileDelta = 0; // how many tiles to move horizontally int vertTileDelta = 0; // how many tiles to move vertically if (wantLeft) { horizTileDelta = -1; horiz = left; } else if (wantRight) { horizTileDelta = 1; horiz = right; } if (wantTop) { vertTileDelta = 1; vert = top; } else if (wantBottom) { vertTileDelta = -1; vert = bottom; } if (horiz) { tile = new TerrainTile(horiz, horizTileDelta * (targetTextureWidth - 1), 0); m_TerrainTiles.Add(tile); // add corner, if we have a link if (wantTop && horiz.topNeighbor) { cornerTerrain = horiz.topNeighbor; } else if (wantBottom && horiz.bottomNeighbor) { cornerTerrain = horiz.bottomNeighbor; } } if (vert) { tile = new PaintContext.TerrainTile(vert, 0, vertTileDelta * (targetTextureHeight - 1)); m_TerrainTiles.Add(tile); // add corner, if we have a link if (wantLeft && vert.leftNeighbor) { cornerTerrain = vert.leftNeighbor; } else if (wantRight && vert.rightNeighbor) { cornerTerrain = vert.rightNeighbor; } } if (cornerTerrain != null) { tile = new TerrainTile(cornerTerrain, horizTileDelta * (targetTextureWidth - 1), vertTileDelta * (targetTextureHeight - 1)); m_TerrainTiles.Add(tile); } }
internal void FindTerrainTiles() { m_TerrainTiles = new List <PaintContext.TerrainTile>(); Terrain left = originTerrain.leftNeighbor; Terrain right = originTerrain.rightNeighbor; Terrain top = originTerrain.topNeighbor; Terrain bottom = originTerrain.bottomNeighbor; bool wantLeft = (pixelRect.x < 0); bool wantRight = (pixelRect.xMax > (targetTextureWidth - 1)); bool wantTop = (pixelRect.yMax > (targetTextureHeight - 1)); bool wantBottom = (pixelRect.y < 0); if (wantLeft && wantRight) { Debug.LogWarning("PaintContext pixelRect is too large! It should touch a maximum of 2 Terrains horizontally."); wantRight = false; } if (wantTop && wantBottom) { Debug.LogWarning("PaintContext pixelRect is too large! It should touch a maximum of 2 Terrains vertically."); wantBottom = false; } // add center tile TerrainTile tile = new TerrainTile(originTerrain, new RectInt(0, 0, targetTextureWidth, targetTextureHeight)); tile.readOffset = Vector2Int.zero; tile.writeOffset = Vector2Int.zero; m_TerrainTiles.Add(tile); // add horizontal and vertical neighbors Terrain horiz = null; Terrain vert = null; Terrain cornerTerrain = null; int xBias = 0; int yBias = 0; int xReadBias = 0; int yReadBias = 0; int xWriteBias = 0; int yWriteBias = 0; if (wantLeft) { xBias = -1; xReadBias = -1; xWriteBias = 1; horiz = left; } else if (wantRight) { xBias = 1; xReadBias = 1; xWriteBias = -1; horiz = right; } if (wantTop) { yBias = 1; yReadBias = 1; yWriteBias = -1; vert = top; } else if (wantBottom) { yBias = -1; yReadBias = -1; yWriteBias = 1; vert = bottom; } if (horiz) { tile = new TerrainTile(horiz, new RectInt(xBias * targetTextureWidth, 0, targetTextureWidth, targetTextureHeight)); tile.readOffset = new Vector2Int(xReadBias, 0); tile.writeOffset = new Vector2Int(xWriteBias, 0); m_TerrainTiles.Add(tile); // add corner, if we have a link if (wantTop && horiz.topNeighbor) { cornerTerrain = horiz.topNeighbor; } else if (wantBottom && horiz.bottomNeighbor) { cornerTerrain = horiz.bottomNeighbor; } } if (vert) { tile = new PaintContext.TerrainTile(vert, new RectInt(0, yBias * targetTextureHeight, targetTextureWidth, targetTextureHeight)); tile.readOffset = new Vector2Int(0, yReadBias); tile.writeOffset = new Vector2Int(0, yWriteBias); m_TerrainTiles.Add(tile); // add corner, if we have a link if (wantLeft && vert.leftNeighbor) { cornerTerrain = vert.leftNeighbor; } else if (wantRight && vert.rightNeighbor) { cornerTerrain = vert.rightNeighbor; } } if (cornerTerrain != null) { tile = new TerrainTile(cornerTerrain, new RectInt(xBias * targetTextureWidth, yBias * targetTextureHeight, targetTextureWidth, targetTextureHeight)); tile.readOffset = new Vector2Int(xReadBias, yReadBias); tile.writeOffset = new Vector2Int(xWriteBias, yWriteBias); m_TerrainTiles.Add(tile); } }