Useful Helpers

Header Builder

The RestRequest class contains methods which allow the caller to specify directly which headers are sent back to the caller. The argument is of type Dictionary<string, List<string>> headers. To ease the creation of this construct, the HeaderBilder class can be used.

Example:

request.CreateResponse().Headers(
        new HeaderBuilder(HttpHeader.E_TAG, "").withHeader("2nd.header", "")
    ).SendAsync(); 

HttpHeader and MimeType

HttpHeader and MimeType define useful constants for Http Headers and Mime Types.


ThreadingHelper

The class ThreadingHelper bridges between the endpoint thread and the unity main rendering thread. See Multithreading for more information.


Profile Marker

Profile markers can be assigned when scheduling a workload via ThreadingHelper.Instance.ExecuteXXX methods like this

ThreadingHelper.Instance.ExecuteAsync(() => { 
	transform.position += new Vector3(0.001f, 0.001f, 0.001f); 
}, "Position Updates");

These can now be found inside the profiler

Screenshot of the profiler showing the waterfall graph

By default, the name of the execute method (e.g. ExecuteSync) is used as the profile marker name.

Performance counters

In Unity 2021 there is a new profiler UI, where custom implementations can provide Performance counters. These can be enabled in the Profiler under “Profiler Modules”.