I asked before… but maybe I didn’t ask in the right way…
so… simply, can we use C# Namespaces in Unity?
Thanks
Shaun
I asked before… but maybe I didn’t ask in the right way…
so… simply, can we use C# Namespaces in Unity?
Thanks
Shaun
Yes, thought you have to do the dummy class to avoid compile warnings, just like with generic and partial classes.
Thanks - I would love to hear from on Unity what their plans are for namespaces, as its a kind of black vice at the moment (for me anyway )
Our devs are building and testing our core classes in Visual Studio as its faster to debug there - we planned to port them straight into Unity as they don’t need to be attached to GameObjects - but it seems that not going to be possible, or at least more difficult.
I’m still not totally clear on why the Class Names have to match the filenames for scripts not attached to game objects?
Well, it probably has to do with how they name the component in the inspector (easier to just use the filename than to parse the file, or query the script engine).
Just a guess though,
-Jeremy
As much as I was trying to avoid it, ive created dummy classes to match the filenames. Its a pretty big mess though, and doesnt let us work easily between Visual Studio and Unity (in the sense that we can develop independently of Unity and merge later)
I really can’t fathom the filenames having to match the classes~(I can see why for scripts linked to GO’s - but not for “standalone” code just used by Mono)
Please tell me this will change in future - it seems uncharacteristically hackish for UT.
if you are talking about plain classes (that don’t inherit MonoBehaviour) you can use name spaces. I develop all plain classes with namespaces in vs and reference them in unity.
Hi Firas,
I have namespaces working now, but I still have to create a dummy class to match the filename, which makes porting them from Visual Studio a pain - the other devs I’m working with don’t use Unity (and only use PC), so they can’t understand why we need dummy classes.
If you’ve found a way around this naming issue, would love to hear it.
Thanks
Shaun
1- what is a dummy class??
2- tell me again if the classes you are talking about are subclasses of MonoBehaviour or not because it makes a difference.
Firas.
if you r not talking about MonoBehaviour sub classes use namespaces and stuff in vs and compile your project into dll’s to be used by unity. the only classes I have in a unity proj that is not in the form of dll’s are MonoBehaviour sub classes.
Hi Firas,
The classes I’m talking about don’t derive MonoBehaviour as they are not attahed to any gameobject (the just do stuff like connect to servers, upload download files, manage a message queue etc)
here’s a sample of what I’m doing now:
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
public class fCEventHandler { }
namespace CMUNEEvent
{
public enum CMUNEEventType
{
AddSN,
}
public class CEventHandler
{
static Queue m_EventQueue= new Queue();
public CEventHandler()
{
}
and so on...
I’m curious how you integrate your DLL’s with Unity - I mean, since they are .NET MSIL assemblies they could be interpreted by Mono and run on both Mac and PC, but I haven’t tried this. It would be a great solution, to abstract the logic from presentation.
Thanks
Shaun