Example #1
0
    void UnloadPlugin()
    {
#if UNITY_EDITOR
        Debug.Log($"Closing plugin {plugin.PluginName}");
#endif
        if (libHandle != IntPtr.Zero)
        {
            _shutdown();
            _init        = null;
            _shutdown    = null;
            _tick        = null;
            _fixedTick   = null;
            _lateTick    = null;
            _sceneLoaded = null;
            while (Functions.FreeLibrary(libHandle))
            {
                // do nothing, repeat until free library release all references
            }
            libHandle = IntPtr.Zero;
            if (_objhandle.IsAllocated)
            {
                _objhandle.Free();
            }
        }
    }
Example #2
0
    void LoadPlugin()
    {
#if UNITY_EDITOR
        Debug.Log($"Loading plugin {plugin.PluginName}");
#endif

        var libPath = plugin.BuildPath(prefix, pluginExtension);
        libHandle = Functions.LoadLibrary(libPath);

        _init     = (PluginInit)Marshal.GetDelegateForFunctionPointer(Functions.GetProcAddress(libHandle, nameof(PluginInit)), typeof(PluginInit));
        _shutdown = (PluginShutdown)Marshal.GetDelegateForFunctionPointer(Functions.GetProcAddress(libHandle, nameof(PluginShutdown)), typeof(PluginShutdown));

        IntPtr tickFun = Functions.GetProcAddress(libHandle, nameof(PluginTick));
        if (tickFun != IntPtr.Zero)
        {
            _tick = (PluginTick)Marshal.GetDelegateForFunctionPointer(tickFun, typeof(PluginTick));
        }

        IntPtr fixedTickFun = Functions.GetProcAddress(libHandle, nameof(PluginFixedTick));
        if (fixedTickFun != IntPtr.Zero)
        {
            _fixedTick = (PluginFixedTick)Marshal.GetDelegateForFunctionPointer(fixedTickFun, typeof(PluginFixedTick));
        }

        IntPtr lateTickFun = Functions.GetProcAddress(libHandle, nameof(PluginLateTick));
        if (lateTickFun != IntPtr.Zero)
        {
            _lateTick = (PluginLateTick)Marshal.GetDelegateForFunctionPointer(lateTickFun, typeof(PluginLateTick));
        }

        IntPtr sceneLoadedFun = Functions.GetProcAddress(libHandle, nameof(Helper_SceneLoaded));
        if (sceneLoadedFun != IntPtr.Zero)
        {
            _sceneLoaded = (Helper_SceneLoaded)Marshal.GetDelegateForFunctionPointer(sceneLoadedFun, typeof(Helper_SceneLoaded));
        }
    }