You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Feel/MMTools/Tools/MMProcedural/MMGridGenerators/MMGridGeneratorRandom.cs

41 lines
1.0 KiB
C#

1 month ago
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;
}
}
}