-
Notifications
You must be signed in to change notification settings - Fork 19
Enable use outside of play mode #12
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d45bfd
Enables use outside of play mode
rogerbarton c7f9937
Merge branch 'master' into edit-mode
rogerbarton 0b77423
Add enableInEditMode, improved and tested execute in edit mode
rogerbarton 3bc630b
Update scripts/Editor/DllManipulatorEditor.cs
rogerbarton c95ef29
Review fixes
rogerbarton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
By default scripts outside of Editor folder (like this one) don't have access to UnityEditor namespace, so you should move the implementation there (
maybe sth likeactuallyDllManipulatorEditor(Script)?DllManipulatorEditorseems very appropriate for it).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.
I assume that you mean to merge the two files
DllManipulatorScriptandDllManipulatorEditor. Would it not make more sense to just move theDllManipulatorScriptto theEditorfolder and keep them separate?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.
I don't really want to move the main executable script to Editor folder, because I want it to be able to run it outside editor. I know I said it isn't recommended to publish games with that way, but a quick Build and Run won't hurt.
What I'm thinking now is to move most of the code from
DllManipulatorScripttoDllManipulator(which should really be done anyway) and make separate, dedicated script in Editor folder (or maybe use existingDllManipulatorEditor?). Btw, does a script with[ExecuteInEditMode]have to be somehow instantiated in order to be run? I will look at this more tomorrow.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.
Makes sense. I'd personally keep the custom editor IMGUI code separate.
Yes there has to be an instance for
[ExecuteInEditMode].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.
Do you maybe know if there is a way to bootstrap code in editor, without a script in the scene? Because now that would require instantiating two scripts, one 'normal' and one for editor, with [ExecuteInEditMode]. I remember searching for something like this some time ago, but I think I didn't find anything suitable. For instance, a constructor of a custom editor class get's called automatically, but only when you select the target script. And if there was a way to do that, I could potentially even cease requiring putting my script in the scene at all.
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.
From what I know you always need an instance in the scene (for it to work without any additional scripting by the user). Theres only
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]but that would only be useful when using this tool in play mode.I don't see why you would need two separate scripts, you can use
Application.isPlayingand/or#if UNITY_EDITORin the same script.I guess you can use
RuntimeInitializeOnLoadMethodfor the 'normal' script and add an instance to the scene when you want to use it in edit mode as well? However, why would you not always use the edit mode version (given all the editor parts are in#if UNITY_EDITORso you can still use it in a build)?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.
Because scripts inside Editor folder are compiled into
Assembly-CSharp-Editorassembly and these outside of Editor folder are compiled intoAssembly-CSharpand only the former referencesUnityEditor.dllassembly, so you can't access theUnityEditornamespace in the non-editor scripts, even whenUNITY_EDITORsymbol is specified. You can have custom assembly definition files that alter this behavior, but I don't want to force users to use them.So that's how I remember it working, but now that I check it again I see that
Assembly-CSharpalso referencesUnityEditor.dll. So unless I messed this up, this behavior has changed in some version of unity. And if that's the case, I want be stay compatible with previous versions and not rely on this change.As to the
[RuntimeInitializeOnLoadMethod], attribute:Which means that I can't safety use it, because some user code that uses a DLL could be have been run earlier, which would cause the DLL to be loaded by Unity (mono to be specific), and disallow further unloading.
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.
Fair point, however, I understood it that the Editor folders are just to save you from putting
#ifs and you can still freely access theUnityEditornamespace outside of such a folder. Files in anEditorfolder are not included in a build. So I think it should be fine if we use#ifs and put the script outside theEditorfolder. (citing docs and this from 2015)Regarding the attribute, I think that's because the default load type is after the scene has been loaded. See decompiled ctor below.
So if you specify the
BeforeSplashScreenorBeforeSceneLoadLoadType it might work as intended.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.
I've checked the Unity 2018 and your're right, although not all UnityEditor assemblies are referenced, the core one is and can be accessed. So this may freely stay how you initially proposed, but with
#if UNITY_EDITORchecks.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.
It still hangs there, although it is being guarded below