This is my first contribution to the unity community and I hope it helps you guys.
I will tell you about the things that make me code faster from a programmer’s point of view.
Keep in mind that I’m using JavaScript/UnityScript as my main language for writing scripts.
I’ll try to keep the post short and to the point :).
Look and Feel
-
Get comfortable with Syntax highlighting (choose a theme that you enjoy and good for your eyes)
-
Customize your layout in MonoDevelop. I prefer to have the following options:
-
Search results window in the bottom left → embedding the window enables me to see things quicker than having them interrupt my workflow when i search for things in my solution.
-
Tabs and spaces markers are enabled → because I’m a software engineer which makes me picky about how my code is written and how perfect it should be.
Shortcuts
Not knowing your IDE’s shortcuts is like changing gear by having to look down on the gear every time you shift up or down -_-!
Therefore, you need to memorize some keyboard shortcuts that will make you code faster. Especially if you are using JavaScript/UnityScript as your coding language for Unity.
Find things quickly
- Go To Type: Ctrl+Shift+T. This shortcut is very popular in all IDEs. It allows you to open files/classes quickly without having to navigate through the solution. It also understands CamelCase in search. For example, I want to open a file called CameraFocus.js. I press Ctrl+Shift+T and start typing CFo which gives me all the files that their first word starts with C and second word starts with F followed by a small letter o.
- Search in files: Ctrl+Shift+F. This is a very important shortcut because you can use it to find occurrences of anything in your solution (e.g. variables, methods …etc.)
- Show Next: F4. This goes to the next search match. Useful scenario is that you highlighted a method name and want to find all other classes that are using it, so you search in files and that shows up in your search results window, so then you press F4 and that opens another file and shows you exactly where it’s used. This saves you time from moving the cursor to the next search item and double clicking it.
- Go To Declaration: F12. As name suggests, very useful when you are trying to understand some one else’s code.
- Unity API Reference: I changed it to Ctrl+` instead of Ctrl+’ because then I can do it in one hand
.
Refactor a lot to make your code easier to understand later.
- Extract Method: Ctrl+Alt+M
- Extract Local: I set this manually to Ctrl+Shift+L by going to the key bindings in Preferences.
- Toggle Line Comments: I changed this to Ctrl+Shift+C because it is easier for my hand to reach the Shift key rather than the Alt key. This is totally a personal preference and also depends on your keyboard. This shortcut allows you to quickly comment or uncomment line(s) of code.
General Code Editing shortcuts
- Delete Line: I added this shortcut because its very useful to me. I made it Shift+D. Again focus on doing shortcuts with one hand.
- Switch between open files(tabs): Ctrl+Tab
- Quickly find occurrences of a word in a file: Ctrl+F which is the search in file shortcut.
- Quick renaming of variables in a file: Ctrl+H which is the shortcut for replace. Now MonoDevelop doesn’t seem to have a way to rename a variable/method in its refactoring keyboard shortcuts, which is unfortunate. So to get around this is to do search in files(CTRL+Shift+F) for this variable, and replace occurrences(Ctrl+H) with the name you want, then F4 to go to the other files that have that variable ;).
- Auto Completion: Ctrl+Space I think everyone knows this but I’ll add it anyway.
Ok, I think i’ll stop here. If I keep going I won’t be able to finish in time haha. This should be enough for now. Tell me if you guys want me to explain how I’m using Git as my repository ;).