/// <summary> /// Gets the tile at position. This can be used to obtain tile data, etc /// -1 = no data or empty tile /// </summary> public Color GetInterpolatedColorAtPosition(Vector3 position) { Vector3 localPosition = transform.worldToLocalMatrix.MultiplyPoint(position); int x = (int)((localPosition.x - data.tileOrigin.x) / data.tileSize.x); int y = (int)((localPosition.y - data.tileOrigin.y) / data.tileSize.y); if (colorChannel == null || colorChannel.IsEmpty) { return(Color.white); } if (x < 0 || x >= width || y < 0 || y >= height) { return(colorChannel.clearColor); } int offset; ColorChunk colorChunk = colorChannel.FindChunkAndCoordinate(x, y, out offset); if (colorChunk.Empty) { return(colorChannel.clearColor); } else { int colorChunkRowOffset = partitionSizeX + 1; Color tileColorx0y0 = colorChunk.colors[offset]; Color tileColorx1y0 = colorChunk.colors[offset + 1]; Color tileColorx0y1 = colorChunk.colors[offset + colorChunkRowOffset]; Color tileColorx1y1 = colorChunk.colors[offset + colorChunkRowOffset + 1]; float wx = x * data.tileSize.x + data.tileOrigin.x; float wy = y * data.tileSize.y + data.tileOrigin.y; float ix = (localPosition.x - wx) / data.tileSize.x; float iy = (localPosition.y - wy) / data.tileSize.y; Color cy0 = Color.Lerp(tileColorx0y0, tileColorx1y0, ix); Color cy1 = Color.Lerp(tileColorx0y1, tileColorx1y1, ix); return(Color.Lerp(cy0, cy1, iy)); } }
void Optimize(ColorChunk chunk) { bool empty = true; Color32 clearColor32 = this.clearColor; foreach (var c in chunk.colors) { if (c.r != clearColor32.r || c.g != clearColor32.g || c.b != clearColor32.b || c.a != clearColor32.a) { empty = false; break; } } if (empty) { chunk.colors = new Color32[0]; } }
void Optimize(ColorChunk chunk) { bool empty = true; Color32 clearColor32 = this.clearColor; foreach (var c in chunk.colors) { if (c.r != clearColor32.r || c.g != clearColor32.g || c.b != clearColor32.b || c.a != clearColor32.a) { empty = false; break; } } if (empty) chunk.colors = new Color32[0]; }
public void Create() { chunks = new ColorChunk[numColumns * numRows]; for (int i = 0; i < chunks.Length; ++i) chunks[i] = new ColorChunk(); }
public void ClearChunk(ColorChunk chunk) { for (int i = 0; i < chunk.colors.Length; ++i) chunk.colors[i] = clearColor; }
// create chunk if it doesn't already exist void InitChunk(ColorChunk chunk) { if (chunk.colors.Length == 0) { chunk.colors = new Color32[(divX + 1) * (divY + 1)]; for (int i = 0; i < chunk.colors.Length; ++i) chunk.colors[i] = clearColor; } }