This may seem like a really noobish question but what is the purpose of creating your own namespace and or framework? How would one go about doing this?
It’s really for the sake of having organization mostly, and being able to do a using statement when you use that particular functionality. There’s a little more to it, but basically for keeping a collection of a certain type of asset or tool or something.
There’s tons of examples online, on this forum and elsewhere.
Agree with regard to organization. Keeping similar things grouped. You’ll see it all throughout the .NET library.
Create your own namespace?
namespace MyNewSpace {
public static class ExampleClass{
public static string FloatStr2(this string str, float f){
return f.ToString("F2");
}
}
}
heh.
Everyone else has already mentioned organization, but the second purpose is to avoid naming conflicts. If you have two classes with identical names then the only way to differentiate between them is to give them different namespaces and refer to them through that.
For example there is a Color struct under UnityEngine and another Color struct under System.Drawing. If you wanted to make use of both of them then you would need to refer to them as UnityEngine.Color and System.Drawing.Color. Or with other shortcuts assigned via the using keyword.
Organization. I put test scripts into a TestCrap namespace so I don’t get it confused with anything else. For your personal projects you can just put everything into the global namespace and it’ll be fine, but for libraries that you distribute to other people you really need those to be in other namespaces. For example, if I send you my CharacterController script but you already have a CharacterController script, there’s a conflict. Both cannot be used at the same time if they’re in the same namespace (in this case, the global namespace). I’d have to put my CharacterController in a namespace called Uzi or something to differentiate them.
But in general you don’t need to worry about them when programming Unity.
Thank you all for the replies and the helpful info, I’ve just been seeing it a lot in other peoples work and was curious!