create your own

Unity3d 2.5 and Visual Studio 2008 Express, Professional

81
rate or flag this page

By adambarker


Overview

Unity's excellent 3D games development platform is gaining ever increasing popularity - ever more so with the recent release of version 2.5, including support for Windows.

Much of Unity3d's success is owed to its support for multiple scripting languages. This article is about increasing the support for C# inside Visual Studio 2008.

Visual Studio 2008 is available in many editions, including perhaps most importantly a free version called Visual Studio C# 2008 Express. You can download it here: http://www.microsoft.com/exPress/download/#webInstall

I've created a Visual Studio 2008 Project Template which will allow you to create projects within Unity. The template is essentially a cut-down version of the built-in class library. Additionally, the template references the Unity3d engine library giving you full Intellisense of the engine object library.

You can download the project template file from here: http://files.q-state.co.uk/unitylibrarytemplate.zip

You need to save this file, in it's ZIP form, in the following location: C:\Users\<username>\Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual C#

Creating a UnityLibrary project from the template
Creating a UnityLibrary project from the template

Create the project under the Assets folder of your Unity project. In Visual Studio 2008 C# Express, create the project first and then save the project as a secondary step.

It's optional whether you create a directory for the solution file, which isn't strictly needed. If yo have multiple solutions for script files and you want to keep them formally organized, this may be a good idea.

As mentioned, the template is a cut down standard C# class library. This template gives you a basic 'script' file to get started with. Most importantly the project is referencing the UnityEngine.dll and has a 'using' statement baked in. The MyScript class itself is inheriting from MonoBehavior.


The UnityLibraryTemplate files
The UnityLibraryTemplate files

You can see above the layout of the template:- class and script files are kept under the CustomScripts folder but you can of course add as many subfolders as necessary to keep things organised.

Optionally remove the bin and obj folders.
Optionally remove the bin and obj folders.

As we won't actually be building anything in Visual Studio, we don't need to keep the bin and obj folders. You can remove these from the Assets/Solution folder.

The solution in Unity3d
The solution in Unity3d

Unity3d has a file-watcher running on anything under the Assets folder, so your solution's folder structure should be visible when you switch back to your project. You can see the MyScript class along with the C# project and solution files.

It would be nice to hide the project and solution files but I couldn't find a way to do this. Technically the solution file (UnityLibraries, in this example) is not needed but it does give you a neatly organised way to work with the code structure outside of Unity if needed.

Additionally, double-clicking a script file will open it in the default editor, or a new instance of VS2008 if you specify so in Unity's preferences. Ideally you want to use the same instance of VS2008 to modify and work on scripts, so use ALT-TAB to switch to VS instead of double-clicking script files in Unity3d.

Print   —   Rate it:  up  down  flag this hub

Comments

RSS for comments on this Hub

jorge.castro  says:
5 months ago

Tanks for the template.

And for non "c:\program files" system, i suggest to change the line 40 of UnityLibraryTemplate.csproj for:

<HintPath>$(ProgramFiles)\Unity\Editor\Data\lib\UnityEngine.dll</HintPath>

Aglet  says:
2 months ago

Great tutorial I must say. I've been missing the intellisense from VS.

And thanks to jorge for the path heads up.

darkmessiah  says:
3 weeks ago

The newest version of Unity3d(2.6) now has an option to sync to VS Express, under the assets menu. Your VS project is in your Documents folder now.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working