How to use System.Func<>

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

System.Func and System.Action are C#'s delegate classes!

Basically, it’s asking for a delegate method as an argument, specifically one that takes three integers and returns a float.

There’s lots of ways to write these, but the best is using lambda expressions:

VeronicCells(1000, (x,y,x) => {
 
    //do something with x y z and return a float.

    return (float)(x * 2 + y * 5 * z - 1000);

});

Check it out:
C# Lambda Expressions - Dot Net Perls ← Check it out.

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)