Skip to content
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

Allow using Unity script templates in Rider #232

Closed
van800 opened this issue Sep 14, 2017 · 8 comments
Closed

Allow using Unity script templates in Rider #232

van800 opened this issue Sep 14, 2017 · 8 comments
Milestone

Comments

@van800
Copy link
Contributor

van800 commented Sep 14, 2017

We need some understanding if ppl use them outside UnityEditor.
Maybe we can provide them/similar directly in Rider?
Also people may need a helper to update Unity templates or just help to find where are they located.

@van800
Copy link
Contributor Author

van800 commented Sep 14, 2017

@jcx
Copy link

jcx commented Sep 14, 2017

in unity, there are just 2 default script templates and it's for the basic MonoBehaviour and ScriptableObject

there is also free asset made by unity but it's outdated so it shows error and you need to install it after you create projects so it's pretty annoying and I stopped to use it a long time ago

I also made class creator but similar problem - need to install it to every new project

also you can make your own templates and put them together with the default but the problem is, it's in unity installation directory for example "c:\Program Files\Unity20171p1\Editor\Data\Resources\ScriptTemplates.." and that's bad ... if you do need update unity often (and it's actually everybody who's not finishing huge project) ... then you just resign on that

anyway as dev you mostly need the MonoBehaviour and the ScriptableObject and we can type so why do I bother, right? :D

BUT if you need Editor or EditorWindow you have to do it from the scratch and if you don't make tools on daily basis you need to go to reference and just copy it

what unity needs is possibility to create scripts from template stored elsewhere then in the installation folder and actually the best way to create scripts is outside of unity because unity recompiles the project after you change something in it so the way of creating scripts in IDE is the best, because you create script, name and edit it and then save and switch to unity to recompile

unityVS can create scripts but also just MonoBehaviour and ScriptableObject (even if they claim it's editor script, it's SO) ...

what I expect from the template is:

  1. change the class name
  2. selecting methods I want to create in it
  3. some basic attributes (like Editor connection to its component or ScriptableObject and EditorWindow connected to its menu path
  4. it would be really nice to be able to create more class files at once (that's what my tool does)

@van800
Copy link
Contributor Author

van800 commented Sep 14, 2017

@jcx Thanks much!
As for multiple classes at once feature, it is hard to think about such feature without more details. Maybe to avoid much writing you don't mind sharing a screencast?

@jcx
Copy link

jcx commented Sep 21, 2017

I thought about it and I guess my idea is pretty complicated for the usual user. The way I am thinking we could get to UML and it's completely different topic.

I guess the usual templates would work just fine and all I need is more of them than just the 2 basic runtime classes.

@citizenmatt citizenmatt mentioned this issue Sep 22, 2017
5 tasks
@citizenmatt
Copy link
Member

I've made a start supporting ReSharper's templates in Unity - see #237. It doesn't quite match what's here, but it's a good start. For example, ReSharper's templates are available in Rider, but there isn't a UI to edit and customise them yet. They also don't have the ability to start a wizard, so the idea of choosing what methods to implement won't work - but it will create a script, and position you where you can then invoke the generate menu and generate the methods you need.

I'm planning on recreating the existing Unity templates first, as listed in the PR. But once the infrastructure is in place, we can customise them, e.g. by creating a "Unity Script", you could get a C# file where the classname matches the filename, and then gives you an editable base class, with a drop down of classes that derive from MonoBehaviour or ScriptableObject. And the next step is Live Templates - text snippets inside the class as you're editing it.

But looking at the requirement for attributes, would this be better with a context action (i.e. hit Alt+Enter on an existing class name)? This could be an action on a type name that shows "Create CustomEditor" and it would create a new class in the same file, and add a [CustomEditor] attribute to the original type?

Not sure what you'd need for EditorWindow, though.

@jcx
Copy link

jcx commented Sep 22, 2017

The problem with editor classes is they have to be in Editor directory, you can have more of them but basically, it's a different project. I saw editors scripts outside of the Editor directory but it might confuse teammates.

for EditorWindow you need just ...
public class ClassName: EditorWindow
{
[MenuItem("MenuPath/Button Label")]
static void Init(){ }
void OnGUI(){ }
}

and maybe some selectable methods like OnFocus/OnLostFocus OnHierarchyChange etc.

@citizenmatt citizenmatt added this to the Rider 2017.2 milestone Oct 2, 2017
@citizenmatt
Copy link
Member

The next Rider 2017.2 build will include some Unity file templates, based on the default Unity templates. You can see them here.

There are a couple of limitations with this first version - Rider doesn't yet have a UI for editing the templates, although you will be able to edit them with ReSharper. And secondly, there's an issue with grouping - a template for use in the Editor folder appears in a different group in the UI (see RIDER-10132 for more details). Both of these are in the plan for Rider 2017.3.

Would appreciate feedback once it's available (probably next week). I'm going to close this issue for now. Feel free to create new issues about the new templates, or suggestions, etc.

@jcx
Copy link

jcx commented Oct 7, 2017

good start, at least one doesn't need to go to unity, create, rename, wait for refresh (big project = long refresh) just to be able to type code to empty class

thanks guys

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

No branches or pull requests

3 participants