Accessing The File Explorer 2021 - (Works in Editor & Build)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another unity tutorial in the previous file explorer video this one on your right we accessed the unity file explorer and we displayed it a to an image on the screen however we did run into some issues and we could not build this out to a device and it would crash and give out an error so this video is merely an update to that this video you can build this out and it will work both on your editor as well as on your desktop so let's give this a try and let's see what it's going to look like so we can press play i'm going to open my file explorer i can choose a picture and i'll open it up and you see it displays nicely here so what we're going to do is i'm just going to show you quickly how it as an executable as well so i've just opened up the folder where i built out my executable in i'm going to run my file explorer.exe and there you see my application running so it opens up nicely and if i click open file file browser i can select a image again and it displays nicely onto the canvas so with that being said let's get started so guys before we move on don't forget to hit that subscribe button and help us grow this channel so we can create more awesome videos for you and tutorials for you guys so let's get started first of all i'm going to right click and create a canvas then i'm going to right click and add an image i'm going to go into my inspector and i'm just going to select shift and alt and stretch this across the screen i'm going to change the color to a color that i like and i'm going to leave it like that i'm going to zoom out a bit the next thing i'm going to need is a raw image and a button so i'm going to right click on the canvas i'm going to go down to ui i'm going to select raw image i'm going to go to my multi tool i'm going to go to the center of the tool and just scale that out a bit i'm going to move this up and the next thing i'm going to need is a button so i'll go to bottom text mesh pro i'll import my essentials close that off bring my button down scale that up a bit and i'm going to rename this button to say open file explorer then i'm going to drop the font size down a bit so that everything fits nicely okay and i think we're good to go there the next thing we're going to need is a empty game object that's going to hold our script i'm just going to go down to right click go down to create empty and i'm going to just reset these transform values and i'm going to rename this to file manager i'm going to add a component i'm going to say new script and i'm going to call this script file manager and i'll just call it update now so that we don't get it confused with the previous video i'm going to say create an ad and i'm going to double click it to open up in visual studio so before we get started i would like to give a shout out to sri on khan who really assisted me and helped me uh with getting this tutorial together for you guys basically he did a awesome rapper to make everything work not only in the editor but also in the build so big shout out to him i'll leave the link to his channel below so you guys can check him out he has some really awesome stuff he also helped me with the uh wrapper libraries as well and i've just modified it a bit just to make it simpler for you guys to understand and not deviating too far from our previous tutorial where we did create the file manager script already so what you're going to do is you're going to head over to my github repository and you're going to download the entire package from there when you do download that i have everything set up already for you guys with the libraries and everything already set up so head over to the link and download the files and head over back to unity okay awesome so now that you have all of the files and the package installed in your unity project let's get started with our script what we're going to do first is similar to the previous file manager we're going to need a public raw image and we're going to call this raw image and we need to include our library that's using unity engine dot ui next thing we need is a function to actually open up our file browser so we can just say public void and we can call this open file browser okay so once that's done what we're gonna do now is we are going to include another library called using another file browser so this is the wrapper that he wrote let's just use it because we don't want to reinvent the wheel so that's his wrapper so the reason that it's giving me this quickly is because i didn't uh import the file so let me do that quickly so now that i have the files imported all the libraries imported this squiggly line goes away so let's start with our first we're going to create a new object we're going to call it bp and that's going to equal to new browser properties so the bp stands for browser properties we're going to close that off next thing we want to do is fill out some we want to populate some of those uh values so if you go into the wrapper that he wrote you go into plugins another file browser we go into the file browser and if you look at the script i've cleared it up a bit just so that it makes sense to you and it makes sense to this video so in the browser properties you see it takes a title initial directory it takes a filter and the filter is an extension to what files are we looking for okay and it takes a filter index so what we're going to do is we're going to say browser properties browser properties dot filter and we want to filter it to all of the image types that we might have on our machine so we can say image files we'll open that up and we can say jpeg it could be jpg it could be jpeg it could be dot jpe it could be dot jfif or we could be using a png file and on the other side here we want to just say the same thing we'll close that off and the next thing we want to set the browser properties dot filter index to zero so we'll say filter index is equal to zero okay that's done the next thing we want to do is we want to take care of the path so what we can say is new file browser dot open file browser which is one of the functions in the wrapper we'll just say browser properties path which is what we're going to pass into our i enumerator just now and then we're just going to use a lambdas expression and we're going to call our start core routine function our innumerator function is going to be called load image and it's going to take in a path i'm going to just close that off and i'm going to close that off as well so let's create this load image function so we'll say ie numerator the reason we use innumerator if you look in our previous video is because we want to wait for a connection or we want to wait for the path first so we'll say load image and it takes in a string path okay so the next thing we want to do is we want to get the path so we'll say using and this is the way that uh we're going to be doing it now just so that it works not only in the editor but on bullet as well so just follow along we'll say using unity web request and we'll just call it unity web request as an abbreviation then if i go control dot i can just include the using unity engine.networking and that's quickly goes away next what i want to do is equal this to unity web request texture because remember we want to get the texture of that path and we'll just say get texture and will pass through that path the next thing we want to do is you know that after when using an i enumerator you need a yield return so we're going to say heal return and we're going to wait for the request so we'll say unityweb request dot send web request and then we're going to do a small check and we're going to say if unityweb request dot is network error or unitywebrequest. is http error then we just want to throw a debug error and we'll just close that off if there's no error and everything goes fine what we want to do is we want to create a new texture and we can call this unity web request texture is equal to download handler texture dot get content and we're gonna pass in the unity web request then what we're going to do finally after we get that texture we want to set it to our raw image so we'll say raw image dot texture is equal to unity web request texture and that's it that's all the things that we need awesome so everything's looking nice here let's head over back to unity and set everything up let's go to our file manager and let's drag our raw image in there let's save our work and now let's hit play and see if everything works fine so there you have it we click open file explorer nothing happens the reason being we didn't hook the button up so let's head over to the button go all the way down to your on click event we'll add an on click event we'll drag the file manager in here go to our function select our script and we can just select our function called open file browser we hit play again we'll hit open file explorer and there you see my file explorer opens nicely and here you see what we typed in previously in the uh filter whatever we type in there will be displayed here and that's our filter so i can choose anything else you can choose another picture and there you see changes as well so i hope you guys enjoy this video i hope this worked for you guys if you having any troubles please comment down below or if it even worked for you comment down below and don't forget to hit that subscribe button i'll see you guys later cheers you
Info
Channel: The Ultimate Developer
Views: 29,172
Rating: undefined out of 5
Keywords: unity, file, explorer, c#, tutorial, easy, method, how to print, how to print c#, how to print documents c#, how to print documents, how to use dll, print documents c#, print documents unity, print unity, print unity c#, print documents unity c#, unity3d, how, to, print, unity file explorer android, unity browser game tutorial
Id: Z1qT65GL-6Q
Channel Id: undefined
Length: 10min 53sec (653 seconds)
Published: Wed Jan 27 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.