Function DrawingManager.TryDrawHasher

TryDrawHasher (DrawingData.Hasher hasher, RedrawScope redrawScope=…)

Tries to draw a builder that was rendered during the last frame using the same hash.

Public Static
bool TryDrawHasher (

DrawingData.Hasher

hasher

Hash of whatever inputs you used to generate the drawing data.

RedrawScope

redrawScope=default

Optional redraw scope for this command builder. See GetRedrawScope.

)

Tries to draw a builder that was rendered during the last frame using the same hash.

Return

True if the builder was found and scheduled for rendering. If false, you should draw everything again and submit a new command builder.

// Just a nice looking curve (which uses a lot of complex math)
// See https://en.wikipedia.org/wiki/Butterfly_curve_(transcendental)
static float2 ButterflyCurve (float t) {
t *= 12 * math.PI;
var k = math.exp(math.cos(t)) - 2*math.cos(4*t) - math.pow(math.sin(t/12f), 5);
return new float2(k * math.sin(t), k * math.cos(t));
}

// Make the butterfly "flap its wings" two times per second
var scale = Time.time % 0.5f < 0.25f ? new float2(1, 1) : new float2(0.7f, 1);

// Hash all inputs that you use for drawing something complex
var hasher = new DrawingData.Hasher();
// The only thing making the drawing change, in this case, is the scale
hasher.Add(scale);

// Try to draw a previously cached mesh with this hash
if (!DrawingManager.TryDrawHasher(hasher)) {
// If there's no cached mesh, then draw it from scratch
using (var builder = DrawingManager.GetBuilder(hasher)) {
// Draw a complex curve using 10000 lines
var prev = ButterflyCurve(0);
for (float t = 0; t < 1; t += 0.0001f) {
var next = ButterflyCurve(t);
builder.xy.Line(prev*scale, next*scale, Color.white);
prev = next;
}
}
}