/// <summary> /// Detects whether the <see cref="DllManipulatorScript.Options"/> have changed, both relative to the previous /// options and the <see cref="DllManipulator.Options"/> if we are currently initialized. /// </summary> /// <param name="t">The OnInspectorGUI target</param> private void DetectOptionChanges(DllManipulatorScript t) { // Set the target as dirty so changes can be saved, if there are changes if (GUI.changed) { if (!t.Options.Equals(_prevOptions)) { // If the options have changed then update the _prevOptions and notify there are changes to be saved // CloneTo is used to ensure a deep copy is made t.Options.CloneTo(_prevOptions); EditorUtility.SetDirty(target); } } // Allow Reinitializing DllManipulator if there are changes if (DllManipulator.Options != null && !t.Options.Equals(DllManipulator.Options)) { if (DllManipulator.Options.loadingMode == DllLoadingMode.Preload) { if (GUILayout.Button(REINITIALIZE_WITH_CHANGES_PRELOADED_GUI_CONTENT)) { t.Reinitialize(); } } else if (GUILayout.Button(REINITIALIZE_WITH_CHANGES_LAZY_GUI_CONTENT)) { t.Reinitialize(); } } // When enabling enableInEditMode for the first time, allow immediately initializing without waiting for OnEnable if (DllManipulator.Options == null && t.Options.enableInEditMode && !EditorApplication.isPlaying && GUILayout.Button(INITIALIZE_ENABLED_EDIT_MODE_GUI_CONTENT)) { t.Initialize(); } }
/// <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"); } }