 Okay, so let's continue and actually finish off our renaming tool and to do that Let's create some objects to rename. So I'm going to call this cube And cube one two three four five six seven and eight. I think that's going to be good We'll stick with the even number. All right, so Just to make this a little more official. Let's go and move these guys all around Not that you have to but It'll just make it look more official Okay, and There we go. That's good All right, so with that out of the way Let's jump back into the code and let's get a few things going here So I'm gonna go back to visual studio and go back to the editor script And what I want to do is I want to fire off a custom function or method right here So we don't need that debug log anymore, and I'm gonna call this method rename objects Like so Perfect, and so we can just copy that and we can come down here to this custom method region. We'll say void rename objects turn it into a method like so and Inside of this method what I want to do is I want to actually Log to the console all the names of the objects I currently have selected So remember we are getting all those objects from this particular Array from the selection class and it's being stored inside of this selected variable, which is also an array so what we can do is we can come down here and we can do a For loop, you know, so you can say for int I is equal to zero and I is less than These the length of selected so selected that length like so All right, and I don't need that there we go And what we need to do is say I plus plus so we want to iterate we want to increase the value of I from zero to how many ever Objects we have selected and we do that by incrementing it. All right So what I'm going to do is I'm just going to do a debug log and we're going to say selected And we use the square brackets and insert that I indexer. All right So that's the the current value so it's going to start at zero and every single time we loop It's going to add one to it because we did the plus plus here So we're going to say, you know, whatever the name is at the current index Cool. So let's try this out. So I'm going to jump back into unity now Let it compile and once it's finished. We will go and select all these cubes here So let's go and select all these cubes and I'm going to clear my console and then hit Rename selected objects All right, so what you can see is that we're getting cube 3 cube 8 cube 6 4 2 cube And cube 5 7 and 1 Well, that's not very useful What we want to do is we want to actually organize that so that it lists it in order here Even if you select it with a control and shift it still gives us that randomized order Which I've always found quite odd But there's a way around this. So what we can do All right, and this is going to be a little bit more of the advanced side, but I want to show you anyway, so What I want to do is I want to do an array sort. All right if we were to Go up to Google up here and Look for array Dot sort Let's actually do a C sharp like so There we go So ray dot sort This is the method that we want to use because what we can do with it is we can actually put in what they call an eye compare All right, so we're actually going to use a delegate version because We want to order it by its name. Okay, so to do that We're going to come back in a visual studio here And what I could what I need to do actually I need to go active to Google here You'll notice that the array dot sort is underneath the system namespace So that means that we need to go and include that namespace here. So we'll say using system Like so which means now we can go and access that array Dot sort method. All right, so now the array dot sort method has a bunch of overrides All right, but what we're going to do is we're going to utilize the delegate version so What I want to do is I want to pass in the array that we want to modify and that's that selected array. Okay, and What I want to do now is Compare the names of all the objects inside of this particular array. So to do that we need to declare a delegate All right, so I'm going to say delegate and we're going to give this delegate some arguments now This delegate is kind of like a method. All right, it's mostly used for like event type stuff So we can it call this particular delegate It's going to run its functionality and return us a particular value and to do this We need to put in two arguments. So I want to pass in two game objects We're going to call this object a And then we want another one called object B All right, so these are the two objects that we're going to compare using this Delegate right here. All right. I also need to add the semicolon Leave right there. Nope. It's going to be right in here because there's no return, right? But this is what this is telling me. Okay, so what I want to do now is I want to return a value So we're going to say return And what we're going to do is we're going to compare object a's name to object B's name and what this Sort is going to do is it's going to sort it by its name Okay, so this is great because and it works really well for this particular instance because Because I duplicated them they have this numbering So it's the sort method is going to pick that up and sort it appropriately and then we're going to log it again And it's going to show us the proper naming structure. All right, so we're going to say return object a Dot name dot compare to and we're going to compare that to object B dot name Like so All right, so Then we just need the semicolon there. Perfect. So with that done, we can do the for loop again So we'll just do four int i is equal to zero And i is less than Selected dot length and then we'll do i plus plus All right. We'll debug dot log Probably shouldn't have deleted it. Oh, well Okay, we'll do dot name So Cool, so let's go back in a unity and test this out make sure we didn't get any errors or anything like that Okay, so let's clear the console and then hit rename selected objects And you'll notice that we get cube cube one two three So our array is now sorted in the correct order So with that information we can actually go and just finish this up now. We've got everything nicely Organized in our array. So I really just want to show that because when you start working with objects, you know With these particular arrays and lists for that matter It's good to kind of organize your stuff. That's a Nice quick and easy way. Well relatively easy way. Would you understand delegates becomes easy? But it's a nice way to you know get that in one line of code So what I want to do now is just declare a string called final Name and I'm going to initialize that final name to an empty string like that or you can also do a string empty like so okay, but those are completely valid and The first thing I want to do is take care of the prefix. Okay, so we can say if Wanted prefix Dot length is greater than zero. All right So we're just looking to see if the wanted prefix has characters in it actual letters and stuff like that because it's string So if it's greater than zero, that means we've got something type in there Then what we want to do is we want to say final name plus equals The wanted prefix now that plus equals just means we're adding on to whatever final name is currently set to and Currently as we go through this particular method here. Okay that is the The name that we want I Mean that is the empty string. So then we're adding on the wanted prefix. Okay, and what I also want to do is just make sure We have that loop in there again. I don't know why I got rid of it. My apologies. So we say I less than selected Dot length so do one more time, you know practice is good All right There we go So for each one of these objects, we're gonna go through and name it appropriately So I'm gonna say then for the next part. We want to say if Wanted name yep, so wanted name Dot length is greater than zero Then we want to say a final name plus equals because we want to take whatever Final name is currently equal to with the prefix on it and then add another piece of the string so we say plus equals and We're gonna do an underscore between all of these and then we'll say plus Wanted name like so And then we'll do the same for the suffix. We'll say if Wanted suffix dot length is Greater than zero Then what we want to do is final name plus equals another underscore and We'll do wanted Suffix so adding that on So then the last thing we want to do is we want to add on the the numbering alright, so we'll do a check down here We're gonna say if Add numbering is true. Okay Remember that's Boolean if that's true then what we want to do is want to say final name plus equals underscore and then plus The I so the indexer okay dot two string And we can give it a format so we can say zero zero zero something like that Okay, so let's save that and go back to immunity and give this a whirl So now this should actually rename the objects and actually I like it won't actually rename the objects because We actually need to say that the selected object the current one that we're on That its current name is now equal to final name And now it'll actually equal that name. So let's go back to unity and try that out Okay, so let's select all these guys and let's put in some value for all these so what I'm gonna do is I'm just gonna call it Let's just say geo for the prefix Box let's do something like that for the name and then the suffix will be Something like Level and then we'll add numbering. All right, so let's then hit the button here And you can see now we have these guys all renamed nicely So it's zero zero zero if you want to actually, you know Start it at one. You would just say I plus one put that into parentheses like so And now let's say it's saved there and go back to unity So now if we go it'll start at one not zero, but you can leave it at zero two It's not like there's anything wrong with that There you go Now we can go and change this so we can call this, you know, whatever. Maybe it's something like DS for whatever that stands for for like your game You know name or something like that. So DS box and we'll call this Geo We'll do that There we go DS box geo one through nine Cool. So that is how we make an object renamer or a mass renamer inside of unity Now you can go and extend this, you know and add all the features that you want You know, you just add on to this particular method right here. Okay, so Thanks so much and I look forward to showing you guys the next tool here soon. Talk to you later. Bye