/// <summary> /// Set the callbacks to call before and after the given OpenXR function is called within the Mock Runtime /// /// Note that since some OpenXR functions are called from within the graphics thread that care should /// be taken to maintain thread safety from within the callbacks. /// /// Note that function callbacks can be set prior to the MockRuntime being initialized but will be /// reset when the mock runtime is shutdown. /// </summary> /// <param name="function">OpenXR function name</param> /// <param name="beforeCallback">Callback to call before the OpenXR function is called (null to clear)</param> /// <param name="afterCallback">Callback to call after the OpenXR function is called (null to clear)</param> public static void SetFunctionCallback(string function, BeforeFunctionDelegate beforeCallback, AfterFunctionDelegate afterCallback) { if (beforeCallback != null) { if (null == s_BeforeFunctionCallbacks) { s_BeforeFunctionCallbacks = new Dictionary <string, BeforeFunctionDelegate>(); } s_BeforeFunctionCallbacks[function] = beforeCallback; } else if (s_BeforeFunctionCallbacks != null) { s_BeforeFunctionCallbacks.Remove(function); if (s_BeforeFunctionCallbacks.Count == 0) { s_BeforeFunctionCallbacks = null; } } if (afterCallback != null) { if (null == s_AfterFunctionCallbacks) { s_AfterFunctionCallbacks = new Dictionary <string, AfterFunctionDelegate>(); } s_AfterFunctionCallbacks[function] = afterCallback; } else if (s_AfterFunctionCallbacks != null) { s_AfterFunctionCallbacks.Remove(function); if (s_AfterFunctionCallbacks.Count == 0) { s_AfterFunctionCallbacks = null; } } MockRuntime_RegisterFunctionCallbacks( s_BeforeFunctionCallbacks != null ? BeforeFunctionCallback : (BeforeFunctionDelegate)null, s_AfterFunctionCallbacks != null ? AfterFunctionCallback : (AfterFunctionDelegate)null); }
private static extern void MockRuntime_RegisterFunctionCallbacks(BeforeFunctionDelegate hookBefore, AfterFunctionDelegate hookAfter);
/// <summary> /// Set a callback to call before the given OpenXR function is called within the Mock Runtime /// </summary> /// <param name="function">OpenXR function name</param> /// <param name="afterCallback">Callback to call after the OpenXR function is called (null to clear)</param> public static void SetFunctionCallback(string function, AfterFunctionDelegate afterCallback) => SetFunctionCallback(function, GetBeforeFunctionCallback(function), afterCallback);