Ejemplo n.º 1
0
        public static void OnBeforeDllUnload(NativeDll dll)
        {
            var unityPluginUnloadFunc = new NativeFunction("UnityPluginUnload", dll)
            {
                delegateType = typeof(UnityPluginUnloadDel)
            };

            DllManipulator.LoadTargetFunction(unityPluginUnloadFunc, true);
            if (unityPluginUnloadFunc.@delegate != null)
            {
                ((UnityPluginUnloadDel)unityPluginUnloadFunc.@delegate)();
            }
        }
Ejemplo n.º 2
0
        public static void OnDllLoaded(NativeDll dll)
        {
            if (_unityInterfacePtr == IntPtr.Zero)
            {
                return;
            }

            var unityPluginLoadFunc = new NativeFunction("UnityPluginLoad", dll)
            {
                delegateType = typeof(UnityPluginLoadDel)
            };

            DllManipulator.LoadTargetFunction(unityPluginLoadFunc, true);
            if (unityPluginLoadFunc.@delegate != null)
            {
                ((UnityPluginLoadDel)unityPluginLoadFunc.@delegate)(_unityInterfacePtr);
            }
        }
Ejemplo n.º 3
0
        public static void OnDllLoaded(NativeDll dll)
        {
            if (_triedLoadingStubPlugin && _unityInterfacePtr == IntPtr.Zero)
            {
                return;
            }

            var unityPluginLoadFunc = new NativeFunction("UnityPluginLoad", dll)
            {
                delegateType = typeof(UnityPluginLoadDel)
            };

            DllManipulator.LoadTargetFunction(unityPluginLoadFunc, true);
            if (unityPluginLoadFunc.@delegate == null)
            {
                return;
            }

            if (!_triedLoadingStubPlugin)
            {
                try
                {
                    _unityInterfacePtr = GetUnityInterfacesPtr();
                    if (_unityInterfacePtr == IntPtr.Zero)
                    {
                        throw new Exception($"{nameof(GetUnityInterfacesPtr)} returned null");
                    }
                }
                catch (DllNotFoundException)
                {
                    Debug.LogWarning("StubLluiPlugin not found. UnityPluginLoad and UnityPluginUnload callbacks won't fire. If you didn't install UnityNativeTool from .unitypackage or it didn't contain the compiled plugin, you'll need to compile it manually. You may also comment out this warning if you don't care about these callbacks.");
                }
                finally
                {
                    _triedLoadingStubPlugin = true;
                }
            }

            if (_unityInterfacePtr != IntPtr.Zero)
            {
                ((UnityPluginLoadDel)unityPluginLoadFunc.@delegate)(_unityInterfacePtr);
            }
        }