Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411499 Posts in 69373 Topics- by 58428 Members - Latest Member: shelton786

April 25, 2024, 09:22:29 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)ELI5 - Unity and C# (.NET versions, build targets, mono, etc.)
Pages: [1]
Print
Author Topic: ELI5 - Unity and C# (.NET versions, build targets, mono, etc.)  (Read 1733 times)
crusty
Level 2
**



View Profile WWW
« on: January 22, 2015, 01:09:28 PM »

Hello everybody.

I'm hoping to start an "explain like I'm five" thread regarding C# scripting inside Unity.  I am asking these questions here because when I look for the answers on google I just get more confused.

environment info:
I am using Unity 4.6 and writing C# scripts in MonoDevelop 4.0.1.  I have classes which are not descendants of MonoBehaviours, but ultimately all of my game logic is tied to update loops inside script components attached to GameObjects in Unity scenes.

I am now 5 years old please be nice Embarrassed. Here are the questions:

1) Today I wanted to use a Dictionary that would use a pair of Objects as the key.  Instead of writing a wrapper class for this specific purpose and defining the hash code myself, I hoped to find a generic solution.  Online I see that .NET 4.0 has a generic Tuple class.  But my compiler says this data structure doesn't exist.  How do I find what version of .NET am I using?  Is it possible to change this version to 4.0?  If I am already using 4.0, what import statement do I need?

2) I don't like MonoDevelop.  Is it possible to set up my project in Visual Studio (and still have in-editor step-by-step debugging)?

I will add more questions as I think of them.  If anyone else has questions please feel free to ask them.
Logged

Caravan: devlog | website
Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #1 on: January 22, 2015, 02:18:00 PM »

1. The version of .NET supported by the Mono included in Unity is 3.5 at most. However, for this purpose .NET has for a long while had a different class that you might like, the Dictionary class! It works like this:

Code:
var dict = new Dictionary<string, string>();
dict.Add("my key", "my value");

var myValue = dict["my key"];

Check out the MSDN page on it here: https://msdn.microsoft.com/en-us/library/xfhwa508%28v=vs.110%29.aspx
Internally this will call GetHashCode() on the object you put into the key. For your own classes and structs you will probably have to implement your own version of this, but for most basic .NET value types (int, string, DateTime) it's implemented for you.

2. Yes you can! Especially since Community Edition of visual studio came out which supports extensions without having to get professional edition. As well, Microsoft bought the UnityVS plugin and made it available for free, check it out here: http://unityvs.com/
Logged
crusty
Level 2
**



View Profile WWW
« Reply #2 on: January 22, 2015, 02:41:35 PM »

Hey thanks for the replies!  So I guess I won't get .NET 4.0, but that still doesn't answer my question of where I can find what version I am using and how to change it if I so wished.

Also, in regards to the Dictionary answer I wanted a

pair of Objects as the key

So I really want the dictionary to create a hash of the two Object hashes.  Which you can sort of hack by doing this:

Code:
Dictionary<Thing1, Dictionary<Thing2, Value>>

but it requires some extra wrapping paper to make adding and retrieving values not ugly.

Thanks for the Visual Studio link!
Logged

Caravan: devlog | website
Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #3 on: January 22, 2015, 03:30:29 PM »

So I can better help you with the problem, for what reason are you looking for 2 different objects as keys?

Edit:
Also it is not possible to change the version of .NET Unity supports. Unity includes a very old version of Mono which only supports 3.5.
« Last Edit: January 22, 2015, 03:51:55 PM by Layl » Logged
crusty
Level 2
**



View Profile WWW
« Reply #4 on: January 22, 2015, 05:32:59 PM »

Actually I already have an answer!  Somebody in the post below suggests a bitwise XOR to combine two Objects' hash codes.

http://stackoverflow.com/questions/689940/hashtable-with-multidimensional-key-in-c-sharp

I am more interested in this Mono stuff you are talking about.  What is Mono exactly?  And what is .NET for that matter?  Are they both code libraries?  Does Mono have a dependency on 3.5 -- like 3.5 is included inside Mono? -- or is it more like Mono calls functions in the latest .NET but can only use ones that existed at or before 3.5?

Sorry they never taught me this stuff in school
Logged

Caravan: devlog | website
Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #5 on: January 22, 2015, 05:48:25 PM »

The ".NET Framework" is created by Microsoft, it includes the .NET Runtime (also called Common Language Runtime) and the .NET Framework Class Library (the classes that are in the System and friends namespaces). What Mono does is provide an open source alternative for running and compiling in ways compatible with .NET.

Because Mono is extremely cross platform it is often picked instead of the .NET Runtime for embedding in game engines. However, lately Microsoft has been moving towards open-sourcing and enabling cross platform usage of the .NET Runtime.

Mono does not have a dependency on anything related to the .NET Framework. The problem that Unity has is that it's using a very old version of Mono which only implements up to 3.5 of the .NET FCL and runtime. They are working on improving this but it may take a while.

Keep in mind with that stackoverflow answer that you need to implement the equality operator, the Equals function and GetHashCode for this.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic