Alternative code completion of the initialization statement or custom postfix templates?

Answered

Unity user here :)

Just wondering if it's possible to add alternative code completion of initialization.

Like, instead of _body = new Rigidbody(); i'd like to have _body = GetComponent<Rigidbody>();

I'm a fan of templates and already have "gc" template for "GetComponent<T>();" 

Unfortunately it's not possible to get variable type in surrounding template or create custom postfix like alternative to ".new". 

Am I missing something?

 

 

3 comments
Comment actions Permalink

Hi Andrew! 

Could you please provide an example of what exactly do you type before completion? 

An example of the second case will also be appreciated. You can attach s code sample or a screencast. Thank you in advance.! 

0
Comment actions Permalink

Hello Alexandra 🙂

oh my, I found the solution while writing this response! 😀

just figure out that it's possible to assign some macro to variable in template, "guess type expected at this point" makro works perfect!

 

But it would be cool to have alternative initialization prompt in Rider anyway, so that's what I meant:

Let's say I have _guid field declared in code

when I write "_guid = " popup appears with bunch of initialization options, and the first one will be "new GuidComponent();".

Rider knows the type of the property so it would be cool to have  GetComponent<GuidComponent>() suggestion if type is derived from MonoBehaviour.

 

I just noticed that whit Ctrl+Shift+Space popup is changed with Unity specific suggestions

but type of the component is not filled automatically, so "guess type expected at this point" for those will be nice

 

0
Comment actions Permalink

Andrew, 

thank you for the details! We have an issue for GetComponent code completion on our bug tracker. We would appreciate it if you would upvote the issue in order to demonstrate additional interest.

0

Please sign in to leave a comment.