UnityProjectTemplatesAndSnippets
UnityProjectTemplatesAndSnippets copied to clipboard
MonoBehaviour Editor script template
The goal of this template is to create a CustomEditor script file to extend an existing MonoBehaviour Script.
this is a Rough, likely not working outline of this editor script. I'm having issues building on my machine: type or namespace 'EnvDTE' not found, type or namespace 'EnvDTE80', not found, and type or namespace 'Microsoft.VisualStudio' not found. Do I test this some other way than just pressing play? I'm happy to clean this up myself if I can get it working on my machine.
What Needs Work?
- Test that given a filename like "Foo.cs", it creates a file named "FooEditor.cs", the class name is "FooEditor", but the script itself is referencing the external Foo.cs class. Undesireable behavior: trying to name the file FooEditor.cs and ending up with a file named FooEditorEditor.cs.
- I've included the "self" variable and setter pretty arbitrarily, because that's what I do for my workflow. Maybe that shouldn't be in the final version. My argument for it is that it helps explain how the editor script works for someone who hasn't touched one in a while, just like including the pretyped Start() and Update() messages in the monobehaviour script
Should this be a snippet?
When I create an editor script, it is to extend an existing MonoBehaviour I already have. I don't know anything about how snippets work so I'm not sure if creating an external file is even possible, but it seems like it might be more intuitive, and could sidestep the above file naming confusion.
The other issue with using a snippet is specifying a file location to create that new file in. all editor scripts need to be in a subfolder named "Editor" somewhere in the tree, and different developers put "Editor" in different places. for example given the directory Assets/Scripts/Player/PlayerController.cs
, do you create the editor script in Assets/Scripts/Player/Editor/PlayerControllerEditor.cs
or in Assets/Scripts/Editor/Player/PlayerController.cs
? I think it would be bad to automatically create the script in a specific directory the developer maybe doesn't even want. Is there a way to prompt for a file location when adding the snippet?