Namespaces in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
alright let's test this game out first off press play fill in this keypad nice hmm that is a lot of class files what am I gonna hey look who it is hey Jason how's it going hey brows yeah pretty good I had a free moment I'll give you a shout see how you're doing oh nice well you've got some perfect timing why is that having more trouble um well I think so but I'm not really sure if it's a problem or not okay go on show your screen I'll have a look sure all right so here's my project is this isn't Project you showed me a few weeks back yeah it is actually I'll be honest I'm surprised to see you're still working on it you know what Charles said the same thing just last week well you do go through an awful lot of prototypes that's true but I'm really trying to finish this one yes let's go better learn to be on earth there's a lot of things to consider that only really come into play once a project starts to mature yeah well funnily enough that's exactly why I need your help here take a look at my scripts folder yeah that's a that's an awful lot of class files yeah I was thinking the same thing have you tried organizing them yet to be honest no I'm not really sure where to begin yeah I can understand when there's this much to work with they can get a bit overwhelming we can step through it together if you want yeah that'd be great but what do we start have you set up a root namespace for your project yet yeah I actually have here them show you a lodge open up the project settings good I can see you filled in the root name space under the sea chef project generation right Charles told me I should do that so all my scripts can live under the same custom namespace yeah exactly and we can actually the same thing with your code editor too all right right so what you're gonna want to do is go to the Explorer window and change it to the solution view it should be in the top corner there okay right next you want to right-click on the assembly project and select properties mm-hmm these settings are for unity and writer right yep they tell unity to use the root namespace when it generates code and right it uses it for its intellisense gotcha that makes sense and by the way you don't really need to set up a root namespace to organize your project but it's good practice hmm you know I actually kind of like it makes me feel legit well yeah there's that too so now on to the hard part I guess right yep right now it's time to organize your project which we'll do with a few well-placed directories and namespaces wait more namespaces yep more namespaces hmm that's funny apart from the room I always thought namespaces were overkill in unity in fact I heard that they shouldn't even be used in game development unless you're writing a library yeah I strongly disagree with that that's a common misconception a lot of projects are so small that they can get away with storing all of their class files in one place but namespaces are not just for organizing your project structure really well for one they can be used to divide your project into separate assemblies and your code will actually compile faster huh I did not know that and on top of that too they can also reveal a lot about a project in general like it'll kind of indicate what a program is intent was and you can highlight where there are certain code smells to deal with Wow and here I was thinking they were just glorified directories well they can be if you're not careful the main idea is to use namespaces to define meaningful system boundaries to write your source code this will lead to a project that's easier to maintain scale and most importantly understand roof that sounds like a lot but excited to see what we can come up with yeah okay let's get started let's have a look at your scripts folder to begin okay okay so first of all describe this code to me what does it do hmm well I think about it right now there's a couple of interactable objects all of my keypad logic and a couple of classes to manage the state of my doors and a digital clock okay let's start with that keypad seems like a great place to draw a boundary okay so create a directory called keypad and that'll be your first name space okay and then just dragging my keypad classes well not just that you're gonna have to update the namespaces on each of those files to move every single one yes every one of them but don't worry there's a nice little shortcut for that in writer is right click on the keypad folder and select refactor this another refactor tab you can select adjust namespaces it'll do it automatically for you nice well that's got a lot better already yeah it's a good start next let's move on to your interactable objects okay that should be easy enough all I need to do is create a folder called interactable x' dragon my interactable object glasses adjust the namespaces and voila wow this is actually pretty easy okay not bad but don't get ahead of yourself we've created two well-defined namespaces but you haven't drawn enough of a boundary between them ah shoot really mm-hmm let me show you what I mean right go ahead and open up that key class okay now have a look at that using statements do you see the references to interactable oh right because the keypad class implements I interactable hmm that feels off what you're experiencing now is called a code smell there's nothing inherently wrong with this code but something is prompting you to take a closer look right I mean I guess it would be okay if the key class reference the interactable x' namespace right yeah you could do that but then you'd lose the ability to separate them into their own assemblies which may or may not be an issue hmm this is tough yeah it can be but there's no right or wrong answer you know is iterate your project and change it as it grows okay that makes me feel a little better but I think I'm gonna have to follow your lead on this one no problem okay so I get the feeling that you're probably going to use this I interactable interface a few more times throughout your project which means it may be exposed to a few more namespaces as well yeah I think that's fair to say so in one way you could say it's sort of part of your your project's core functionality exactly right so why don't we make a new directory call it corn and hold all of the core items of your project oh yeah that makes sense that actually sounds like a really good compromise right now it consists of the interactable interface and I'm guessing probably the player related stuff too good I'd say your project is about ready to start taking advantage of assemblies Wow already sure we're gonna save that friend of the day because now it's time for a few rounds of veterans oh no way you got a beta code yep but I only have to watch about 30 hours of streams to get one oh yeah here let me save up and I'll call you back when I'm in the game a special thanks to my top supporters burgers 3d dark brush photography jota's ol our star Thomas Tron Jakub a safari and iron Alex thanks guys [Music]
Info
Channel: Infallible Code
Views: 26,847
Rating: undefined out of 5
Keywords: How to Use Namespaces in Unity, how to use namespace in unity, namespaces in unity, namespace in unity, how to uise namespaces in unity, unity namespace tutorial, unity namespaces tutorial, unity3d programming tutorial, programming tutorial unity3d, unity programming tips, unity programming c#, unity programming c# tutorial, unity c# programming tutorial, unity tutorial, unity3d, unity 3d
Id: vLrGdx-Ob3g
Channel Id: undefined
Length: 7min 5sec (425 seconds)
Published: Sun Apr 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.