Beispiel #1
0
        /// <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();
        }
        /// <summary>
        /// Painting on TerrainTypeLayer
        /// </summary>
        /// <param name="position">Brush position</param>
        /// <param name="brushSize"></param>
        /// <param name="layer">Layer index</param>
        private void SymmetryPaint(Vector3 paintPosition, float brushSize, TerrainTypeLayerSettings layer)
        {
            //Paint(positionCenter, brushSize, layer);

            //TODO Symmetry points

            BrushGenerator.Current.GenerateSymmetry(paintPosition);

            for (int i = 0; i < BrushGenerator.Current.PaintPositions.Length; i++)
            {
                Vector2 brushPos2 = GetTypePos(BrushGenerator.Current.PaintPositions[i]);
                brushPos2 = new Vector2(brushPos2.x * 10, TerrainTypeSize.y - brushPos2.y * 10);

                Paint(brushPos2, brushSize, layer);
            }

            TerrainTypeTexture.Apply();
        }
Beispiel #3
0
 private Color[] GetToUndoTex()
 {
     return(TerrainTypeTexture.GetPixels());
 }
Beispiel #4
0
        private void ApplyChanges()
        {
//            Undo.Current.RegisterTerrainTypePaint();
            TerrainTypeTexture.Apply();
            ApplyTerrainTypeChanges();
        }