You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Edit options when initialized, Fix cleanup when recompiling (#20)
* Allow editing options when initialized, DllManip has a separate Options copy to DllManipScript
When DllManipulator is initialized we pass a copy of the current DllManipulatorScript options. This allows us to keep editing the options when the manipulator is initialized/dlls are loaded as we are editing a copy. This is particularly useful when using enableInEditMode.
Changes are always applied at OnEnable as before. To allow modifying without play/stop a DllManipulatorScript.Reinitialize() has been added which can be called via GUI (see DetectOptionChanges) which unloads dlls and initializes with new options. GUI is only shown when there are changes.
* Fix OnDestroy not being called when recompiling
When recompiling only `OnDisable` is called, not `OnDestroy`. Now gets the callback for when the assembly is being reloaded, just when finished with compiling. This is called before `OnDisable`, so I just set a flag `_isRecompiling`.
Previously the native function `UnityPluginUnload` was not being called causing various bugs.
* Update scripts/Editor/DllManipulatorEditor.cs
Co-authored-by: mcpiroman <38111589+mcpiroman@users.noreply.github.com>
* Review changes
Also removed check if singletonInstance in Reinitialize as this should never occur
* Small fix
* DllManip.Options private set
Co-authored-by: mcpiroman <38111589+mcpiroman@users.noreply.github.com>
// When recompiling OnDestroy is not called by default (the object is not really destroyed)
147
+
// Manually trigger OnDestroy to clean up if we are disabled because of recompilation
148
+
if(_isRecompiling)
149
+
{
150
+
_isRecompiling=false;
151
+
Reset();
152
+
}
153
+
}
117
154
}
118
155
#endif
119
156
120
157
privatevoidOnDestroy()
121
158
{
122
159
if(_singletonInstance==this)
123
-
{
124
-
//Note on threading: Because we don't wait for other threads to finish, we might be stealing function delegates from under their nose if Unity doesn't happen to close them yet.
125
-
//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.
126
-
//Thankfully thread safety with Lazy mode is not implemented yet.
160
+
Reset();
161
+
}
127
162
128
-
if(DllManipulator.Options!=null)// Check that we have initialized
129
-
DllManipulator.Reset();
130
-
_singletonInstance=null;
131
-
}
163
+
privatevoidReset()
164
+
{
165
+
//Note on threading: Because we don't wait for other threads to finish, we might be stealing function delegates from under their nose if Unity doesn't happen to close them yet.
166
+
//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.
167
+
//Thankfully thread safety with Lazy mode is not implemented yet.
168
+
169
+
if(DllManipulator.Options!=null)// Check that we have initialized
"Mocks native functions to allow manually un/loading native DLLs. DLLs are always unloaded at OnDestroy.";
18
+
"Mocks native functions to allow manually un/loading native DLLs. DLLs are always unloaded at OnDestroy. Configuration changes below are always applied at OnEnable.";
0 commit comments