Quantcast
Channel: philippseifried.com » Unity
Viewing all articles
Browse latest Browse all 7

Settling into Unity3D: MonoDevelop Tips and Tricks

$
0
0

When I learn a new platform that comes with a new IDE, new paradigms, a new API and a new programming language, the IDE is usually last on my list. Months after our first Unity project, I still knew very little about MonoDevelop. I’ve finally found some time to dig around in the environment and compiled a little list of small things that can go a long way in increasing your productivity.

I’m on a Mac, so for any keyboard shortcuts I list that use CMD, you’ll probably have to substitute CTRL on Windows. Also I program in C#, so there may be some tips that aren’t applicable to JavaScript.

(Update: I compiled most of these tips into a PDF cheatsheet)

Navigation:

For any Unity type selected in your code, you can press CMD+’ to jump to Unity’s manual page on that type in your browser. No more googling “Unity GameObject”!

Use CMD+Shift+T and type the name of any class to jump to its definition. Use CMD+. for a more general search window that also lets you jump to things like specific methods in any class in the project.

Use CMD+Alt+Left Cursor / Right Cursor to jump around in your navigation history. Your navigation history contains the different parts in different classes where you last edited code. Super-useful when you need to jump back and forth between two pieces of code. You can also use Search/Navigation History in the menu to access your history.

You can select any type in your code and press CMD+D to go to that type’s definition (e.g. in “Player myPlayerInstance;“, select the text “Player” and press CMD+D). You can also do that by selecting a type and right clicking. In the same context menu, you can also get a list of all classes that derive from the type (“Find derived classes“), or a list of all places in your code where the type is referenced (“Find references“).

Use CMD+L to jump to a specific line number in the currently open file.

Not something I use a lot, but you can toggle bookmarks in various places in a file using CMD+*, and then jump back and forth between them (only between those in a single file) using “Search/Previous Bookmark” and “Search/Next Bookmark” in the menu. Bookmarks are handled on a per file basis – going to the next bookmark will only do so in the same file.

Use “View/Pads/Classes” to add a navigation panel which lets you browse your project by packages and classes instead of by folder. Especially helpful for code that contains several classes per file.

 

Editing:

Use Alt+Cursor Up or Alt+Cursor Down to move the line of code you’re in (or a selected code block) up or down.

Use “View/Pads/Task List” from the menu to get a list of any comments in your code containing the words “TODO“, “FIXME“, etc. You can edit the list of keywords listed here in “Preferences/Task List“.

Use “View/Pads/Toolbox” to open a panel containing easily accessible text templates. Add things like new class definitions, compiler directives, or access to the last element in a collection with a double click on the snippet in the panel. If you want to dig deeper, you can edit the templates in “Preferences/Text Editor/Code Templates“. I’d recommend looking at each template once to find out which are useful to you, and then removing some of the clutter from the list. Some of the stuff in there is really neat.

Use the preprocessor directives #region yourRegionName and #endregion to mark regions in your code, for instance to bundle methods that do similar things together. These methods will be shown grouped in the Document Outline on the lefthand side on the screen (in which you can fold and unfold different regions). Once there is at least one region in your document, the right-hand side of the bar above the code editing window will display a drop-down menu, which lets you jump to a specific region.

Like other advanced IDEs, MonoDevelop comes with built in refactoring capabilities: Select the method name in a method definition, or the class name in a class definition, right-click and select “Refactor/Rename“. The new method or class name will be updated in all references throughout your project. There are two more refactoring capabilities I’ve come across that I think are really useful:

If you have private or protected members variables in a class, you can right-click on your class definition and select “Refactor/Encapsulate Fields“, and MonoDevelop will let you choose which of your members it should automatically produce getter and (optionally) setter methods for.

If your class is a subclass of another class or implements any interfaces, right-clicking on your class definition and selecting “Override/implement members” will let you choose from a list of methods that MonoDevelop can automatically produce for you.

You can also right-click on your class definition and select “Show Code Generation Window“, which will offer you some more automatic code generation options, including automatic implementations of constructors and ToString() methods.

 

Editor Preferences:

It always seems a little annoying to poke around for that stuff, but here are a few things I’ve changed in the Editor Preferences, which I think paid off:

Under Preferences/Visual Style/Welcome Page, I deactivated the welcome page.

I don’t (yet?) see a need to build the project in MonoDevelop, and after several times of accidentally hitting CMD+B or CMD+K and starting a build process, I took a moment to remove the keyboard shortcuts from Preferences/Key Bindings.

Also, at least on Mac, the find and replace text functionality doesn’t have a keyboard shortcut by default, so I assigned a keyboard shortcut to “Replace” in “Key Bindings“.

I also assigned Alt+D to “Delete entire line“.

I removed CMD+P to print. No reason for me to ever print code, and it happened more than once that I wanted to Alt+Tab into Unity and CMD+P to play, and brought up the print dialog instead.

Working on a 13 inch MBP, I can use any screen estate I can get, so I assigned Alt+F to “Show Fullscreen“.

On a Mac, holding down CMD and moving two fingers over the touchpad (which emulates a mouse wheel) zooms the text in MonoDevelop in and out, which is annoying because it happens by accident all the time, and you can’t deactivate it. I assigned CMD+0 to “Normal Size“, so I can at least reset it quickly when it happens.

Finally, it’s definitely not your most productive option, but if you’re feeling nostalgic, you can set your editor color scheme to C64 in “Preferences/Text Editor/Syntax Highlighting“.


Viewing all articles
Browse latest Browse all 7

Trending Articles