I apologize if this is something that is easily searched, but I'm not really sure what the correct search terms are for this.
I am using Visual Studio right now, primarily for Unity development. When creating a new script, I often declare a some private member variables like this:
private Rigidbody _rigidbody;
private SomeOtherComponent _myComponent;
In order to initialize those variables, I need to add a GetComponent call in a function called "Start", like this:
void Start(){
_rigidbody = GetComponent<Rigidbody>();
_myComponent = GetComponent<SomeOtherComponent>();
}
Right now, I've found a Visual Studio snippet to quickly type the "GetComponent" part, which is nice, but I'm looking for a way to auto-generate the lines of code in the Start function. In an ideal world, I could type in
private Rigidbody _rigidbody;
then I could hit some key-combination, and it would automatically add
_rigidbody = GetComponent<Rigidbody>();
To the Start function.
Snippets only get me halfway there. What would I need to do to create this type of extension for Visual Studio? Is this a difficult thing to accomplish?
You can try my Visual Commander extension which is designed exactly for such kind of lightweight extensibility. It allows to edit a document as text or use Visual Studio code model and Roslyn.
For example, call the following command when the caret is on _rigidbody or _myComponent in a variable declaration: