-
Notifications
You must be signed in to change notification settings - Fork 19
Editor GUI Fixes #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor GUI Fixes #15
Changes from all commits
9263c10
88a8895
34a6b01
74c1c96
87dcb2a
3d11bc8
b478c7b
1a33f4d
39c4fce
5f7b79c
5bda990
66c60cf
a0dc185
e5edbf4
05fc35c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| using System; | ||
| using System.Reflection; | ||
| using System.Collections.Concurrent; | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Linq; | ||
| using UnityEngine; | ||
| using UnityNativeTool.Internal; | ||
| #if UNITY_EDITOR | ||
|
|
@@ -38,6 +38,8 @@ public class DllManipulatorScript : MonoBehaviour | |
| onlyInEditor = true, | ||
| enableInEditMode = false | ||
| }; | ||
|
|
||
| public static ConcurrentQueue<Action> MainThreadTriggerQueue = new ConcurrentQueue<Action>(); | ||
|
|
||
| private void OnEnable() | ||
| { | ||
|
|
@@ -46,7 +48,7 @@ private void OnEnable() | |
| { | ||
| if (EditorApplication.isPlaying) | ||
| Destroy(gameObject); | ||
| else | ||
| else if(_singletonInstance != this) | ||
| enabled = false; //Don't destroy as the user may be editing a Prefab | ||
| return; | ||
| } | ||
|
|
@@ -57,6 +59,11 @@ private void OnEnable() | |
|
|
||
| if(EditorApplication.isPlaying || Options.enableInEditMode) | ||
| Initialize(); | ||
|
|
||
| // Ensure update is called every frame in edit mode, ExecuteInEditMode only calls Update when the scene changes | ||
| if(!EditorApplication.isPlaying && Options.enableInEditMode) | ||
| EditorApplication.update += Update; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doens't just having
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For |
||
|
|
||
| #else | ||
| if (Options.onlyInEditor) | ||
| return; | ||
|
|
@@ -83,6 +90,32 @@ private void Initialize() | |
| initTimer.Stop(); | ||
| InitializationTime = initTimer.Elapsed; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Note: also called in edit mode if Options.enableInEditMode is set. | ||
| /// </summary> | ||
| private void Update() | ||
| { | ||
| InvokeMainThreadQueue(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Executes queued methods. | ||
| /// Should be called from the main thread in Update. | ||
| /// </summary> | ||
| public static void InvokeMainThreadQueue() | ||
| { | ||
| while (MainThreadTriggerQueue.TryDequeue(out var action)) | ||
| action(); | ||
| } | ||
|
|
||
| #if UNITY_EDITOR | ||
| private void OnDisable() | ||
| { | ||
| if(!EditorApplication.isPlaying && Options.enableInEditMode) | ||
| EditorApplication.update -= Update; | ||
| } | ||
| #endif | ||
|
|
||
| private void OnDestroy() | ||
| { | ||
|
|
@@ -92,9 +125,8 @@ private void OnDestroy() | |
| //On Preloaded mode this leads to NullReferenceException, but on Lazy mode the DLL and function would be just reloaded so we would up with loaded DLL after game exit. | ||
| //Thankfully thread safety with Lazy mode is not implemented yet. | ||
|
|
||
| DllManipulator.UnloadAll(); | ||
| DllManipulator.ForgetAllDlls(); | ||
| DllManipulator.ClearCrashLogs(); | ||
| if (DllManipulator.Options != null) // Check that we have initialized | ||
| DllManipulator.Reset(); | ||
| _singletonInstance = null; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows the user to properly toggle enabled in edit mode.