Skip to content

Commit 6a85dd6

Browse files
committed
Add customizable callbacks OnDllLoaded and Unloaded
Allows users to write their custom code in these callback functions. OnDllLoaded, OnBeforeDllUnload, OnAfterDllUnload Currently only the name is passed, this could be extended to be the NativeDll class (which is currently internal)
1 parent 3d33aac commit 6a85dd6

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

scripts/DllCallbacks.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace UnityNativeTool
2+
{
3+
/// <summary>
4+
/// A place to implement you custom callbacks.
5+
/// </summary>
6+
public static class DllCallbacks
7+
{
8+
/// <summary>
9+
/// This is called whenever a dll has been loaded.
10+
/// </summary>
11+
/// <param name="dllName">The name without preceding underscores or file extension.</param>
12+
public static void OnDllLoaded(string dllName)
13+
{
14+
// Debug.Log("[dll] " + dllName + " dll loaded.");
15+
}
16+
17+
/// <summary>
18+
/// This is called whenever a dll is about to be unloaded.
19+
/// </summary>
20+
/// <param name="dllName">The name without preceding underscores or file extension.</param>
21+
public static void OnBeforeDllUnload(string dllName)
22+
{
23+
// Debug.Log("[dll] " + dllName + " dll unloading...");
24+
}
25+
26+
/// <summary>
27+
/// This is called whenever a dll has been unloaded.
28+
/// </summary>
29+
/// <param name="dllName">The name without preceding underscores or file extension.</param>
30+
public static void OnAfterDllUnload(string dllName)
31+
{
32+
// Debug.Log("[dll] " + dllName + " dll unloaded.");
33+
}
34+
}
35+
}

scripts/DllManipulator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ public static void UnloadAll()
7676
if (dll.handle != IntPtr.Zero)
7777
{
7878
LowLevelPluginManager.OnBeforeDllUnload(dll);
79+
DllCallbacks.OnBeforeDllUnload(dll.name);
7980

8081
bool success = SysUnloadDll(dll.handle);
8182
if (!success)
8283
Debug.LogWarning($"Error while unloading DLL \"{dll.name}\" at path \"{dll.path}\"");
8384

8485
dll.ResetAsUnloaded();
86+
DllCallbacks.OnAfterDllUnload(dll.name);
8587
}
8688
}
8789
}
@@ -424,6 +426,7 @@ internal static void LoadTargetFunction(NativeFunction nativeFunction, bool igno
424426
{
425427
dll.loadingError = false;
426428
LowLevelPluginManager.OnDllLoaded(dll);
429+
DllCallbacks.OnDllLoaded(dll.name);
427430
}
428431
}
429432

0 commit comments

Comments
 (0)