 Howdy guys. All right, so throughout these next few videos what we're going to do is we're going to build an object renamer tool here inside of Unity and This is one of those things that you know I really wish the editor would just come with and you know, maybe there's some version of the tool I just don't know about but I really want to be able to mass name or rename I should say objects inside of the hierarchy because sometimes you end up with a bunch of models and you just want to clean up the naming Conventions form or maybe you actually need to change the convention all together All right, so that that should be easy enough to do and what we're going to do is we're going to write a nice Tool inside of Unity here that will allow us to do that. All right, and it also allow you to extend it So the first thing that I want to do is I want to come in here and add a new folder and I'm going to call this the object renamer All right, and we'll do underscore tool just to stick with my convention here In this project. All right, so underneath that if you've been watching the series here We're going to add that editor folder now. Remember in order to make an editor tool for Unity We have to put all the C-sharp scripts inside of this editor folder. It's a requirement by Unity by the Unity Editor, okay? So inside of that we're going to create a couple scripts. So I'm going to call this the IP Object rename Menu now we're going to store all the menu options inside of this particular script and I like doing this because I like keeping all the the menu options up here In a separate script that I can access and read easily I'm not a big fan of nesting my menu items inside of my actual editor script And you'll see this as we walk through this particular Section of videos here. So the next script I'm going to write is IP object rename. This is going to be called Editor and I'm going to put a capital on that rename there Just to stay professional. All right Cool. So once that's finished compiling there What I want to do is pop open the object rename menu script just so we can get the menu inside of the Indie pixel Drop down up here. Okay, so that's what we're going to do. We're going to add another option to this particular menu item up here All right, so to do that. It's pretty simple I Do not want to give you back right now. I'm right in the middle of video Microsoft All right, so what I want to do is I'm going to put this into the namespace of Indie pixel all right dot tools and That is my namespace that I'm putting all of my tools into All right, so if you're not familiar with namespaces, it's kind of like a folder structure for your particular scripts All right, so I highly recommend watching some of the previous tools that we've made in this whole Series of Unity tools and editor tools All right Because I talk a little bit more about namespaces, but think of it like folders that protects your code from being Clashed with or Imagine a script comes in from like an asset store pack and it's got the same name Where your C sharp script has the same name as a script that comes in that asset pack Unity would throw an error so you can protect your code by putting it into a custom namespace like this All right, so I'm going to get rid of these built-in methods there. All right, and you notice I got rid of the mono behavior Inheritance basically and it's just because I don't really need it for this particular script So and that's because I'm not going to be using this in game So I don't need to inherit any of the functionality that comes with mono behaviors Okay So let's also go and add the using unity editor up here because we're writing editor code here So I usually put the unity editor stuff in there in this case We do actually need it because we want to access the Menu item and we need to put down the two square brackets and we type in menu item All right, and that comes with this unity editor namespace right here All right, so Let's go take a look at the arguments for this menu item and again We need to add the string item name and that's literally the path the folder path Let's jump back in unity here. That's literally the folder path right here So here we have indie pixel then level tools and then replace select object That was the last tool that we made okay, and so what I want to do is put in another option That is rename objects basically and so I'm going to come in here and we're going to say Indie pixel Indie dash pixel all right forward slash level tools like so and rename Objects all right, and you can name that whatever you want All right, so we just need to make sure we put the parentheses right there There we go So now we have a new menu item But what we need to do to make this actually work is we need to provide it a method Directly below it and I'm going to make that a public Static method that way any other editor script that I write can access this particular method without having to Create an instance of it or you know stored in a variable type of thing so Or have multiple of them. I just want to have one of these particular menu items All right, so I'm going to make this method static and I'm just going to call it a rename selected objects like so Okay, so What can we do now so what I want to do actually just to make sure that this works I'm going to do a debug log and I am going to say We are renaming objects Exclamation mark because you always need that Okay, so what I want to do now is go back into unity. Let the script compile All right, so we see it's compiling down here and once it's finished We can go up to the Indie pixel level tools and you can see we now have a new menu item up here And when I click it I Get a readout to the console over here that we are renaming objects So we are in fact calling that method that is directly below this menu item declaration Cool, that means we can now actually launch another script or launch some other functionality from it Or we can have that functionality directly inside of this But again, like I said, I like to keep my menu code separate from my actual editor code because it just keeps it nice and clean All right And that's completely a style thing, you know, I'm sure lots of other people have different ways of doing this I just kind of like to keep those two components separate menus and editors. All right, cool so let's go back to unity and I'm going to go back to the project paying here and open up the Editor version of the object rename code All right, and I'm going to put this into the namespace as well So we're going to do Indie pixel dot tools there we go and I'm going to just make sure that that is fully encapsulated there and What we're going to do I'm going to get rid of these built-in methods because again, we're not going to be using money behavior We're using editor scripts. So money behavior is for runtime stuff So what I'm going to do is I'm going to say you using unity editor All right, and then I'm going to get rid of the money behavior But I do want to actually inherit from Editor window. All right, so this editor window Class comes with this unity editor namespace right here This means now we can create an editor window when we go inside of unity and we click on this option here I can launch a window and it's a custom window just like what we did with the replace selected objects tool Okay, so let's go back to visual studio here and let's actually get this working. So One of the first things that I usually like to do is just set up regions It keeps your code nice and clean. All right, so we're going to do region variables And then we're going to do and I didn't need to do so many steps there. So what we're going to do is a region Built-in methods and we are in fact going to create a custom method as well for this so let's do that and Say and region so this just helps me stay organized with my code I put all my variables in that region and I put all my built-in methods the ones that come with unity All right come with this editor window script Then I put all my custom code inside of this custom code region That just helps me stay organized and you can also go and collapse this stuff too. All right makes it Nice and compact. All right, so let me re-expand these guys All right, so the first thing that I want to do is I want to create a method that I can call from this menu Rename selected objects Method. All right. So when we click on this menu item inside of unity We're going to automatically run this method and whatever code is inside of here is going to launch So that means we need to create a public not a partial. We'll do a public Hold on one sec. There we go static void launch. This is what I'm going to call it renamer Yeah, it'll work for now. All right, so let's do that. So now let's do a debug log For this just to make sure this code is running. So I'm gonna say debug log and we are going to say we launched The renamer window Boat just like that so What we need to do now is we need to go back to our menu script here and I'm going to now call That method so because we made it static remember I can see it now. I don't have to you know create a variable and store This editor script or anything like that. I can just say ip object rename editor dot Launch renamer and voila. We can actually access that code All right. So when we hit this menu item And call this method right here, we're going to then launch the renamer And that's going to fire off the code right here. So we're going to say debug dot log We launched the renamer window. All right. So let's test this out now inside of unity Okay, so I'm going to come up here and go to level tools rename objects and look at that. We are now Launching the renamer window very cool Okay, so before I close out this particular video in this Section, uh, what I'm going to do is actually create the window So I want to launch an actual editor window that we can put Ui into and add buttons and text fields and stuff and let users do something with all that stuff So what I want to do is declare a new variable just a generic variable Using the var keyword. All right, and then what I'm going to do is call this win All right, this is kind of one of those general ways of launching these editor windows Probably more the the most basic way too. So what I want to do is I want to call get window All right and give it a type and that type is going to be This particular script All right, this editor script. I want to launch this window. Think of it like that Okay, and this get window Uh, it's not magic or anything like that. It actually is included inside of this editor window class here That's why we're able to access it because we're inheriting all the functionality from this class That's just you can tell because we're using those two dots there. Okay, so Then what I want to do is I want to say win dot title is equal to Rename objects All right, so actually let me just comment that out really quick We don't want to get too far ahead of ourselves So let's let all that compile and then let's see if we're actually launching a window First all right, so I'm going to go to any pixel level tools and rename objects And look at that. We actually have a window All right So, uh, what we can do now, let me actually close this down What we can do now is We can go back to this rename Or the title here, so I'm going to say e and then u to uncomment the to comment on the keyboard is e and c So control e and c and then control e and u to uncomment Cool. So now we actually have a title here. All right, so let me save this Come back in unity let that compile And then once it's finished what I'm going to do is launch it here From the menu All right, and you can see that now we've changed the title and this is just helpful So that users know which tool they've launched. All right, and you can see it's getting cut off a little bit Which I've never been a big fan of I wish they would just auto extend that or something But you can't customize all this stuff and you know, honestly, I need to make a More full course about you know making really fancy tools instead of maybe I'm trying to keep all this stuff relatively basic Just to give you guys the Fundamentals here. All right, so you'll notice that there's this little kind of a Green or olive wavy line down here. And that's just because This isn't really the way we set these anymore. You can see that Unity or visual studio is telling us that this Title is obsolete. We need to use title content instead. All right, so To do that, let me just make a point of showing you guys this. So what I'm going to do is say Title content. All right is equal to and if we hover over this you can see that title content Content is actually expecting a GUI content object Which means that we need to come up here and we need to say GUI content Let's just call it content. All right, it's equal to new GUI content All right, and you can see that it has eight overrides over here So we can go through all this and we can add text to it an image text and a tooltip Text in an image so I'll let you guys roll through all those all I want to do is just add that title So I'm going to call this rename objects Like so and just put a semicolon there and then assign the title content here. All right our content object There we go. So now if I come over to unity here All right And when I go and click on the menu item up here we should have Basically the same result But inside of a little studio. We just don't get that All of wavy line. All right, so that's a little bit better So last thing I want to do is a win dot show and that's just because that's what I'm used to it looks You know nowadays, it's just launching anyways, and I think get windows is calling show But I'm so used to doing that that I I have to so All right, so usually the next step in all this is I put down void And then I do on gooey because this is where you add your custom UI. So to test that out Let's put in this on gooey method here And the first thing I want to do just to make sure it's all working is I put in an editor gooey layout dot label field All right, and I just call this My label like so So we should see a label in the Editor window called my label. So let's go test that out And there we go. So now we have my label Cool So with that, I think I'm going to close out this lecture All right, and in the next what we're going to do is we're going to start populating this with some UI And then, you know, I think in the third video We are going to get into, you know, actually renaming all the objects But what I want to do is get the UI set up That way I have data to work with Okay, so let's close out this video and get on to the next. Thanks so much