Visua Studio2008 to become the perfect Unity Script Editor

The use of Unity projects set up C # script

Open VS2008, in the document> open> select Unity web project folder. At its “management program resource manager” in the new bin file. At bin file right-click on select “Add Reference”, url:" Unity \ Editor \ Data \ Frameworks \ UnityEngine.dll"

Now,containing auto-complete the perfect grammar editor was born. :smile:

See also Setting up Visual Studio for Unity :wink:

Some of that is only relevant for using Visual Studio in a Mac environment - but I guess there’s also quite some useful info for using Visual Studio with Unity on Windows.

Can you write backend libraries in C# and access them from Unity? Do they have to be in Mono?

Going from OOP based XNA to a scripting model where scripts are attached to objects is hard to comprehend sometimes. I’m sure I’m over complicating it in my head…

Yes.

No.

Well, the thing is: Mono perfectly runs .NET assemblies compiled with Visual Studio. You may be a little careful with the .NET version, though. Unity 2.5 still has Mono 1.2.5 which is “about equivalent” with .NET 2.0 (with a few limitations and bugs).

At some point in time, Unity will be updated to the most current Mono version but that seems to be a major pain to do - due to some technical magic they’re doing … so, it’s not like they just “plug in” a new version of Mono - they have to do some serious porting there which is why they don’t do it in every “little” minor release (the last couple of “minor releases” I saw were actually “major releases in disguise”) … last time Mono was updated was with Unity 2.0.

Yeah, it takes a little while to get used to - but you’ll probably soon find out that it’s extremely powerful. The way I conceptualize it is that I can simply “extend” the game engine with those scripts. And personally, I really don’t call them “scripts” but “components” (which is what they really are - I think they just call them “scripts” to make people with scripting background feel more comfortable :wink: ).

So, a game object is a composition of a couple of objects (Transform, GameObject, Renderer, your own components). “Composition” in the UML-sense of the term (see, e.g. (ootips) Association, Aggregation and Composition in case you’re not familiar with that).

Now, the really cool thing is that any public member variable of your MonoBehaviour-derived components is accessible and persistent through the editor; so you can tweak parameters even while play-testing the game (the changes made while playing the game are not persistent, though). I honestly couldn’t imagine a better way of handling this :slight_smile:

The component approach is probably one of the best move they could do. It makes for extremely clean design and very reusable code. It’s hard to go back to the old-school models of deep inheritance trees after you get a taste of this…

Note that XNA also uses the Component pattern, but since there’s no IDE that funnels you into using them, it doesn’t come naturally as in Unity. And, of course, Unity has a lot of sugar in its basic MonoBehavior whereas in XNA it’s pretty bare-boned IIRC.

You mention that it’s possible to access an external C# object from Unity. Two questions:

  1. How? do you have a simple example or can you point me to one?

  2. Can this be used to make dynamic decisions at runtime from within a Unity script or is it static and needs to be hard coded at compile time within unity?

Thanks :slight_smile:

For static external libraries, I think you drop the DLLs into the Assets folder and they will be included in the build.

For dynamic libraries, load them using Assembly.Load or LoadFile, instantiate classes using reflection, and access the instances using reflection (slow) or a common plugin interface.

Google “plugin pattern C#” and read up on different approaches; most of them should be applicable to Unity.

  1. Just use the corresponding .NET assembly within your C# script file

  2. dynamic decisions? what kind of dynamic decisions? you can do whatever you could do within regular C# with it as long as you only use whats supported in mono 1.2.5

Thanks guys. I’ve been writing C# code for 6 years and it’s embarassing how I get glassy eyed when using Unity. I think one problem was the whole Mac/Windows thing. I think then I thought I had to write it all in Mono or else how would Windows compiled .NET assemblies run? But now that it’s native on Windows (Unity) I have no excuse, I just need to spend more time with the engine.