Draw any graph in your custom editor.
Go to Window -> Package Manager
and add from git URL using this URL:
https://github.com/MPrzekop/unity-inspector-graph-drawer.git
Create Dummy field and give it attribute [Graph("Method name")]
template:
[Graph("F")] public float dummy;
public float F(float x)
{
return Mathf.Sin(x) + Mathf.Sin(x*25)*0.2f;
}
full parameters (Method name, function x start, function x end, rect height, sample count)
:
[Graph(MethodName: "F",start:-5,end: 5,rectHeight:200,samples:400)] public float dummyFull;
Visualised method has to be declared as public float MethodName(float x)
In custom editor create a call to GraphDrawer.DrawGraph()
there are overloads for:
- array of Vector3 points
- arbitrary points wraper with line color and width
- function container with line color and width
Graph values by default are stretched to a width of inspector window:
but can also be declared to have regular grid:
There is demo component and custom editor for it.