Exemplo 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)();
            }
        }
Exemplo 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);
            }
        }
        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);
            }
        }
Exemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            var t = (DllManipulatorScript)this.target;

            DrawOptions(t.Options);
            EditorGUILayout.Space();

            var usedDlls = DllManipulator.GetUsedDllsInfos();

            if (usedDlls.Count != 0)
            {
                if (t.Options.loadingMode == DllLoadingMode.Preload && usedDlls.Any(d => !d.isLoaded))
                {
                    if (EditorApplication.isPaused)
                    {
                        if (GUILayout.Button("Load all DLLs & Unpause"))
                        {
                            DllManipulator.LoadAll();
                            EditorApplication.isPaused = false;
                        }
                    }

                    if (GUILayout.Button("Load all DLLs"))
                    {
                        DllManipulator.LoadAll();
                    }
                }

                if (usedDlls.Any(d => d.isLoaded))
                {
                    if (EditorApplication.isPlaying && !EditorApplication.isPaused)
                    {
                        bool pauseAndUnloadAll;
                        if (t.Options.threadSafe)
                        {
                            pauseAndUnloadAll = GUILayout.Button(UNLOAD_ALL_DLLS_AND_PAUSE_WITH_THREAD_SAFETY_GUI_CONTENT);
                        }
                        else
                        {
                            pauseAndUnloadAll = GUILayout.Button("Unload all DLLs & Pause");
                        }

                        if (pauseAndUnloadAll)
                        {
                            EditorApplication.isPaused = true;
                            DllManipulator.UnloadAll();
                        }
                    }


                    bool unloadAll;
                    if (EditorApplication.isPlaying && t.Options.threadSafe)
                    {
                        unloadAll = GUILayout.Button(UNLOAD_ALL_DLLS_WITH_THREAD_SAFETY_GUI_CONTENT);
                    }
                    else if (EditorApplication.isPlaying && !EditorApplication.isPaused && t.Options.loadingMode == DllLoadingMode.Preload)
                    {
                        unloadAll = GUILayout.Button(UNLOAD_ALL_DLLS_IN_PLAY_PRELOADED_GUI_CONTENT);
                    }
                    else
                    {
                        unloadAll = GUILayout.Button("Unload all DLLs");
                    }

                    if (unloadAll)
                    {
                        DllManipulator.UnloadAll();
                    }
                }

                DrawUsedDlls(usedDlls);
            }
            else if (EditorApplication.isPlaying)
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField("No DLLs to mock");
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            if (EditorApplication.isPlaying && t.InitializationTime != null)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
                var time = t.InitializationTime.Value;
                EditorGUILayout.LabelField($"Initialized in: {(int)time.TotalSeconds}.{time.Milliseconds.ToString("D3")}s");
            }
        }
Exemplo n.º 5
0
 public static void UnloadAll()
 {
     DllManipulator.UnloadAll();
 }
Exemplo n.º 6
0
 public static void LoadAllShortcut()
 {
     DllManipulator.LoadAll();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Draws GUI related to the current state of the DllManipulator.
        /// Buttons to load/unload Dlls as well as details about which Dlls are loaded
        /// </summary>
        /// <param name="t">The OnInspectorGUI target</param>
        private void DrawCurrentState(DllManipulatorScript t)
        {
            if (DllManipulator.Options == null) // Exit if we have not initialized DllManipulator
            {
                return;
            }

            var usedDlls = DllManipulator.GetUsedDllsInfos();

            if (usedDlls.Count != 0)
            {
                if (DllManipulator.Options.loadingMode == DllLoadingMode.Preload && usedDlls.Any(d => !d.isLoaded))
                {
                    if (EditorApplication.isPaused)
                    {
                        if (GUILayout.Button("Load all DLLs & Unpause"))
                        {
                            DllManipulator.LoadAll();
                            EditorApplication.isPaused = false;
                        }
                    }

                    if (GUILayout.Button("Load all DLLs"))
                    {
                        DllManipulator.LoadAll();
                    }
                }

                if (usedDlls.Any(d => d.isLoaded))
                {
                    if (EditorApplication.isPlaying && !EditorApplication.isPaused)
                    {
                        bool pauseAndUnloadAll;
                        if (DllManipulator.Options.threadSafe)
                        {
                            pauseAndUnloadAll = GUILayout.Button(UNLOAD_ALL_DLLS_AND_PAUSE_WITH_THREAD_SAFETY_GUI_CONTENT);
                        }
                        else
                        {
                            pauseAndUnloadAll = GUILayout.Button("Unload all DLLs & Pause");
                        }

                        if (pauseAndUnloadAll)
                        {
                            EditorApplication.isPaused = true;
                            DllManipulator.UnloadAll();
                        }
                    }


                    bool unloadAll;
                    if (DllManipulator.Options.threadSafe)
                    {
                        unloadAll = GUILayout.Button(UNLOAD_ALL_DLLS_WITH_THREAD_SAFETY_GUI_CONTENT);
                    }
                    else if (DllManipulator.Options.loadingMode == DllLoadingMode.Preload && (EditorApplication.isPlaying && !EditorApplication.isPaused || DllManipulator.Options.enableInEditMode))
                    {
                        unloadAll = GUILayout.Button(UNLOAD_ALL_DLLS_IN_PLAY_PRELOADED_GUI_CONTENT);
                    }
                    else
                    {
                        unloadAll = GUILayout.Button("Unload all DLLs");
                    }

                    if (unloadAll)
                    {
                        DllManipulator.UnloadAll();
                    }
                }

                DrawUsedDlls(usedDlls);
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField("No DLLs to mock");
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            if (t.InitializationTime != null)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
                var time = t.InitializationTime.Value;
                EditorGUILayout.LabelField($"Initialized in: {(int)time.TotalSeconds}.{time.Milliseconds.ToString("D3")}s");
            }
        }