/// <summary> /// Painting on TerrainTypeLayer /// </summary> /// <param name="position">Brush position</param> /// <param name="brushSize"></param> /// <param name="layer">Layer index</param> private void Paint(Vector2 positionCenter, float brushSize, TerrainTypeLayerSettings layer) { Rect rect = Rect.MinMaxRect( positionCenter.x - brushSize, positionCenter.y - brushSize, positionCenter.x + brushSize, positionCenter.y + brushSize ); // if (RectUtils.IsCrossed(new Rect(Vector2.zero, TerrainTypeSize), rect)) // { var crossRect = RectUtils.Cross(new Rect(Vector2.zero, TerrainTypeSize), rect); int size = (int)brushSize; // Vector2 positionCenterLocal = positionCenter - crossRect.position; // Vector2 positionCenterLocal = positionCenter - crossRect.position; TerrainTypeTexture.SetPixels( Mathf.RoundToInt(crossRect.x), Mathf.RoundToInt(crossRect.y), Mathf.RoundToInt(crossRect.width), Mathf.RoundToInt(crossRect.height), TerrainTypeTexture.GetPixels( Mathf.RoundToInt(crossRect.x), Mathf.RoundToInt(crossRect.y), Mathf.RoundToInt(crossRect.width), Mathf.RoundToInt(crossRect.height)) .Select((color, i) => { int x = i % Mathf.RoundToInt(crossRect.width) + Mathf.RoundToInt(crossRect.xMin) - Mathf.RoundToInt(positionCenter.x); int y = i / Mathf.RoundToInt(crossRect.width) + Mathf.RoundToInt(crossRect.yMin) - Mathf.RoundToInt(positionCenter.y); return((x * x + y * y > size * size) ? color : layer.color); } ) .ToArray() ); for (int j = (int)crossRect.yMin; j < (int)crossRect.yMax; j++) { for (int i = (int)crossRect.xMin; i < (int)crossRect.xMax; i++) { int x = (int)(i - positionCenter.x); int y = (int)(j - positionCenter.y); if (x * x + y * y <= size * size) { TerrainTypeData2D[i, j] = layer.index; } } } TerrainTypeTexture.Apply(); }
private Color[] GetToUndoTex() { return(TerrainTypeTexture.GetPixels()); }