Implemented #242 - Added NodeEditor.OnEnable() #243
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To recap Issue #242: XNode's
NodeEditor
does not have anOnEnable
method like the Unity Editor does. This PR adds anOnEnable
virtual method toNodeEditor
and calls it when the editor is instantiated - for instance, when a graph containing the node is opened, or when the graph window switches to a graph containing the node.I have also deprecated
NodeEditor.OnCreate
as it has been superseded byOnEnable
, which has a name more inline with what I assume most developers would expect. CurrentlyOnCreate
functions identically toOnEnable
.I made a major change to the way editors are cached in order to make
OnEnable
work as expected. XNode stores the type and an instance of everyNodeEditor
it can find inNodeEditorBase
. Keeping the type cached makes sense, as reflection is expensive and it's highly unlikely to change during (Editor) runtime. However, I have added a method that flushes the instance cache (SeeClearCachedEditors
) when called. When a node graph is opened, it is called, and the cache is cleared. This way the required editors for the graph are instantiated, and their editors'OnEnable
methods are called.This is my first every PR on a public repo, I have to admit I'm a little nervous :) I did my best to follow the contribution guidelines, but I saw that
NodeEditorBase
is indented using tabs. I figured I'd leave it alone...