Skip to content

Edit options when initialized, Fix cleanup when recompiling - #20

Merged
mcpiroman merged 6 commits into
mcpiroman:masterfrom
rogerbarton:fixes
May 6, 2020
Merged

Edit options when initialized, Fix cleanup when recompiling#20
mcpiroman merged 6 commits into
mcpiroman:masterfrom
rogerbarton:fixes

Conversation

@rogerbarton

@rogerbarton rogerbarton commented May 1, 2020

Copy link
Copy Markdown
Contributor
  1. Allows editing options when initialized, this is done by having a separate copy of the Options in the script as in the manipulator. Changes are applied when entering play mode or can be applied immediately. This also avoids bugs when using enableInEditMode and changing the options when already initialized.
  2. Properly cleans up when recompiling, the problem is that OnDestroy is not called when recompiling.

See commit messages for details.

…ns 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.
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.
@rogerbarton

Copy link
Copy Markdown
Contributor Author

PR20-gui-preview

@mcpiroman mcpiroman left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick notes I left here, will have a closer look soon, lgtm though, thanks!

Comment thread scripts/Editor/DllManipulatorEditor.cs Outdated
Comment thread scripts/Editor/DllManipulatorEditor.cs Outdated

// 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))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe move that button to be close to the 'enable in edit mode' option

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean you enable it and this shows up right next to it so that you know you have to click it first for it to work, sth like warning button i guess

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its reasonably clear when the button pops up. If the user immediately clicks the initialize button and then changes the options below they will have to unnecessarily reinitialize. Having the button at the bottom implies that the other options also affect its behaviour.

Also in the code it is clearer as the functionality about re/initializing is together in DetectOptionChanges.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, it looks like Options in DllManipulator can now be private?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use it in the Script and Editor to check if the DllManip is initialized/there are changes to be applied. We could make the setter private?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Comment thread scripts/DllManipulatorScript.cs Outdated
if (_isRecompiling)
{
_isRecompiling = false;
OnDestroy();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like calling a callback method so I'd be after creating separate one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a Reset()

if (DllManipulator.Options != null)
DllManipulator.Reset();

#if UNITY_EDITOR

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if this is not going to actually perform the initialization again, then this method shouldn't be called in the first place (it doesn't actually reinitialize).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've changed it although this requires that the Initialize function is public.

Comment thread scripts/Editor/DllManipulatorEditor.cs
Comment thread scripts/DllManipulatorScript.cs Outdated
if(_singletonInstance != this)
return;

if (DllManipulator.Options != null)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain, but it appears to me that we could reduce the number of different places when options are stored and move them from this class to the DllManipulator itself? TBH I don't really like how it's scattered.

@rogerbarton rogerbarton May 6, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes its a bit scattered but I think this makes sense:

  1. DllManipulatorScript has an Options copy which are seen in the inspector.
  2. DllManipulator has Options which are currently used.
  3. DllManipulatorEditor has Options solely for detecting changes in the inspector.

Each .cs only has to consider one Options (except the editor). Having the previousInspectorOptions from the editor in DM means DM has a copy which it never uses. I would leave it as is personally.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya, sure

rogerbarton and others added 2 commits May 6, 2020 09:39
Co-authored-by: mcpiroman <38111589+mcpiroman@users.noreply.github.com>
Also removed check if singletonInstance in Reinitialize as this should never occur
Comment thread scripts/DllManipulatorScript.cs Outdated
DllManipulator.Reset();
_singletonInstance = null;
}
public void Reset()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one doesn't need to be public right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, its now private


// 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))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

Comment thread scripts/DllManipulator.cs
_customAfterUnloadTriggers?.Clear();
_customBeforeUnloadTriggers?.Clear();

Options = null;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait a sec, what does it do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We delete the DllManip Options copy. This is also used as an indicator to whether the DllManip is initialized.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, how does it consume the options when they are null? Sry if I miss sth

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nvm, on the diff it blended in as though it was called in Initalize, not Reset, sorry

@mcpiroman

Copy link
Copy Markdown
Owner

LGTM

@mcpiroman
mcpiroman merged commit ec2d35b into mcpiroman:master May 6, 2020
@rogerbarton
rogerbarton deleted the fixes branch May 6, 2020 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants