Added Feel plugin

This commit is contained in:
journaliciouz
2025-12-11 14:49:16 +01:00
parent 97dce4aaf6
commit 1942a531d4
2820 changed files with 257786 additions and 9 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 09b33ad49e4509b4b8d32960e6a7b347
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,289 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
namespace MoreMountains.Tools
{
public class MMGridGenerator
{
/// <summary>
/// Prepares the grid array for use in the generate methods
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
public static int[,] PrepareGrid(ref int width, ref int height)
{
int[,] grid = new int[width, height];
return grid;
}
/// <summary>
/// Carves or adds to the grid
/// </summary>
/// <param name="grid"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool SetGridCoordinate(int[,] grid, int x, int y, int value)
{
if (
(x >= 0)
&& (x <= grid.GetUpperBound(0))
&& (y >= 0)
&& (y <= grid.GetUpperBound(1))
)
{
grid[x, y] = value;
return true;
}
else
{
return false;
}
}
#if MM_PHYSICS2D
/// <summary>
/// Converts a tilemap's contents into a grid
/// </summary>
/// <param name="tilemap"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
public static int[,] TilemapToGrid(Tilemap tilemap, int width, int height)
{
if(tilemap == null)
{
Debug.LogError("[MMGridGenerator] You're trying to convert a tilemap into a grid but didn't specify what tilemap to convert.");
return null;
}
int[,] grid = new int[width, height];
Vector3Int currentPosition = Vector3Int.zero;
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
currentPosition.x = i;
currentPosition.y = j;
currentPosition += MMTilemapGridRenderer.ComputeOffset(width-1, height-1);
grid[i, j] = (tilemap.GetTile(currentPosition) == null) ? 0 : 1;
}
}
return grid;
}
#endif
/// <summary>
/// Outputs the contents of a grid
/// </summary>
/// <param name="grid"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public static void DebugGrid(int[,] grid, int width, int height)
{
string output = "";
for (int j = height-1; j >= 0; j--)
{
output += "line "+j+" [";
for (int i = 0; i < width; i++)
{
output += grid[i, j];
if (i < width - 1)
{
output += ", ";
}
}
output += "]\n";
}
MMDebug.DebugLogInfo(output);
}
/// <summary>
/// Returns the int value at the specified coordinate on a grid
/// </summary>
/// <param name="grid"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="errorValue"></param>
/// <returns></returns>
public static int GetValueAtGridCoordinate(int[,] grid, int x, int y, int errorValue)
{
if (
(x >= 0)
&& (x <= grid.GetUpperBound(0))
&& (y >= 0)
&& (y <= grid.GetUpperBound(1))
)
{
return grid[x, y];
}
else
{
return errorValue;
}
}
/// <summary>
/// Inverts the contents of a grid (1 becomes 0, 0 becomes 1)
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
public static int[,] InvertGrid(int[,] grid)
{
for (int i = 0; i <= grid.GetUpperBound(0); i++)
{
for (int j = 0; j <= grid.GetUpperBound(1); j++)
{
grid[i, j] = grid[i, j] == 0 ? 1 : 0;
}
}
return grid;
}
/// <summary>
/// Smoothens a grid to get rid of spikes / isolated points
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
public static int[,] SmoothenGrid(int[,] grid)
{
int width = grid.GetUpperBound(0);
int height = grid.GetUpperBound(1);
for (int i = 0; i <= width; i ++)
{
for (int j = 0; j <= height; j ++)
{
int adjacentWallsCount = GetAdjacentWallsCount(grid, i , j);
if (adjacentWallsCount > 4)
{
grid[i,j] = 1;
}
else if (adjacentWallsCount < 4)
{
grid[i,j] = 0;
}
}
}
return grid;
}
#if MM_PHYSICS2D
/// <summary>
/// Carves "safe spots" with 0s into the specfied grid
/// </summary>
/// <param name="grid"></param>
/// <param name="layer"></param>
/// <returns></returns>
public static int[,] ApplySafeSpots(int[,] grid, List<MMTilemapGeneratorLayer.MMTilemapGeneratorLayerSafeSpot> safeSpots)
{
foreach (MMTilemapGeneratorLayer.MMTilemapGeneratorLayerSafeSpot safeSpot in safeSpots)
{
int minX = Mathf.Min(safeSpot.Start.x, safeSpot.End.x);
int maxX = Mathf.Max(safeSpot.Start.x, safeSpot.End.x);
int minY = Mathf.Min(safeSpot.Start.y, safeSpot.End.y);
int maxY = Mathf.Max(safeSpot.Start.y, safeSpot.End.y);
for (int i = minX; i < maxX; i++)
{
for (int j = minY; j < maxY; j++)
{
SetGridCoordinate(grid, i, j, 0);
}
}
}
return grid;
}
#endif
/// <summary>
/// Adds bounds (walls made of 1) to a grid, on the selected sides
/// </summary>
/// <param name="grid"></param>
/// <param name="top"></param>
/// <param name="bottom"></param>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static int[,] BindGrid(int[,] grid, bool top, bool bottom, bool left, bool right)
{
int width = grid.GetUpperBound(0);
int height = grid.GetUpperBound(1);
if (top)
{
for (int i = 0; i <= width; i++)
{
grid[i, height] = 1;
}
}
if (bottom)
{
for (int i = 0; i <= width; i++)
{
grid[i, 0] = 1;
}
}
if (left)
{
for (int j = 0; j <= height; j++)
{
grid[0, j] = 1;
}
}
if (right)
{
for (int j = 0; j <= height; j++)
{
grid[width, j] = 1;
}
}
return grid;
}
/// <summary>
/// Returns the amount of adjacent walls for a specific coordinate
/// </summary>
/// <param name="grid"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public static int GetAdjacentWallsCount(int[,] grid, int x, int y)
{
int width = grid.GetUpperBound(0);
int height = grid.GetUpperBound(1);
int wallCount = 0;
for (int i = x - 1; i <= x + 1; i ++)
{
for (int j = y - 1; j <= y + 1; j ++)
{
if ((i >= 0) && (i <= width) && (j >= 0) && (j <= height))
{
if ((i != x) || (j != y))
{
wallCount += grid[i,j];
}
}
else
{
wallCount ++;
}
}
}
return wallCount;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8a5db094ce3821d44a8a41a4cb7d45cc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMGridGenerators/MMGridGenerator.cs
uploadId: 830868

View File

@@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Generates a grid of the specified size, either entirely full or empty
/// </summary>
public class MMGridGeneratorFull : MMGridGenerator
{
/// <summary>
/// Generates a grid of the specified size, either entirely full or empty
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="full"></param>
/// <returns></returns>
public static int[,] Generate(int width, int height, bool full)
{
int[,] grid = PrepareGrid(ref width, ref height);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
SetGridCoordinate(grid, i, j, full ? 1 : 0);
}
}
return grid;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: fa40f7f3424f6fb41b91e1888ad1d960
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMGridGenerators/MMGridGeneratorFull.cs
uploadId: 830868

View File

@@ -0,0 +1,170 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
namespace MoreMountains.Tools
{
/// <summary>
/// Generates a grid with a path in the specified direction
/// </summary>
public class MMGridGeneratorPath : MMGridGenerator
{
public enum Directions { TopToBottom, BottomToTop, LeftToRight, RightToLeft }
/// <summary>
/// Generates a grid with a path in the specified direction
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="seed"></param>
/// <param name="direction"></param>
/// <param name="startPosition"></param>
/// <param name="pathMinWidth"></param>
/// <param name="pathMaxWidth"></param>
/// <param name="directionChangeDistance"></param>
/// <param name="widthChangePercentage"></param>
/// <param name="directionChangePercentage"></param>
/// <returns></returns>
public static int[,] Generate(int width, int height, int seed, Directions direction, Vector2Int startPosition, int pathMinWidth, int pathMaxWidth, int directionChangeDistance, int widthChangePercentage, int directionChangePercentage)
{
int[,] grid = PrepareGrid(ref width, ref height);
grid = MMGridGeneratorFull.Generate(width, height, true);
System.Random random = new System.Random(seed);
Random.InitState(seed);
int pathWidth = 1;
int initialX = startPosition.x;
int initialY = startPosition.y;
SetGridCoordinate(grid, initialX, initialY, 0);
switch (direction)
{
case Directions.TopToBottom:
int x1 = initialX;
for (int i = -pathWidth; i <= pathWidth; i++)
{
SetGridCoordinate(grid, x1 + i, initialY, 0);
}
for (int y = initialY; y > 0; y--)
{
pathWidth = ComputeWidth(random, widthChangePercentage, pathMinWidth, pathMaxWidth, pathWidth);
x1 = DetermineNextStep(random, x1, directionChangeDistance, directionChangePercentage, pathMaxWidth, width);
for (int i = -pathWidth; i <= pathWidth; i++)
{
SetGridCoordinate(grid, x1 + i, y, 0);
}
}
break;
case Directions.BottomToTop:
int x2 = initialX;
for (int i = -pathWidth; i <= pathWidth; i++)
{
SetGridCoordinate(grid, x2 + i, initialY, 0);
}
for (int y = initialY; y < height; y++)
{
pathWidth = ComputeWidth(random, widthChangePercentage, pathMinWidth, pathMaxWidth, pathWidth);
x2 = DetermineNextStep(random, x2, directionChangeDistance, directionChangePercentage, pathMaxWidth, width);
for (int i = -pathWidth; i <= pathWidth; i++)
{
SetGridCoordinate(grid, x2 + i, y, 0);
}
}
break;
case Directions.LeftToRight:
int y1 = initialY;
for (int i = -pathWidth; i <= pathWidth; i++)
{
SetGridCoordinate(grid, initialX, y1 + i, 0);
}
for (int x = initialX; x < width; x++)
{
pathWidth = ComputeWidth(random, widthChangePercentage, pathMinWidth, pathMaxWidth, pathWidth);
y1 = DetermineNextStep(random, y1, directionChangeDistance, directionChangePercentage, pathMaxWidth, width);
for (int i = -pathWidth; i <= pathWidth; i++)
{
SetGridCoordinate(grid, x, y1 + i, 0);
}
}
break;
case Directions.RightToLeft:
int y2 = initialY;
for (int i = -pathWidth; i <= pathWidth; i++)
{
SetGridCoordinate(grid, initialX, y2 + i, 0);
}
for (int x = initialX; x > 0; x--)
{
pathWidth = ComputeWidth(random, widthChangePercentage, pathMinWidth, pathMaxWidth, pathWidth);
y2 = DetermineNextStep(random, y2, directionChangeDistance, directionChangePercentage, pathMaxWidth, width);
for (int i = -pathWidth; i <= pathWidth; i++)
{
SetGridCoordinate(grid, x, y2 + i, 0);
}
}
break;
}
return grid;
}
/// <summary>
/// Determines the new width of the path
/// </summary>
/// <param name="random"></param>
/// <param name="widthChangePercentage"></param>
/// <param name="pathMinWidth"></param>
/// <param name="pathMaxWidth"></param>
/// <param name="pathWidth"></param>
/// <returns></returns>
private static int ComputeWidth(System.Random random, int widthChangePercentage, int pathMinWidth, int pathMaxWidth, int pathWidth)
{
if (random.Next(0, 100) > widthChangePercentage)
{
int widthChange = Random.Range(-pathMaxWidth, pathMaxWidth);
pathWidth += widthChange;
if (pathWidth < pathMinWidth)
{
pathWidth = pathMinWidth;
}
if (pathWidth > pathMaxWidth)
{
pathWidth = pathMaxWidth;
}
}
return pathWidth;
}
/// <summary>
/// Determines in what direction to move the path
/// </summary>
/// <param name="random"></param>
/// <param name="x"></param>
/// <param name="directionChangeDistance"></param>
/// <param name="directionChangePercentage"></param>
/// <param name="pathMaxWidth"></param>
/// <param name="width"></param>
/// <returns></returns>
private static int DetermineNextStep(System.Random random, int x, int directionChangeDistance, int directionChangePercentage, int pathMaxWidth, int width)
{
if (random.Next(0, 100) > directionChangePercentage)
{
int xChange = Random.Range(-directionChangeDistance, directionChangeDistance);
x += xChange;
if (x < pathMaxWidth)
{
x = pathMaxWidth;
}
if (x > (width - pathMaxWidth))
{
x = width - pathMaxWidth;
}
}
return x;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 6040f34cccf59644a9602da5bc052d06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMGridGenerators/MMGridGeneratorPath.cs
uploadId: 830868

View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = System.Random;
namespace MoreMountains.Tools
{
/// <summary>
/// Generates a grid of the specified size based on a seeded perlin noise, the smaller the seed, the blockier the grid
/// </summary>
public class MMGridGeneratorPerlinNoise : MMGridGenerator
{
/// <summary>
/// Generates a grid of the specified size based on a seeded perlin noise, the smaller the seed, the blockier the grid
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="seed"></param>
/// <returns></returns>
public static int[,] Generate(int width, int height, float seed)
{
int[,] grid = PrepareGrid(ref width, ref height);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
int value = Mathf.RoundToInt(Mathf.PerlinNoise(i * seed, j * seed));
SetGridCoordinate(grid, i, j, value);
}
}
return grid;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 6a6c4a44291630848b8d616911bd8c47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMGridGenerators/MMGridGeneratorPerlinNoise.cs
uploadId: 830868

View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = System.Random;
namespace MoreMountains.Tools
{
/// <summary>
/// Generates a grid with a ground floor
/// </summary>
public class MMGridGeneratorPerlinNoiseGround : MMGridGenerator
{
/// <summary>
/// Generates a grid with a ground floor
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="seed"></param>
/// <returns></returns>
public static int[,] Generate(int width, int height, float seed)
{
int[,] grid = PrepareGrid(ref width, ref height);
for (int i = 0; i < width; i++)
{
int groundHeight = Mathf.FloorToInt((Mathf.PerlinNoise(i, seed) - 0.5f) * height) + (height/2);
for (int j = groundHeight; j >= 0; j--)
{
SetGridCoordinate(grid, i, j, 1);
}
}
return grid;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 4829c639bd6729945b0664d15e2f740e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMGridGenerators/MMGridGeneratorPerlinNoiseGround.cs
uploadId: 830868

View File

@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using MoreMountains.Tools;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Generates a simple grid filled with random points
/// </summary>
public class MMGridGeneratorRandom : MMGridGenerator
{
/// <summary>
/// Generates a simple grid filled with random points
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="seed"></param>
/// <param name="fillPercentage"></param>
/// <returns></returns>
public static int[,] Generate(int width, int height, int seed, int fillPercentage)
{
int[,] grid = PrepareGrid(ref width, ref height);
grid = MMGridGeneratorFull.Generate(width, height, true);
System.Random random = new System.Random(seed);
for (int i = 0; i <= width; i ++)
{
for (int j = 0; j <= height; j ++)
{
int value = (random.Next(0,100) < fillPercentage)? 1: 0;
SetGridCoordinate(grid, i, j, value);
}
}
return grid;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c05de6f8b07240b4e87c6219630c251d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMGridGenerators/MMGridGeneratorRandom.cs
uploadId: 830868

View File

@@ -0,0 +1,101 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Generates a grid with a path carved by a drunkard walk algorithm
/// See http://pcg.wikidot.com/pcg-algorithm:drunkard-walk
/// </summary>
public class MMGridGeneratorRandomWalk : MMGridGenerator
{
/// <summary>
/// Generates a grid with a path carved by a drunkard walk algorithm
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="seed"></param>
/// <param name="fillPercentage"></param>
/// <returns></returns>
public static int[,] Generate(int width, int height, int seed, int fillPercentage, Vector2Int startingPoint, int maxIterations,
bool boundsTop = false, bool boundsBottom = false, bool boundsLeft = false, bool boundsRight = false)
{
int[,] grid = PrepareGrid(ref width, ref height);
grid = MMGridGeneratorFull.Generate(width, height, true);
System.Random random = new System.Random(seed);
int requiredFillQuantity = ((width * height) * fillPercentage) / 100;
int fillCounter = 0;
int currentX = startingPoint.x;
int currentY = startingPoint.y;
grid[currentX, currentY] = 0;
fillCounter++;
int iterationsCounter = 0;
int minX = boundsLeft ? 2 : 1;
int maxX = boundsRight ? width - 1 : width;
int minY = boundsBottom ? 2 : 1;
int maxY = boundsTop ? height - 1 : height;
while ((fillCounter < requiredFillQuantity) && (iterationsCounter < maxIterations))
{
int direction = random.Next(4);
switch (direction)
{
case 0:
if ((currentY + 1) < maxY)
{
currentY++;
grid = Carve(grid, currentX, currentY, ref fillCounter);
}
break;
case 1:
if ((currentY - 1) > minY)
{
currentY--;
grid = Carve(grid, currentX, currentY, ref fillCounter);
}
break;
case 2:
if ((currentX - 1) > minX)
{
currentX--;
grid = Carve(grid, currentX, currentY, ref fillCounter);
}
break;
case 3:
if ((currentX + 1) < maxX)
{
currentX++;
grid = Carve(grid, currentX, currentY, ref fillCounter);
}
break;
}
iterationsCounter++;
}
return grid;
}
/// <summary>
///
/// </summary>
/// <param name="grid"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="fillCounter"></param>
/// <returns></returns>
private static int[,] Carve(int[,] grid, int x, int y, ref int fillCounter)
{
if (grid[x, y] == 1)
{
grid[x, y] = 0;
fillCounter++;
}
return grid;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: bcddb04b7bb50904182da35f2b38777c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMGridGenerators/MMGridGeneratorRandomWalk.cs
uploadId: 830868

View File

@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Generates a grid with a path carved by a drunkard walk algorithm that will avoid another grid's walls
/// </summary>
public class MMGridGeneratorRandomWalkAvoider : MMGridGenerator
{
/// <summary>
/// Generates a grid with a path carved by a drunkard walk algorithm that will avoid another grid's walls
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="seed"></param>
/// <param name="fillPercentage"></param>
/// <returns></returns>
public static int[,] Generate(int width, int height, int seed, int fillPercentage, Vector2Int startingPoint, int[,] obstacles, int obstacleDistance, int maxIterations)
{
int[,] grid = PrepareGrid(ref width, ref height);
grid = MMGridGeneratorFull.Generate(width, height, true);
System.Random random = new System.Random(seed);
int requiredFillQuantity = ((width * height) * fillPercentage) / 100;
int fillCounter = 0;
int currentX = startingPoint.x;
int currentY = startingPoint.y;
grid[currentX, currentY] = 0;
fillCounter++;
int iterationsCount = 0;
while ((fillCounter < requiredFillQuantity) && (iterationsCount < maxIterations))
{
int direction = random.Next(4);
switch (direction)
{
case 0: // up
if ( ((currentY + 1) <= height) && !ObstacleAt(obstacles, currentX, currentY + obstacleDistance) )
{
currentY++;
grid = Carve(grid, currentX, currentY, ref fillCounter);
}
break;
case 1: // down
if ( ((currentY - 1) > 1) && !ObstacleAt(obstacles, currentX, currentY - obstacleDistance) )
{
currentY--;
grid = Carve(grid, currentX, currentY, ref fillCounter);
}
break;
case 2: // left
if (((currentX - 1) > 1) && !ObstacleAt(obstacles, currentX - obstacleDistance, currentY ) )
{
currentX--;
grid = Carve(grid, currentX, currentY, ref fillCounter);
}
break;
case 3: // right
if (((currentX + 1) <= width) && !ObstacleAt(obstacles, currentX + obstacleDistance, currentY) )
{
currentX++;
grid = Carve(grid, currentX, currentY, ref fillCounter);
}
break;
}
iterationsCount++;
}
return grid;
}
/// <summary>
/// Returns true if an obstacle is found at the specified coordinates, false otherwise
/// </summary>
/// <param name="obstacles"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private static bool ObstacleAt(int[,] obstacles, int x, int y)
{
return (MMGridGenerator.GetValueAtGridCoordinate(obstacles, x, y, 1) == 1);
}
/// <summary>
///
/// </summary>
/// <param name="grid"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="fillCounter"></param>
/// <returns></returns>
private static int[,] Carve(int[,] grid, int x, int y, ref int fillCounter)
{
if (GetValueAtGridCoordinate(grid, x, y, 0) == 1)
{
SetGridCoordinate(grid, x, y, 0);
fillCounter++;
}
return grid;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 3c349afb15421f141ae3ba659175c815
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMGridGenerators/MMGridGeneratorRandomWalkAvoider.cs
uploadId: 830868

View File

@@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Uses random walk to generate a ground with controlled elevation
/// </summary>
public class MMGridGeneratorRandomWalkGround : MMGridGenerator
{
/// <summary>
/// Uses random walk to generate a ground with controlled elevation
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="seed"></param>
/// <param name="minHeightDifference"></param>
/// <param name="maxHeightDifference"></param>
/// <param name="minFlatDistance"></param>
/// <param name="maxFlatDistance"></param>
/// <returns></returns>
public static int[,] Generate(int width, int height, int seed, int minHeightDifference, int maxHeightDifference, int minFlatDistance, int maxFlatDistance, int maxHeight)
{
System.Random random = new System.Random(seed.GetHashCode());
Random.InitState(seed);
int[,] grid = PrepareGrid(ref width, ref height);
int groundHeight = Random.Range(0, maxHeight);
int previousGroundHeight = groundHeight;
int currentFlatDistance = -1;
for (int i = 0; i < width; i++)
{
groundHeight = previousGroundHeight;
int newElevation = Random.Range(minHeightDifference, maxHeightDifference);
int flatDistance = Random.Range(minFlatDistance, maxFlatDistance);
if (currentFlatDistance >= flatDistance - 1)
{
if (random.Next(2) > 0)
{
groundHeight -= newElevation;
}
else if (previousGroundHeight + newElevation < height)
{
groundHeight += newElevation;
}
groundHeight = Mathf.Clamp(groundHeight, 1, maxHeight);
currentFlatDistance = 0;
}
else
{
currentFlatDistance++;
}
for (int j = groundHeight; j >= 0; j--)
{
grid[i, j] = 1;
}
previousGroundHeight = groundHeight;
}
return grid;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 21e69a8c38f55e84ea754b184697f036
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMGridGenerators/MMGridGeneratorRandomWalkGround.cs
uploadId: 830868

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 457a984195dd82e4194c80673fdf1c9b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,229 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Tilemaps;
using Random = UnityEngine.Random;
namespace MoreMountains.Tools
{
#if MM_PHYSICS2D
/// <summary>
/// This class will fill a tilemap with the data generated by the combination of its layers
/// </summary>
[ExecuteAlways]
public class MMTilemapGenerator : MonoBehaviour
{
[Header("Grid")]
/// The width of the grid, in cells
[Tooltip("The width of the grid, in cells")]
[MMVector("Min","Max")]
public Vector2Int GridWidth = new Vector2Int(50,50);
/// the height of the grid, in cells
[Tooltip("the height of the grid, in cells")]
[MMVector("Min","Max")]
public Vector2Int GridHeight = new Vector2Int(50,50);
[Header("Data")]
/// the list of layers that will be used to generate the tilemap
[Tooltip("the list of layers that will be used to generate the tilemap")]
public MMTilemapGeneratorLayerList Layers;
/// a value between 0 and 1 that will be used by all layers as their random seed. If you generate another map using the same seed, it'll look the same
[Tooltip("a value between 0 and 1 that will be used by all layers as their random seed. If you generate another map using the same seed, it'll look the same")]
public int GlobalSeed = 0;
/// whether or not to randomize the global seed every time a new map is generated
[Tooltip("whether or not to randomize the global seed every time a new map is generated")]
public bool RandomizeGlobalSeed = true;
[Header("Slow Render")]
/// turning this to true will (at runtime only) draw the map progressively. This is really just for fun.
[Tooltip("turning this to true will (at runtime only) draw the map progressively. This is really just for fun.")]
public bool SlowRender = false;
/// the duration of the slow render, in seconds
[Tooltip("the duration of the slow render, in seconds")]
public float SlowRenderDuration = 1f;
/// the tween to use for the slow render
[Tooltip("the tween to use for the slow render")]
public MMTweenType SlowRenderTweenType = new MMTweenType(MMTween.MMTweenCurve.EaseInOutCubic);
protected int[,] _grid;
protected int _width;
protected int _height;
/// <summary>
/// the possible methods that can be used to generate a random grid
/// </summary>
public enum GenerateMethods
{
Full,
Perlin,
PerlinGround,
Random,
RandomWalk,
RandomWalkAvoider,
RandomWalkGround,
Path,
Copy
}
/// <summary>
/// Generates and renders every layer in the data stack
/// </summary>
public virtual void Generate()
{
Random.InitState((int)System.DateTime.Now.Ticks);
if (RandomizeGlobalSeed) { GlobalSeed = Mathf.Abs(Random.Range(int.MinValue, int.MaxValue)); }
foreach (MMTilemapGeneratorLayer layer in Layers)
{
GenerateLayer(layer);
}
}
/// <summary>
/// On reset, we initialize our list
/// </summary>
void Reset()
{
Layers = new MMTilemapGeneratorLayerList(){
new MMTilemapGeneratorLayer()
};
}
/// <summary>
/// Generates a layer grid, and renders it
/// </summary>
/// <param name="layer"></param>
protected virtual void GenerateLayer(MMTilemapGeneratorLayer layer)
{
if (!layer.Active)
{
return;
}
if (layer.TargetTilemap == null) { Debug.LogError("Tilemap Generator : you need to specify a Target Tilemap to paint on."); }
if (layer.Tile == null) { Debug.LogError("Tilemap Generator : you need to specify a Tile to paint with."); }
if (layer.GridWidth == 0) { Debug.LogError("Tilemap Generator : grid width can't be 0."); }
if (layer.GridHeight == 0) { Debug.LogError("Tilemap Generator : grid height can't be 0."); }
float seedFloat = 0f;
float layerSeedFloat = 0f;
float globalSeedFloat = 0f;
UnityEngine.Random.InitState(GlobalSeed);
int width = layer.OverrideGridSize ? layer.GridWidth : UnityEngine.Random.Range(GridWidth.x, GridWidth.y);
int height = layer.OverrideGridSize ? layer.GridHeight : UnityEngine.Random.Range(GridHeight.x, GridHeight.y);
globalSeedFloat = UnityEngine.Random.value;
// random outside of the global seed
if (layer.DoNotUseGlobalSeed)
{
Random.InitState((int)System.DateTime.Now.Ticks);
if (layer.RandomizeSeed)
{
layer.Seed = Mathf.Abs(Random.Range(int.MinValue, int.MaxValue));
}
UnityEngine.Random.InitState(layer.Seed);
layerSeedFloat = UnityEngine.Random.value;
}
int seed = layer.DoNotUseGlobalSeed ? layer.Seed : GlobalSeed;
seedFloat = layer.DoNotUseGlobalSeed ? layerSeedFloat : globalSeedFloat;
switch (layer.GenerateMethod)
{
case GenerateMethods.Full:
_grid = MMGridGeneratorFull.Generate(width, height, layer.FullGenerationFilled);
layer.Grid = _grid;
break;
case GenerateMethods.Perlin:
_grid = MMGridGeneratorPerlinNoise.Generate(width, height, seedFloat);
layer.Grid = _grid;
break;
case GenerateMethods.PerlinGround:
_grid = MMGridGeneratorPerlinNoiseGround.Generate(width, height, seedFloat);
layer.Grid = _grid;
break;
case GenerateMethods.Random:
_grid = MMGridGeneratorRandom.Generate(width, height, seed, layer.RandomFillPercentage);
layer.Grid = _grid;
break;
case GenerateMethods.RandomWalk:
_grid = MMGridGeneratorRandomWalk.Generate(width, height, seed, layer.RandomWalkPercent, layer.RandomWalkStartingPoint, layer.RandomWalkMaxIterations, layer.BoundsTop, layer.BoundsBottom, layer.BoundsLeft, layer.BoundsRight);
layer.Grid = _grid;
break;
case GenerateMethods.RandomWalkAvoider:
int[,] obstacleGrid = MMGridGenerator.TilemapToGrid(layer.RandomWalkAvoiderObstaclesTilemap, width, height);
_grid = MMGridGeneratorRandomWalkAvoider.Generate(width, height, seed, layer.RandomWalkAvoiderPercent, layer.RandomWalkAvoiderStartingPoint, obstacleGrid, layer.RandomWalkAvoiderObstaclesDistance, layer.RandomWalkAvoiderMaxIterations);
layer.Grid = _grid;
break;
case GenerateMethods.RandomWalkGround:
_grid = MMGridGeneratorRandomWalkGround.Generate(width, height, seed,
layer.RandomWalkGroundMinHeightDifference, layer.RandomWalkGroundMaxHeightDifference,
layer.RandomWalkGroundMinFlatDistance, layer.RandomWalkGroundMaxFlatDistance, layer.RandomWalkGroundMaxHeight);
layer.Grid = _grid;
break;
case GenerateMethods.Path:
_grid = MMGridGeneratorPath.Generate(width, height, seed, layer.PathDirection, layer.PathStartPosition, layer.PathMinWidth,
layer.PathMaxWidth, layer.PathDirectionChangeDistance, layer.PathWidthChangePercentage,
layer.PathDirectionChangePercentage);
layer.Grid = _grid;
break;
case GenerateMethods.Copy:
layer.TargetTilemap.ClearAllTiles();
DelayedCopy(layer);
break;
}
if (layer.Smooth) { _grid = MMGridGenerator.SmoothenGrid(_grid); }
if (layer.InvertGrid) { _grid = MMGridGenerator.InvertGrid(_grid); }
_grid = MMGridGenerator.BindGrid(_grid, layer.BoundsTop, layer.BoundsBottom, layer.BoundsLeft, layer.BoundsRight);
_grid = MMGridGenerator.ApplySafeSpots(_grid, layer.SafeSpots);
RenderGrid(layer);
}
/// <summary>
/// Copies the tilemap's content after a delay because Unity.
/// </summary>
/// <param name="layer"></param>
async static void DelayedCopy(MMTilemapGeneratorLayer layer)
{
await Task.Delay(500);
MMTilemapShadow.Copy(layer.CopyTilemap, layer.TargetTilemap);
}
/// <summary>
/// Renders the grid with the selected modes to the specified target tilemap
/// </summary>
/// <param name="layer"></param>
protected virtual void RenderGrid(MMTilemapGeneratorLayer layer)
{
MMTilemapGridRenderer.RenderGrid(_grid, layer, SlowRender, SlowRenderDuration, SlowRenderTweenType,this);
}
/// <summary>
/// Sets default values for all layers
/// </summary>
protected virtual void OnValidate()
{
if ((Layers == null) || (Layers.Count <= 0))
{
return;
}
foreach (MMTilemapGeneratorLayer layer in Layers)
{
layer.SetDefaults();
}
}
}
#endif
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 1554ad3bc2245e64bbf7cf0a29ed7fa0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMTilemapGenerator/MMTilemapGenerator.cs
uploadId: 830868

View File

@@ -0,0 +1,293 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to display a reoderable list of MMTilemapGeneratorLayers
/// </summary>
[System.Serializable]
public class MMTilemapGeneratorLayerList : MMReorderableArray<MMTilemapGeneratorLayer>
{
}
/// <summary>
/// A class used to store and edit the data of MMTilemapGenerator layers, which you can use and combine
/// to generate unique and random grids
/// </summary>
[Serializable]
public class MMTilemapGeneratorLayer
{
#if MM_PHYSICS2D
/// the grid generated by this layer
public virtual int[,] Grid { get; set; }
/// the various modes of fusion you can use on this layer.
/// Fusion modes will be applied on layers from top to bottom (the last to speak wins)
/// Normal : just generates a grid, default mode
/// NormalNoClear : generates a grid, but doesn't clear it first
/// Intersect : when painting on a target grid that already has content, will only keep the resulting intersection
/// Combine : adds the result of this grid to the existing target
/// Subtract : removes the result of this grid from the existing target
public enum FusionModes { Normal, NormalNoClear, Intersect, Combine, Subtract }
/// the name of this layer, doesn't do anything, just used to organize things
[Tooltip("the name of this layer, doesn't do anything, just used to organize things")]
public string Name = "Layer";
/// whether this layer should be taken into account when generating the final grid
[Tooltip("whether this layer should be taken into account when generating the final grid")]
public bool Active = true;
[Header("Tilemaps")]
/// the tilemap on which to paint tiles
[Tooltip("the tilemap on which to paint tiles")]
public Tilemap TargetTilemap;
/// the tile to use to paint on the tilemap
[Tooltip("the tile to use to paint on the tilemap")]
public TileBase Tile;
[Header("Grid")]
/// whether or not this layer should paint a grid of a different size than the global one
[Tooltip("whether or not this layer should paint a grid of a different size than the global one")]
public bool OverrideGridSize = false;
/// the new value of the grid width
[Tooltip("the new value of the grid width")]
[MMCondition("OverrideGridSize", true)]
public int GridWidth = 50;
/// the new value of the grid height
[Tooltip("the new value of the grid height")]
[MMCondition("OverrideGridSize", true)]
public int GridHeight = 50;
[Header("Method")]
/// the algorithm to use to generate this layer's grid
[Tooltip("the algorithm to use to generate this layer's grid :\n" +
"Full : will fill or empty the grid\n" +
"Perlin : uses perlin noise to randomly fill the grid\n" +
"Perling Ground : uses perlin noise to generate a ground surface\n" +
"Random Walk : starts at point A then moves randomly, carving a path\n" +
"Random Walk Avoider : same, but avoids obstacles\n" +
"Path : starts at Point A, and carves a path in the selected direction\n" +
"Copy : copies another tilemap to generate a grid")]
public MMTilemapGenerator.GenerateMethods GenerateMethod = MMTilemapGenerator.GenerateMethods.Perlin;
/// if this is true, global seed won't be used for this layer
[Tooltip("if this is true, global seed won't be used for this layer")]
public bool DoNotUseGlobalSeed = false;
/// whether or not to randomize this layer's seed when pressing Generate
[Tooltip("whether or not to randomize this layer's seed when pressing Generate")]
[MMCondition("DoNotUseGlobalSeed", true)]
public bool RandomizeSeed = true;
/// the dedicated seed of this layer, when not using the global one
[Tooltip("the dedicated seed of this layer, when not using the global one")]
[MMCondition("DoNotUseGlobalSeed", true)]
public int Seed = 1;
[Header("PostProcessing")]
/// whether or not to smoothen the resulting grid, gets rid of spikes/isolated points
[Tooltip("whether or not to smoothen the resulting grid, gets rid of spikes/isolated points")]
public bool Smooth = false;
/// whether or not to invert the grid to get the opposite result (filled becomes empty, empty becomes filled)
[Tooltip("whether or not to invert the grid to get the opposite result (filled becomes empty, empty becomes filled)")]
public bool InvertGrid = false;
/// The selected fusion mode
[Tooltip("the various modes of fusion you can use on this layer.\n" +
"Fusion modes will be applied on layers from top to bottom (the last to speak wins)\n" +
"Normal : just generates a grid, default mode\n" +
"NormalNoClear : generates a grid, but doesn't clear it first\n" +
"Intersect : when painting on a target grid that already has content, will only keep the resulting intersection\n" +
"Combine : adds the result of this grid to the existing target\n" +
"Subtract : removes the result of this grid from the existing target")]
public FusionModes FusionMode = FusionModes.Normal;
[Header("Settings")]
// full
/// in full mode, whether the grid should be full or empty
[Tooltip("in full mode, whether the grid should be full or empty")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.Full)]
public bool FullGenerationFilled = true;
// random
/// in random mode, the percentage of the grid to fill
[Tooltip("in random mode, the percentage of the grid to fill")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.Random)]
public int RandomFillPercentage = 50;
// random walk ground
/// in random walk ground mode,the minimum height difference between two steps
[Tooltip("in random walk ground mode,the minimum height difference between two steps")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkGround)]
public int RandomWalkGroundMinHeightDifference = 1;
/// in random walk ground mode,the maximum height difference between two steps
[Tooltip("in random walk ground mode,the maximum height difference between two steps")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkGround)]
public int RandomWalkGroundMaxHeightDifference = 3;
/// in random walk ground mode, the minimum distance that should remain flat
[Tooltip("in random walk ground mode, the minimum distance that should remain flat")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkGround)]
public int RandomWalkGroundMinFlatDistance = 1;
/// in random walk ground mode, the maximum distance that should remain flat
[Tooltip("in random walk ground mode, the maximum distance that should remain flat")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkGround)]
public int RandomWalkGroundMaxFlatDistance = 3;
/// in random walk ground mode, the maximum height of the tallest platfrom, from the bottom of the grid
[Tooltip("in random walk ground mode, the maximum height of the tallest platfrom, from the bottom of the grid")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkGround)]
public int RandomWalkGroundMaxHeight = 3;
// random walk
/// in random walk mode, the percentage of the map the walker should try filling
[Tooltip("in random walk mode, the percentage of the map the walker should try filling")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalk)]
public int RandomWalkPercent = 50;
/// in random walk mode,the point at which the walker starts, in grid coordinates
[Tooltip("in random walk mode,the point at which the walker starts, in grid coordinates")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalk)]
public Vector2Int RandomWalkStartingPoint = Vector2Int.zero;
/// in random walk mode, the max amount of iterations to run the random on
[Tooltip("in random walk mode, the max amount of iterations to run the random on")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalk)]
public int RandomWalkMaxIterations = 1500;
// random walk avoider
/// in random walk avoider mode, the percentage of the grid the walker should try filling
[Tooltip("in random walk avoider mode, the percentage of the grid the walker should try filling")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkAvoider)]
public int RandomWalkAvoiderPercent = 50;
/// in random walk avoider mode, the point in grid units at which the walker starts
[Tooltip("in random walk avoider mode, the point in grid units at which the walker starts")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkAvoider)]
public Vector2Int RandomWalkAvoiderStartingPoint = Vector2Int.zero;
/// in random walk avoider mode, the tilemap containing the data the walker will try to avoid
[Tooltip("in random walk avoider mode, the tilemap containing the data the walker will try to avoid")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkAvoider)]
public Tilemap RandomWalkAvoiderObstaclesTilemap;
/// in random walk avoider mode,the distance at which the walker should try to stay away from obstacles
[Tooltip("in random walk avoider mode,the distance at which the walker should try to stay away from obstacles")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkAvoider)]
public int RandomWalkAvoiderObstaclesDistance = 1;
/// in random walk avoider mode,the max amount of iterations this algorithm will iterate on
[Tooltip("in random walk avoider mode,the max amount of iterations this algorithm will iterate on")]
[MMEnumCondition("GenerateMethod", (int)MMTilemapGenerator.GenerateMethods.RandomWalkAvoider)]
public int RandomWalkAvoiderMaxIterations = 100;
// path
/// in path mode, the start position of the path
[Tooltip("in path mode, the start position of the path")]
[MMEnumCondition("GenerateMethod", (int) MMTilemapGenerator.GenerateMethods.Path)]
public Vector2Int PathStartPosition = Vector2Int.zero;
/// in path mode, the direction the path should follow
[Tooltip("in path mode, the direction the path should follow")]
[MMEnumCondition("GenerateMethod", (int) MMTilemapGenerator.GenerateMethods.Path)]
public MMGridGeneratorPath.Directions PathDirection = MMGridGeneratorPath.Directions.BottomToTop;
/// in path mode, the minimum width of the path
[Tooltip("in path mode, the minimum width of the path")]
[MMEnumCondition("GenerateMethod", (int) MMTilemapGenerator.GenerateMethods.Path)]
public int PathMinWidth = 2;
/// in path mode, the maximum width of the path
[Tooltip("in path mode, the maximum width of the path")]
[MMEnumCondition("GenerateMethod", (int) MMTilemapGenerator.GenerateMethods.Path)]
public int PathMaxWidth = 4;
/// in path mode, the maximum number of units the path can change direction
[Tooltip("in path mode, the maximum number of units the path can change direction")]
[MMEnumCondition("GenerateMethod", (int) MMTilemapGenerator.GenerateMethods.Path)]
public int PathDirectionChangeDistance = 2;
/// in path mode, the chance (in percent) for the path to change width at every step
[Tooltip("in path mode, the chance (in percent) for the path to change width at every step")]
[MMEnumCondition("GenerateMethod", (int) MMTilemapGenerator.GenerateMethods.Path)]
public int PathWidthChangePercentage = 50;
/// in path mode, the chance percentage that the path will take a new direction
[Tooltip("in path mode, the chance percentage that the path will take a new direction")]
[MMEnumCondition("GenerateMethod", (int) MMTilemapGenerator.GenerateMethods.Path)]
public int PathDirectionChangePercentage = 50;
// copy
/// in copy mode, the tilemap to copy
[Tooltip("in copy mode, the tilemap to copy")]
[MMEnumCondition("GenerateMethod", (int) MMTilemapGenerator.GenerateMethods.Copy)]
public Tilemap CopyTilemap;
[Header("Bounds")]
/// whether or not to force a wall on the grid's top
[Tooltip("whether or not to force a wall on the grid's top")]
public bool BoundsTop = false;
/// whether or not to force a wall on the grid's bottom
[Tooltip("whether or not to force a wall on the grid's bottom")]
public bool BoundsBottom = false;
/// whether or not to force a wall on the grid's left
[Tooltip("whether or not to force a wall on the grid's left")]
public bool BoundsLeft = false;
/// whether or not to force a wall on the grid's right
[Tooltip("whether or not to force a wall on the grid's right")]
public bool BoundsRight = false;
/// <summary>
/// A struct used to store safe spots dimensions
/// </summary>
[Serializable]
public struct MMTilemapGeneratorLayerSafeSpot
{
public Vector2Int Start;
public Vector2Int End;
}
[Header("Safe Spots")]
/// a list of "safe spots" : defined by their start and end coordinates, these areas will be left empty
[Tooltip("a list of 'safe spots' : defined by their start and end coordinates, these areas will be left empty")]
public List<MMTilemapGeneratorLayerSafeSpot> SafeSpots;
[HideInInspector]
/// this is only used to initialize the default values in the inspector
public bool Initialized = false;
/// <summary>
/// This method will set default values, because Unity.
/// </summary>
public virtual void SetDefaults()
{
if (!Initialized)
{
GridWidth = 50;
GridHeight = 50;
GenerateMethod = MMTilemapGenerator.GenerateMethods.Perlin;
RandomizeSeed = true;
DoNotUseGlobalSeed = false;
FusionMode = FusionModes.Normal;
Seed = 123456789;
Smooth = false;
InvertGrid = false;
FullGenerationFilled = true;
RandomFillPercentage = 50;
RandomWalkGroundMinHeightDifference = 1;
RandomWalkGroundMaxHeightDifference = 3;
RandomWalkGroundMinFlatDistance = 1;
RandomWalkGroundMaxFlatDistance = 3;
RandomWalkGroundMaxHeight = 8;
RandomWalkPercent = 50;
RandomWalkStartingPoint = Vector2Int.zero;
RandomWalkMaxIterations = 1500;
PathMinWidth = 2;
PathMaxWidth = 4;
PathDirectionChangeDistance = 2;
PathWidthChangePercentage = 50;
PathDirectionChangePercentage = 50;
RandomWalkAvoiderPercent = 50;
RandomWalkAvoiderStartingPoint = Vector2Int.zero;
RandomWalkAvoiderObstaclesTilemap = null;
RandomWalkAvoiderObstaclesDistance = 1;
RandomWalkAvoiderMaxIterations = 100;
BoundsTop = false;
BoundsBottom = false;
BoundsLeft = false;
BoundsRight = false;
PathStartPosition = Vector2Int.zero;
PathDirection = MMGridGeneratorPath.Directions.BottomToTop;
Initialized = true;
}
}
#endif
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 01608833a8be3af4587b87e116bffc68
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMProcedural/MMTilemapGenerator/MMTilemapGeneratorLayer.cs
uploadId: 830868