我一直在尝试做几乎相同的事情。对于正方形,您可以在这里找到答案:Unity 中的 2D Array Gradient Generation
对于圆圈一:您可以根据每个“像素”与阵列中心的距离生成它。
这段代码在 C# 中,因为这就是我正在使用的,但我认为它足够基本,可以轻松转换。
int arrayWidth, arrayHeight;
float[,] gradientArray = new var[arrayWidth, arrayHeight]
int centerX = arrayWidth / 2 -1; //find center of the array
int centerY = arrayHeight / 2 -1; //find center of the array
for (int x = 0; x < arrayWidth; x++)
{
for (int y = 0; y < arrayHeight; y++)
{
float distanceX = (centerX - x) * (centerX - x);
float distanceY = (centerY - y) * (centerY - y);
//find distance from center
float distanceToCenter = Mathf.Sqrt(distanceX + distanceY);
//divide distance by one of the sides (width or height).
//by messing with this line you can easily alter the gradient
distanceToCenter = distanceToCenter / arrayHeight;
gradientArray[x, y] = distanceToCenter; //set value
}
}