I’m using the CoherentNoise library and one of the classes constructors requires “System.Func<int, int, int, float>” I have no idea what to pass it. Intelisense says this:
public VoronoiCells(
int seed
System.Func<int, int, int, float> cellValueSource
)
Parameter
cellValueSource: Function that returns cell's value
Delegate Info
TResult Func (T1 arg, T2 arg2, T3 arg3)
Summary
Create a new Voronoi diagram using seed. Control points will be obtained
using random displacement seed by supplied value
That said I’m imagining this library probably already has a number of cellValueSource methods defined somewhere, and is probably expecting you to use one of them.
Ok, I kinda understand. But I’ve tried to implement the lambda and get an error. Here’s my code
[System.Serializable]
public class Function
{
//Public
[Range(1, 4096)]
public int width = 16;
[Range(1, 4096)]
public int height = 16;
public float x;
public float y;
public float z;
public float gain = 1f;
public float bias = 1f;
public Texture2D ramp;
public UnityEngine.Texture GetTexture()
{
CoherentNoise.Generation.Function function = new CoherentNoise.Generation.Function((x, y, z) => {return x + y + z;});
Generator gainFunction = function.Gain(gain);
Generator biasFunction = gainFunction.Bias(bias);
if(ramp != null)
return TextureMaker.RampTexture(width, height, biasFunction, ramp);
else
return new UnityEngine.Texture();
}
}
Here’s my error
IndexOutOfRangeException: Array index is out of range.
CoherentNoise.Texturing.TextureMaker+<>c__DisplayClass7.b__6 (Single x, Single y)
CoherentNoise.Texturing.TextureMaker.Make (Int32 width, Int32 height, System.Func`3 colorFunc, TextureFormat format)
CoherentNoise.Texturing.TextureMaker.RampTexture (Int32 width, Int32 height, CoherentNoise.Generator noise, UnityEngine.Texture2D ramp)
Procedural+Texture+Function.GetTexture () (at Assets/Code/Framework/Procedural.cs:458)
ProceduralTexture.Update () (at Assets/Code/ProceduralTexture.cs:40)