public void ApplyTerrainChange(Vector2Int[] positions, Color[] colors) { Debug.Log("apply"); for (int i = 0; i < positions.Length; i++) { texture.SetPixel(positions[i].x, positions[i].y, colors[i]); terrainChanges.Remove(positions[i]); } texture.Apply(); TerrainQuadTree.Instance.UpdateTerrainTexture(this); // Find neighbors of positions and combine the colors List <Vector2Int> parentPositions = new List <Vector2Int>(); List <Color> combinedColors = new List <Color>(); for (int i = 0; i < positions.Length; i++) { string lastChar = id.Substring(id.Length - 1); Vector2Int basePos = new Vector2Int(Mathf.FloorToInt(positions[i].x / 2) * 2, Mathf.FloorToInt(positions[i].y / 2) * 2); Color combinedColor = (texture.GetPixel(basePos.x, basePos.y) + texture.GetPixel(basePos.x + 1, basePos.y) + texture.GetPixel(basePos.x, basePos.y + 1) + texture.GetPixel(basePos.x + 1, basePos.y + 1)) / 4; Vector2Int basePosOffset = new Vector2Int(lastChar == "1" || lastChar == "3" ? textureSize : 0, lastChar == "2" || lastChar == "3" ? textureSize : 0); basePos.x += basePosOffset.x; basePos.y += basePosOffset.y; Vector2Int parentPosition = new Vector2Int(basePos.x / 2, basePos.y / 2); if (!parentPositions.Contains(parentPosition)) { parentPositions.Add(parentPosition); combinedColors.Add(combinedColor); } } parent.ApplyTerrainChangeRecursive(parentPositions, combinedColors); }