.Net access

I read in some post on the forum about being able to access the .Net libraries from Unity without having to write any .Net specific plugins (for example for XML) but I cannot find anywhere in the documentation on how to do this. Does anyone have an example or some reference they can point me to?

Thanks,

– Clint

Just add a “using [library];” to the top of you script. E.g. using System.Xml; if you want the XML library.

(This is C# syntax, if you use JS I think that it’s import instead of using.)

Cool thanks!

Is there a list of the libraries that can be accessed and their methods, etc.?

– Clint

MSDN has a fairly complete reference: Technical documentation | Microsoft Learn

Unity has most of the System namespace available. Except GUI stuff like System.Drawing and window forms.

Great thanks! :slight_smile:

Anyone have an example of using the XML or File library?

I am starting to work on it but am not really sure… Do I need to create an instance of File and XML prior to using them or just can I access them directly?

I was trying to access them directly but am getting an error that is saying Unknown Identifier: ‘File’

The code I threw together real quick is:

import System.IO.File;
import System.Xml;

function Start(){

	var xmlText = "test.xml";
	
	if (File.Exists(xmlText)){
	
		var txt = File.OpenText(xmlText);
	
	}

}

Any ideas?

Thanks,

– Clint

You have to import the namespace that contains the class, not the class itself:

import System.Xml;
import System.IO;

function Start(){
	var xmlText = "test.xml";
	
	if (File.Exists(xmlText)){
		var txt = File.OpenText(xmlText);
	}

}

Actually the import is just a convenience feature. You can if you want, just specify the full name instead:

function Start(){
	var xmlText = "test.xml";
	
	if (System.IO.File.Exists(xmlText)){
		var txt = System.IO.File.OpenText(xmlText);
	}
}

Okay cool. :slight_smile:

Thanks,

– Clint