Project-Based Augmented Reality Course with Unity Engine and AR Foundation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
augmented reality is growing in popularity and in this course you will learn how to develop AR apps by building practical projects the course consists of four different augmented reality projects which are built on top of unity engine and AR Foundation the projects will help you explore various Fields such as engineering education e-commerce and creativity priyanshu developed this course he has a lot of experience developing AR apps and he's created other popular courses on the topic and this free course we are gonna explore the possibilities of Augmented Reality by building such captivating and practical augmented reality experiences we will start with Planet CR in which we will be exploring planet Earth and other different planet States than ever before we'll be exploring it so that's not all we will also delve deeper into the world of creativity by building an application that would actually help you plant different different kinds of plants and into your room if we talk about the fourth project that we are going to build we are going to explore the possibilities of e-commerce with that application we're gonna create an interior design application that would actually help us put different different Interiors different different sofas chairs onto our room I am priyashi co-founder and CTO fantern and I bring you the three comprehensive augmented reality course that is going to teach you to develop augmented right experiences with the AR foundation and unity engine so without any further Ado let's move forward and learn how to build such captivating and amazing augmented yet experiences hey everyone welcome to this lecture and in this lecture we are actually going to build our very first augmented reality project with ar core and AR Foundation from the very scratch I'm going to teach you how you can set up the project how you can uh build the AR Foundation app to your devices right so without any further Ado let's move forward and let's learn what to do next okay the very first thing you have to do is you have to open your Unity up and you have to create a new project now if you don't have any Unity version installed you can simply go to installs option click on install editor choose the editor of your choice now in this course I am going to use Twitter what you want so you can simply click on install then select the Android build support because we are actually going to bend for Android and also select the iOS bit support and then you can simply click on continue accept the terms and condition and simply click on it okay that's gonna take a bit of time it's gonna of course it's gonna take a lot of Internet like around four or five GBS maybe so it's gonna download the package it's gonna install so given the time it needs okay and once the project I mean the unity editor has been installed what you can do is you can simply go to the project section now what you have to do is you have to create a new project now it is very simple to create a new project what you have to do is you have to click on this new project button and once you have create like you know clicked on that particular button you will be able to find this option called editor version now you you can choose any editor you want for this course I'm going to use 2021.3.50 F1 you can also go with any other version such as new to 2019 or 2020 but I would suggest you to like you know keep up with this video that is used 2021 version of unity now once we've selected the unity editor you will be seeing there are multiple options for templates right there's 2D there's 3D there's 3D mobile 2D urp then sample urp I think there's hdrp also then there's like you know a lot of examples that Unity has already coded for us that Unity has already given us but for now for this video we are gonna wait uh gonna go with a blank project and we are going to select 3D core because we want to have the 3D functionalities now if you want to build any sort of like you know 2D game or anything you can simply select the 2D code option but for this video I'm gonna go with 3D code as we are gonna need the 3D version of that once you have selected that 3D core option what you have to do is you have to change the project now you can change the project name to anything I'm Gonna Keep It planets AR you can also keep it anything you want and you can also change the location of the project if you want okay and that simply click on create project that's gonna start the process and it's gonna create a project for you okay now once the project has been created you will see this editor now this editor is called Unity editor now within this editor now what what we have to do is we have to set up the project okay we have to set up this single territor so that it is able to build for Android devices and it should be able to support augmented reality okay now just clear out our head now okay just clear out your head and listen to now the very first process that you want to go through is switching your platform and setting up the project the reason is you can see you can set up the project later on also after importing the assets doing everything but the reason why you should set up your project at the very first because let's say I have added multiple Assets in the project folder okay so what's gonna happen is let's say I remove the graph Graphics API I switch my build platform the switching part the setting apart it's gonna take a much longer time okay and definitely we don't have that much time to wait for it to build and switch the project and all the process it needs to be done so that's why that's why you should always set up your project at the very first then only import the required assets so let's move forward the very first thing you have to do is you have to click on file go to build settings now in the build settings you'll be able to find multiple options in here like there's Windows Mac Linux dedicated server Android iOS PS4 PS5 now now I want to build for Android devices only so I'm going to select Android but you can also build for iOS devices if you want now there's one thing that you have to keep in mind okay the code base will be very much similar because we are going to use AR Foundation now AR Foundation makes it easier for the developers to build for both IOS and Android how it provides two plugins called AR plugin and AR code XR plugin now AR kit is supported on iOS devices and AR core exam plugin is supported on Android devices so if you want to build for iOS you can simply install AR it and if you want to build for Android you can simply install AR code exampler okay that's it nothing much nothing too complicated but again like you know if you want to use AR core on iOS devices that's also possible you just have to install the application from the App Store I think it's called as Google services for AR code or I maybe it's called AR code I'm not really short but there's a plugin for that so you can you can simply install that uh within your iOS device and simply like you know work with it build the applications in there and again if you do this want to do the same for Android that is built for AR code then make sure your Android device supports the airport okay there are uh there's a whole list or where you can find if your device supports VR code or not and if it does what you can do is you can go to Play Store and search for Google services for here okay the link will be down below in the description you can simply begin to search for that app or you can go through the link that will be given in the description and simply install that particular because without that uh the AR code apps won't work on your Android device so I hope that's that's clear to you so let's move forward now you have to select this Android option and click on switch platform now it's gonna take a few minutes or few seconds depending on your system to phrase the platform so given the time it needs bye now once it has switched its platform to Android the next thing you want to do is we want to set up the project so that we don't have to like you know go through the whole painful built-in process again and it shouldn't take much time for you okay we want to make sure that now once you like you know once you have switched the platform you at the very like you know bottom left you'll be able to find this player setting so click on the player settings from there the very first thing you want to change is the company name you can of course you can keep it uh as a disk but I would suggest to change the name right keep it anything you want so for now I want to keep it coded reality because that's the name of my channel and then there's uh I I'm just going to keep the product name as planets here because that's the most suitable way okay now if you want to set uh any icon for the application you can totally do that from here now I uh in the assets folder I already have a icon so I'm gonna I'm gonna show you how you can do that now after that uh in the resolution in presentation you would want to uh go to this default orientation option and make sure to uh select the portrait option in here because we don't want the landscape left or landslip right or any other option there we just want it to be in portrait mode of course if you want you can also keep it uh in landscape mode but again you have to design the UI that for now I'm gonna show you how you can do the scene but for portrait now once uh the orientation has been selected the next thing you can do is you can simply go to other settings now from there make sure you uncheck this autographics API now the reason why we are unchecking this Auto Graphics API because by default our Unity project something called uh cut date something called Volcan right now is another Graphics API just like open GLE but the problem is AR code doesn't really support worker so if your project already has Balkan and if you haven't removed it AR code after building right AR code is gonna give you a lot of letters and your build won't complete so we don't want the World Cup Graphics API so I'm just going to select the welcome from here and click on this minus now that's going to remove the working API from our project and once that has been removed you can simply go to multi-threader rendering and make sure to uncheck this multi-threaded rendering then I didn't go below and you'll be able to find this option called Minima API level now make sure to set to Android 7.0 because AR code requires a minimum bid level of Android 7.0 if you go below that maybe 6.05.1 and maybe below that the problem is that it won't build it's going to give you error so you have to keep either Android 7.0 as the menu APN level or maybe above you can also keep 8.07.1 8.19 10 anything you want okay but just not below Android 7.7 now work that has been done you have to change your scripting back into IL to CPP the reason is AR code doesn't really support 32-bit architecture anymore so you need to build it for uh like you know 64-bit architecture now to do that you you have to set your scripting back into i2cp because if you if we check out mono you won't be able to find this arm 64 option now to get this on 64 option you have to shift to Il to CPT and make sure to check this arm 64 option from there and once that has been done we are actually done for now with the player settings we still have a few more settings to go through but that will only be enabled when AR foundation and er Port has been installed so to do that simply close these window go to window go to package manager then again from the drop down select Unity registry now from there what you can do is give it the time to load it might take a bit of time depending on your internet now it loaded uh very fast on my in my case uh now once the package has been loaded what you can do is you can search for ER okay now once you search for AR you'll be able to find this AR Foundation AR code and arcade exam plugin now these are the three packages we need to focus on if you are building for iOS I would highly suggest to go with AR kit because uh I wouldn't suggest to go with ar code is best with Android so keep it for Android only and if you want to build for iOS then go with AR kit don't worry apart from the building process everything is similar you don't have to make any changes to your code you don't have to make any changes to your project setup just whenever you are building you have to set the project settings according to iOS okay now for this course I'm gonna use Android so I'm gonna simply install the AR codex but before that you have to install this AR foundation 4.2.7 so just select this version and click click on install give it the time it teach for the installation now once that would be done we'll also be installing AR code example now AR code is necessary to build AR experiences for Android me now as you can see AR Foundation has been installed the next thing you have to do is you have to click on the exam plugin and then click on install now once both of these has been installed what you can do is simply close this window again click on file build settings click on player settings and then go to this particular option exam plugin manager okay now in here you will be able to find multiple options that is AR code Oculus and Immunity mock hmd now Oculus and unity mock hmd is not something we want to mess with as of now we wanna uh do everything with this AR core option okay now this ER core option is very important you must check it out the reason is you can see in here you you are able to see a text called initialize its are on start now that means whenever your you start your application it's going to initialize the particular plugin you have checked it so for me I have just checked AR code so it's going to initialize the AR code plugin at the beginning of the starting of the application okay so it is mandatory for you to check the AR core option if you don't do it then ER or won't be initialized at a start at the very start and you will be you won't be able to use AR code within your application so make sure to check this option out and once it has been checked you can simply close this window and now we have got our project set up very well okay now the next thing what you have to do is you have to delete the main camera okay once you have delete the main camera you have to right click in the hierarchy click on XR add an ER session widget then again add an AR session now ER session origin would be responsible for handling the camera the plane tracking the image tracking the recasting and all every and all the other things that are necessary for performing augmented reality and the ER session will be controlling the whole life cycle of unity and your AR application so both of these components are mandatory and you can see inside they are session audit we also have an AR camera which will be uh capturing all the real world scenario and will be like and this whole AR section origin will be helping you to place the object into the real okay now here you can see we have set up our project properly we have set it up properly and now what we have to do is we have to import the assets okay but before that let me change the name of the scene okay so I'm Gonna Keep It uh planets let's follow it or maybe or maybe let's uh call it home swing because we want a whole speed which will help us to navigate between different different uh like you know planets that we have in here now we are going to call this home screen and another one you have to create another C we are going to call that CNS Arc okay or let's do one thing as we have already set it set this scene up for uh augmented reality let's call this scene as uh planet okay let's create another C that will be having the default main camera and we are going to call it home screen now the uh the reason I removed this main camera the reason I removed this main camera is because it renders the virtual scene okay it actually renders this particular scene so that's why I removed it the AR camera would actually be rendering the rear mode so that's why you have to add the AR camera if you want to perform augmentation but as this is the home screen it doesn't needs any sort of augmentation that's why we want to use the main camera as the default camera okay now once both of the scenes are created we want to import the asset okay and we simply wanna import the Assets Now I already have if you if you see here I already have a folder created in where I am having all the unity assets stored now this is the planet's AR assets that we want to import it's again fairly simple right click in the project setting click on import click on custom package I simply import this planet CR Assets Now again you can do the same by simply dragging and dropping uh all the Assets in here so both of the way works choose the one you are comfortable now once you have like you know dragged and drop the or maybe imported the package within your Unity screen you will be able to find this particular window now you you have to Simply click on the import import option that we all the textures all the files that are included in the package will be imported in your project file so give it the time it needs yeah now here you can see that we imported our project now inside the asset folder you will be able to find textures then there's Planet textures that will be containing all the like you know textures for the planets then there's UI texture that will be used for our user interface uh here you can also see that we got a logo now we will be using this logo also that I also have a model for the Saturn so we will be using all these uh in our project to get everything set it up okay so once the assets have been imported the next thing you want to do is let's create the UI okay let's create the user interface first then we are going to move on to the then we are actually going to move on to our augmented realityc okay so now once the home screen has been created simply double click on it to open it then what you have to do is you have to right click in the hierarchy click on the UI add a canvas okay now the canvas is actually going to help us to create UI for this whole scenario and go to your game window and make sure to change it to uh some portrait okay now I actually already have some preloaded templates from wyson now if you want you can also do the same for yourself you can like simply click if you if I show you click on this uh option right and you'll be able to find this plus sign if you click on this plus sign you can name the device you can add its width and height okay that way you will be able to get the proper mode or the proper device you want to use now for me I'm gonna use this OnePlus not C to light for myself you can use any other UI you want if you are let me select something in between Maybe yeah redmi note 9 seems much better so I'm gonna go with redmi Note 9. now here you can see that it's a blank canvas okay and inside the canvas we don't really have any and also also this is a really good feature that we have in unity if you click on this 2D option you will be going on to the 2D mode and once you go on to a 2d mode you can double click on this canvas object and you can zoom out like you can bring the canvas to your phone this is a very useful feature that I think you should know about you can simply click on the canvas option then in the at the inspector you'll be able to find this canvas Scalia okay now in the canvas query you will be able to find this UI scale mode make sure to change it it is actually by default set it up with the constant pixel size we definitely don't want that to make the UI responsive we want kill with spaces okay so make sure this uh to select the scale with screen size option and once you have select that in the canvas we want a background okay we want a background so that not everything this this whole like you know weird looking background isn't visible so the very better the the better way to do is right click in the canvas you can either like you know go to UI add a panel in here right or you can what you can do is you can simply add an image okay we can also add an image like go to UI add an image in here and then change the name of your image to background now once you have selected the image in you can you might find this option called direct transform in the inspector if you select the image right and in there you will be able to find a small box right so click on that box press alt in your keyboard if you are a Windows and press option on your map so once you click the alt button on option button on your device you can simply like you know at the very bottom right you will be able to find the stretch options simply click on that stretch option and you can build and you will be able to see that it has failed the whole image in there okay it is filled the whole background so we want to keep it to white as of now and if we go to our assets and go to the textures option and click on UI textures you'll be able to find this diagram okay now what you can do is now basically the the assets are already set to texture type to like you know Sprite today and even but let's say if you import some other like you know import some external image by yourself you will be able to see that it will be set to this default option okay now if it is set set to default just change it to Sprite 2D anyway because that's the option we are gonna need now once you have selected the background make sure to drag and drop this background image from the UI texture in here you can see that we got a pretty neat and clean background uh for our UI now once you have selected this particular background you can add another image let's click on UI let's add an image now this is going to be our headache okay that is it is going to contain that I tell for us so I'm simply gonna drag and drop this home header and click on set native size and now reduce the size Mill 0.5 yeah 0.5 seems much better and to Anchor this right without anchary this uh like you know this planet's AR logo won't really be responsive so you have to Anchor it to that to answer it simply click on the heading press alt in your keyboard open this option anchor presets option in here just simply press on the top that way you will be able to set the like you know this particular anchor to the very now let's say if we change the resolution or maybe change the UI you can see that it is adapting to the particular interface okay and that's what we want now once you have added this particular heading we are also have to add a few buttons to navigate between the planets right now again it's pretty simple uh first of all I would like you to let you know create a empty container that way it would be much better for us to like you know handle all the uis I mean the UI buttons let's name it uh button button Handler now what you can do is you can simply like you know click on this button Handler again press alt in your keyboard and make sure to stretch it out to the very top and you can like you know reduce or maybe change the top value by something 250 maybe yeah change it by uh change the Top Value to 250 now what you can do is you can keep on adding the buttons in here okay and uh let's do it let's add this button Handler let's click on this button Handler add a UI let's add an image in here let's anchor this image to the top and let's reposition this image maybe let's let's change the weight and height to maybe 200. that was seen much better yeah totally much better and let's make it to 200 okay and minus 100 now this looks diff uh this definitely looks much better and let's still change the image size name to baby or okay now let's actually let's try minus 200 yeah this looks much better let's duplicate the button and put it uh to maybe the site right let's put it to the side like this and change it to minus 200 and again minus 200 that way we got two different buttons for our planets okay now you can change it to maybe Mars right uh similarly you can uh set the C do the same thing for other buttons right so for now I'm just gonna keep these two buttons what you can do is you can replicate uh much more buttons in here like I already have options for Jupiter Saturn Uranus Venus and other planets too so you can definitely do that for now let's keep these two buttons only and the next thing you have to do is you have to select the Earth button drag and drop this Earth texture in here and again select the mask button and drag and drop the masks option in here now definitely it seems like the spacing is too much let's increase the weight to mainly 400 um how about 350 yeah 350 seems much much better and the next thing you can do is as these are images right these doesn't have the capability of button now what you can do is Select both the images click on ADD component and add a button component into onto these images right now if you click on these uh images the buttons like these will these images will be clickable okay so you can click on these images and set any functionality you want for now now once we got the Earth and Mars Butters of it out we have to create a new UI okay so not UI exactly but a new C so I'm going to call this uh Planet seal to earth now once I've opened this Earth C what I can do is I can create a new spear okay that's gonna Conte the Earth planet so I'm going to reset its transform set the Z value to 5 or maybe how about two two seems much better I mean let's keep it to four four would be much like four would look much better the next thing you want to do is rename the spear to R and then create a new material okay so I'm gonna create a new folder called material now I'm gonna create a material called Earth so and then simply drag and drop this Earth material on top of that Earth object now if you change the color you you will be able to see that the object is also changing the color according to the material so that means our material has been applied properly once the material has been applied what you can do is you can simply search for the Earth texture texture now we already have this 2K Earth Day map I'm gonna select that and you can see that we actually got the Earth texture in here now it might seem that like you know it's a bit too flashy uh you can definitely skim through the shaders that we have you can search for uh like you can simply click on this drop down option search for unlit and you can set it to texture that we will be getting this option but it definitely looks much more dull uh let's go for legacy shaders let's try let's start diffuse yeah this one looks much better but I think uh the standard one look was looking better so let's hear the standard standard one only but if you want to reduce the smoothness you can definitely do that let's take two maybe point four yeah point four seems much better and now you can see that we got our Earth properly set it up now what you can do is we want this Earth to rotate right because of course Earth does rotate so you we have to write a new script okay that script would actually be helping us to rotate the Earth now again it's pretty simple so create a new folder called scripts folder now inside the script folder what we want to do is we want to write a script that should actually rotate the art on its axis so I'm going to create a new script let's name it rotation controller okay so let me edit the time to compile and once it has compiled just open the script in your IDE now I'm gonna I'm using visual studio you can use Visual Studio code Sublime Text on any ID you are comfortable with now once the script has been opened we want to create a public variation called public uh public game object or object right let's call it or maybe plan it off that would be much of a universal need let's call it Planet object now once you have created this particular variation you also have to create another video byte other Vector 3 variable to be honest okay so let's create a vector 3 variable public website three and then name it rotation Vector because that would actually be helping us to control in which axis we want to rotate our Arc okay so rotation vector now within the update function what you want to do is you want to reference like take a reference to the planet object okay and pass the rotation Vector uh within this particular parameter as a parameter to the rotate function and then multiply it with time dot there okay that's going to give us a much more realistic rotation bag now if we compile the script and add this script to the particular Earth and drag and drop the Earth object as a planet object and uh let's see let's play it okay now right now you can see the Earth is not moving so if you increase the value of this one right it will be how about 10 yeah 10 looks much better so now what I can do is I can replace the value to 10 and now if I play it you can see that we are the planet is actually moving right uh the plant is actually rotating now next well you can like you know replicate the scene maybe duplicate the scene Again by con you can like select the simple C press Ctrl D that's simply gonna duplicate the scene and rename it to Mars okay open that mask and rename the object to maybe Mars and then what you can do is you can click either create a new material or again uh like you know duplicate this material change the name to bars and then select the mask texture and simply drag and drop this texture in here now if we see replay it you can see the mass is also rotating properly right now what's next okay what's next if we open this particular scene if we go to the home screen and if we press on this particular button we must be able to like you know switch between seeds right if you press on R then we should open the Earth scene if we press on Mark then we should open the Marcy definitely right but it's not doing it right so what should we do now to perform that we actually have to create a new script that would actually help us to switch between C okay so again it's pretty simple create a new script and call it scene controller okay now this scene controller will actually be having a method to switch between the seats so open this particular scene controller now you have to add a using a direct app so using Unity engine Dot scene manage okay once you've added that simply click you know create a new function public void switch scenes and make sure it takes a parameter or a string parameter and let's name it seed name once you have created the parameter the next thing what you have to do is you have to uh and give a second click manager you have to reference the scene manager and click on load C right that is load the load scene method and within that you have to pass the shield okay that way will be will actually be able to switch between multiple scenes that we have so next what you want to do is you can simply drag and drop this script to anywhere you want let's attach this scene controller to the canvas that we have or maybe let's not add it to the canvas let's add it to the button handle okay and the next thing what you can do is you can simply click on Earth and Mars add the particular uh like you know go to this on click option click on ADD option and then simply drag and drop this button and Handler in here then click on this no function click on scene controller and make sure to switch to this switch scenes option now you can keep the name of your scene download and if I still lived in Mars I'm going to change it to boss okay now if we let's say if we try to like you know switch between the scenes you can see that it is giving us internet Earth and Mars is not loaded that it couldn't be loaded so what you can do is you can simply click on file build setting click on ADD open scenes just gonna add the home screen in here then go to your series option at the bars and Earth okay now if you like you know play this option you can simply click on R and you can see that it has loaded the over C but again there are no options for going back right we also have to add the option to go back to the home screen again you have to do the things the same way it's pretty simple okay it's not too hard so click on right click on the hierarchy create a new canvas change its UI scale mode to scale with screen size uh then what you can do is you can simply add an image now this image would be acting as a button right so I'm going to add the back texture in here so you guys see I added the back button texture I'm gonna click on set native size and reduce the size to maybe 0.2 let's see how does it do not point to decently not pointing maybe 0.5 so Pi 0.5 would be two big list go for points F1 phone seems much better and then click on the select transform fill in the anchor preset press alt on your keyboard and Anchor It To The Top okay that way you'll be getting this particular button and you can be how about we keep it 160 and minus 100b so that way we got the button in here now again what you can do is you can simply add a button component you can add the particular script in here that is history uh scene controller script to the canvas click on this click add an option to the on click function drag and drop this canvas in here then click on scene controller click on switch scenes and give the name of your scene where you want to switch now again what you can do is you can simply copy this too right make sure to copy the canvas and the event system without the event system your clicks won't be registered now you can go to the mass scene add these two in here and just check if everything's fine so you can see that everything is loaded as it as it should be now if you play this you can see that we are able to navigate back and forth between the seats now this is it for this lecture okay we actually needed a fully functional ER application and I'll be adding a small demo to this application at the very end of the video okay so make sure to watch that demo also and the task for this okay the task for this lecture would be to add a few more planets up in the list and also you can add an information panel that would actually be so showing the information about these plan properly okay so these are the tasks these are the modifications that you can do to this project and to build this project what you can do is you can simply click on file click on build settings make sure all the scenes are added up in here and then click on build give the name to your application I'm gonna click uh name it build and also also before building a forward to showing if you click on player settings you can actually set your icon now I already have a icon for this so I'm gonna click on this select option go and look out for the icon it should be somewhere here I guess I named it logo so here you can see that we got the planet CR logo now if you build the application you should be able when you like after building the application if you install the application on your device you will be able to see the application with this particular Loop so I'm simply gonna name this application and build and I'm simply gonna save the build okay so it's gonna take a few minutes to build the application for you so yeah this is it for this lecture and make sure you try to add a lot more features to this application believe me it's gonna be fun hey everyone welcome to this lecture and in this lecture I'm going to teach you how you can build an augmented reality-based simulation of a jet turbine sounds amazing right so so let's get started why wait for the very first three you have to do is to set up this project now to set up this project you have to like you know create a project first so to do that what you can do is you can open your Unity Hub click on this new project option choose the unity editor version you want to now for this course for this lecture I'm going to use 2021 you can also go for any other version like I have to give it to 2020.3.4 tf1 also so you can go for any other version you want but I would suggest to like you know keep up with 2021 as it has the latest version latest stable version that we have right now and uh so yeah let's move forward now once you have selected your editor version right the next thing you got to do is you have to select the template now of course there are multiplicity of places 2D template 3D template 2D urp 3D mobile then 3D urp 3D sample c new RPM like you know many other templates uh that you can down but for this now we want to start with a black 3D template so we are going to select the second option that is 3D code now once you have selected that particular option you have to name your product now what should you name you can name anything right I can I can name it jet turbine simulation right I can I can name it this way then if you want to change the location of your project you can totally do that you just have to select this location option click on it once and then what you can do is you can simply select the folder you wanna create the project and once all these things have been done you can simply create project now if you don't have any Unity editors what you can do is you can simply go to install click on install editor select the unity version so this is the latest version that is out there that is 2080 1.3.17 F1 what you can do is you can simply click on install Ed the Android build support because if you want to build for Android you are going to delete it and if you want to bid for iOS you can select that and then click on continue uh agree the license and then click on next okay and then it would start downloading and installing the editor and all the packages that is necessary for building for Android and iOS device and then you can again like you know create the project give it a few minutes to like you know create the project and then we can get started now once you have created the project this particular editor window will be opening up right this is the unity editor window and in here we have to the very first thing we have to do is we have to set up this project so that we can build for Android and it should also support augmented reality now you already know for all these four projects that we are going to develop we are going to use uh something called AR foundation and we are so AR Foundation is a pool of like a universal package in where you can add the ER kit and AR code plugin that would actually help you uh build cross-platform AR applications so now before setting up all of that okay what you have to do is you have to click on file click on build settings and then switch to the Android minute if you are building for Android or if you are building for iOS you can simply switch to the ions okay but for now we want to keep it to Android only so what we are going to do is we are gonna select the Android build and then click on switch platform now this is a small tip that I always follow basically what happens now if if there are already assets available within your editor window that is within your project itself it's going to take a lot more time to set up this whole project okay because it's gonna convert all the materials all the assets to the like you know related versions and to avoid that kind of like you know time what we want to do is we want to switch to the platform setup everything at the very first before importing all the assets that we have okay so that's what I do always and believe me that saves me a lot of so I would recommend you guys to do that now once you once your platform has been switched the next thing you can do is you can simply click on player settings now from player settings you can change the company name I'm Gonna Change it to coded reality okay because that is my channel snake then you can change the product name to maybe jet turbine and then if you if you have any sort of icons for your application you can like you know add the icon to the folder and then select it in here that way you can also like you know add a logo for your application and once all these have been done you have to go to your resolution and presentation now we want this app to be in landscape mode okay so for that what we are going to do is we are gonna uh go to this default orientation and I wanna check out landscape left okay once you have selected landscape left what you have to do is you have to click on and get other settings make sure to uncheck this Auto Graphics API because we want to remove this Balkan API from here okay because uh ER Port doesn't really support Vulcan so we have to remove that orderly or else you will be like you know getting errors while building the application so we are simply going to remove that Vulcan API once that has visible what you can do is you can turn off this multi 3D rendering as we are not gonna need it and then go directly below to this minimum API level and set it to Android 7.0 because that is the minimum API level that ER core actually supports uh if you if you are choosing any version below that you are gonna face in so make sure to uh like you know keep it 7.0 or above seven points okay and then we're gonna have to shift our scripting back into IL to CPP okay now once we shift the scripting back into iot CPP you can check this arm 64. the reason we are doing this is the AR code doesn't really supports 32-bit architecture it only supports uh 64-bit architecture so you have to shift towards 64 architecture and with mono that's not really possible like if you check more load you won't be able to uh you won't be having this option for arm 64. so to get that arm 64 option you have to switch towards IL to CPP and uh here's another I'll to CPP builds are much more optimized and much more faster in terms of loading I like the CPP builds are much more faster and much better and much optimized than mono built so whenever like you know you are deploying your app to production make sure to do it in il to CPP scripting back okay and once you are done with this the next thing you have to do is you have to install the plugin you have to install the AR Foundation plugin and also you have to install the AR code example and if you are on iOS then you have to install AR kit plug and also here's another thing AR core is also supported on iOS devices okay so if you wanna like you know stay up with ar core only what you can do is you can simply like you know install AR code plugin and also uh install the AR code from uh Apple's App Store okay that way you'll be able to run ER code on iOS devices also but I think it's much better to like you know use ER Kit only because arkit has much more functionality to be honest like body tracking that uh AR code doesn't have why Always if you if you are on iOS right always try to use AR kit as much as possible rather than using Yahoo and if you are using Android then definitely your code is the V2 now to set up this project for augmented reality you have to click on window then click on package manager from there uh you'll be able to find this particular drop down right and the talk so you have to click on that drop down and select with unity registry so give it the time to load right and once it loads the packages you will be able to find a lot of options in here you know like it's confusing I understand that but to sort everything out just search for AR right with ar you are going to find a lot of different packages now for this tutorial we're gonna need a and if you are choosing to install AR kit plugin also there won't be much difference in building like you know setting up the project the Kodi part but yeah the uh the building part will be different the deploying part will be different for AR kit so I'm gonna stick with ar code and AR Foundation I'm gonna click on AR Foundation the version I'm gonna use is 4.2.7 as this is a stable version and simply gonna click install give it the time to install the packages give it the time to install the air Foundation packages and once it is done what you can do is you can also install the AR code XR plug now as you can see we already installed the AR Foundation package the next thing we have to install is AR code example so I'm going to Simply install it add do you know the benefit of using AR Foundation AR Foundation helps us to like include both AR core and AR kit plugin so with a single code base you can build for both the platforms it brings a more cross-platform functionality for AR so I really like using AR foundation and AR tool other than using any other SDK that is out now once I have installed both the packages right you have to go to your player settings again and make sure that AR core gets initialized uh whenever it is built first so what you have to do is you have to click on player settings then simply go to EXA plugin management and make sure to check this plugin provide okay if you if you don't check this AR core uh like you know AR code option in the plugin providers the AR core part won't be initialized when you start the application which is definitely not the thing we want we want uh AR code to initialized whenever the app is started app has been started so we want to check this particular option and then what you can do is you can rename your scene I'm gonna rename my screen to Jet byte okay and once I renew the seat you can see that we we got the c d m as jet turbine at the very top and also before setting up the scene I just want to make sure that all the settings in the player settings are totally fine so let me go through that once uh yeah we got the graphics EPA sorted we got a multi-threaded rendering sorted out we've also got the minimum API level sorted out we got the scripting back end and the arm 64 option sorted up now there's one more thing if you want to uncheck this on V7 option the 32-bit option you can do that let me keep it for now but if you want you can also unchain that and uh yeah everything seems fine and in the exam plugin management also we got the AR code plugin provider check uh so we got everything set up uh like for our project so that it supports AR now so that our scene also supports here we have to delete the main cap because this camera is the virtual camera and it only records the C only give this game view right we want the real world so that we want the AR app to access our camera and then like you know place the objects there so to do that AR Foundation has something called uh AR session origin so what you can do is you can simply right click in the hierarchy click on XR add an AR session origin and then again click on Exon add an ER session now definitely you already know what the serious session object does it basically handles uh all the like you know camera and all the plane management and everything that is out there all the functionalities and this AR session actually handles the whole life cycle of augmented reality and unity so it is mandatory to have both of these components in here now once you have these components what you have to do is just create a few folders the first folder I want to create is called the script folder okay because that is this particular folder is very necessary other than that we want to create a prefabs folder in case we need it and then we also want to create a materials for okay in case reading now I already have packaged the assets for you guys okay it's already packaged in a Unity package so what you have to do is you have SIM you simply have to download that package from the link given below and once you download that particular package you have to import it the process is very simple once you download it you can see that I have this folder called Unity Assets Now what I'm gonna do is I'm gonna either I can simply drag and drop this folder in here right or I can do I can simply click on import package select the custom package go to the location of the folder and simply open it that way you can see that we got a lot of options in here you don't have to like you know get confused between these options what you just have to do is you have to click on you okay once these packages packages are important he will see an assets folder now within that asset folder there is an audio file another one is this jet engine folder which contains the prefab for the jet engine now what you have to do is you have to Simply drag and drop this jet engine in this particular hierarchy and you will be able to see that this particular J engine has been positioned correctly now this is the preferred position this is the position I tested out this application with so that's why I've kept this position if you want to change it like if you want to move it a bit more forward what you can do is you can simply uh you know use this anchor to move this thing uh much more far further from the camera for now I would just want to keep it to 2 as it is much more of a preference and then I have made the rotation to 90 okay you can also keep it that way but I would suggest to keep it true 90 or maybe uh one eight okay if you want to see the front view of uh front view directly from the cap but for now I just want to keep it to nine that way I'll be able to get the product okay and now here you can see that we got our like you know project attempt we got the check turbine India what about the functionalities we need to code something we just don't want to augment this it's pretty simple we just don't want to augment this thing what do we want to do is just a secondary just a second here you can see that this ER session origin is at the top right so we don't want it at the two top we want it at the center so what you can do is you can simply click on this transform like click on this particular session go to the inspector and in this transform you will be able to find this three dots click on that acceptably reset the drop now I will be able to see the object and the game object in here let our bind in okay let's talk about the functionality now within this app we want some Intel activity or is this app will be boring right this is more of an educational application which is going to teach people about a jet turbine so how should we do this now the basic mechanism that I'm going to teach you today is to like you know you can disable the some part of this particular model like let's say if I wanna see the internal parts of this particular like you know this jet turbine what I can do is I can simply disable this Hull to see what is exactly inside this particular jet turbine and if I want I can also enable it okay that way we'll be able to get a much more broader view much better view of this particular uh Jet top okay so to do that it's it's actually pretty simple okay but before getting to that mechanism I want this particular like you know jet turbine that is this particular what is that oh rotor or blades I want this blades to rotate okay so to do that I'm just going to write a very simple script okay so I'm gonna what you have to do is go to the script folder right click click on Create and create a new C sharp you can call this script as uh rotation controller you can name it anything I'm just gonna name it rotation controller as it sounds much better now let the script compile and once the script has been compiled just open it within your Visual Studio or any other editor that you are using I am using visual studio for now so I'm simply going to use that one so give it the tag okay now here you can see that we got the start and update method so let's remove all of these okay we are going to need the update method but before that let's create a variable now we are going to create a public vector3 variable now you will see why I'm why I am exactly creating a vector 3 video pretty soon so given the type okay once you have created this particular Vector 3 variable you have to go to the update method then what you have to do is you have to write transform to rotate to rotate and inside that you'll have to pass this rotation vector and then multiply it with time dot Delta okay so that way you'll be able to rotate your rotational Motors okay that is these bleeds so let's give it the time to load yeah so as you can see once we got this particular script loaded up compiled what you can do is you can search for the turbine and then that is this you know bleed let me show you it should rotate you know something like this so to do that what you're going to do is you can simply like you know first of all select the turbine option once I have selected that just simply add this rotation script in there and that maybe change the Y value let's say uh in which axis is it rotating so it is rotating in the y axis 1 gonna simply change it to maybe a hundred okay and once I have changed the value to 100 you can uh I cannot check if it is rotating by playing the scene so let's see as you can see that yeah we are able to rotate the particular jet turbine in a certain direction okay so our jitterbahn is rotating it seems more realistic now let's add the other functionality that is enabling and disabling the objects in here okay and before we do that we are going to create a simple UI so what you have to do is you have to again go to the hierarchy right click up in there uh go to the UI option then search for this canvas okay now canvas would actually help us to create the UI now I'm gonna shift to a much better landscape view I'm going to use this particular one plus not C to light uh device resolution this is the device that I am using for testing so I'm going to use this resolution for now if you want you can also like you know try to find some resolution of the devices that you want to add and simply click on this add option give give its name and then with that height that way you will be able to create all these options that I have created for myself so let's revert that and here you can see that we got the canvas option now in here you'll be able to find something called uh canvas scalar from there you'll be able to find this UI scale mode make sure to change it to uh scale with screen size once you have changed it this would actually help you to read the UI much more responsive now once you have changed the canvascaler option create a button okay so I'm gonna create a button text mesh Pro now if you are creating a text message Pro button it should prompt uh a tmb importer simply click on import TMP Essentials give it the time to load once that particular thing has been loaded just edit the button once right just uh see if you can like resize it a bit just for uh you know make it to look much more paid up much more you know better so I'm just gonna do it this way yeah this one looks much better let me Center it right so I did Center it now what I'm gonna do is I'm gonna maybe reduce the scale a bit maybe um Point size yeah 0.5 looks much better so let's change it to okay let's change it to point a yeah uh this is much more visible he appoints it much is much more visible and then what you have to do simply click on this uh transform option from there press alt in your key okay if you are on a Windows PC press alt and if you are on a Mac I think option is for an alternative for at all so you have to click on option and then you have to select this particular option so that it anchors to the bottom all right okay now once it has been anchored what you can do is you can maybe like increase the position of it maybe let's see yeah this looks much much more cleaner and let's name this button as Hall okay uh let's copy the name and again do the C add this same for the text and make it a bit bold yeah this now this particular button looks much more clean right doesn't it it definitely looks much more cleaner if you want you can also create a much like you know much better button through figma or maybe some other UI designing I'm gonna use the default one that unit is providing now I'm going to duplicate that particular button right and let's uh let's see what else do we have we have we have the tubes okay we definitely want to disable and enable the cube so I'm gonna give it two okay so we got the tubes in here now again go change the text of it to cubes and then here's a pretty neat trick that I really like just uh add this to maybe one to eighty maybe 100 and then it this this value actually depends on the UI so I'm gonna add it as 110 now I'm again gonna duplicate it right let's uh see what else could we add um we had something called grid yeah we got the grid now I'm also gonna change the name to create then again minus 110 and then again change the text to grid yeah so once every is an uh text to grid I also add another button for the Piston so I'm gonna simply duplicate it name this button paste turns uh copy this again go to the text change the text to past tense then select the button again uh add 110 there and you can see that we got all the buttons positioned properly okay now if we let's say change the UI to something else you can see that uh it is pretty much responsive and it is you know working flawlessly as it should now once these buttons are added okay what you have to do is you have to like make sure that once you click this button it should disable add enable the objects that we have to do that we have to create a script so right click in the project folder that is the scripts then click on Create and create a new script let's call it mesh okay this second mesh problems once you have created the scriptlet compile okay so the script is compiled I have opened it the very first thing you have to do is you have to create a variable called uh game object and name it you know naming a variable is really hard for me it takes a lot of time okay let's name it turbine object okay and once you have like you know added this particular variable the next thing you have to do is you have to create a Boolean back okay let's keep it private for now so private uh Boolean and let's name it is active now of course at the very first of the start of the application all of the objects will be active so we want to set it to true and within the like you know within this particular script you also want to create another function that is that will actually help us like if we call that function it is going to help us to disable and enable the object so to do that I'm going to create a public void that is public function public void Let's uh call it uh toggle now once you write this function what you have to do is you have to check if the phone if the like you know mesh is active or not now we want to check this through this is active Boolean so if is active what you want to do is you want to set the turbine object to false so turbine object dot set active to solve and also change the value of is active Okay that way uh we will make sure that uh like you know we are getting the exact value or able to switch on and off the uh the objects now you have to add an else block now within that is block you have to you know again do the same but in this block you have to turn the object active right that is you have to make sure that objects are true they are the objects are actually on so yeah this says that this this is the whole script this is this new text is actually going to help us toggle between the objects so once you have saved the script simply low let's load it now as you can see that we got the script loaded up now the next thing you have to do is you have to select the objects you wanna you know disable and enable so I'm gonna select the hull then I'm gonna select the tubes then the Piston then the grids okay now I'm simply gonna I'm simply gonna drag and drop this mesh toggle option in here then in the Highlander simply going to drag and drop this file object then in the tubes I'm gonna like add this tubes then in the Pistons I'm gonna set this this object to piston then in the grid I'm gonna do the same for the okay once you have done all of that select the buttons uh go down below to the on click make sure to click on ADD and first of all try adding one okay change uh the next thing you have to do is you have to select the first button uh you can see right once the hull object has been selected if you click on the no function drop down you'll be able to see something called this mesh toggle okay this is the name of our script and if okay if your or if your method right if you are this particular function is public you should be able to see that function in here so I have this toggle function I'm simply going to click on the stable function and let's try this particular you know option up right let's see if it is enabling or disable information so if you click the button you can see that it is enabling and disabling the mesh now the next thing you want to do is we want to do this all of the same thing that we have done till now for the other buttons also so I'm going to select the tube then search for the tubes option drag and drop it in here select the mesh Toggler select toggle then again same for Z I'm gonna search for the grid option in here install your token and again same for the pistol so as you can see now if we play it you can see we can enable the hull we can enable and disable the tube we can enable or disable the grids we can also enable and disable the Pistons we have okay so this is it for this now now of course after you have built this whole application you want to test it out right so how to do that again it's pretty simple you have to click on file click on build setting now you can see that we have the scene active we have the jet turbine scene active now there are two ways to add a scene one you can do is you can simply drag and drop this scene in here and the way is that you can click on ADD openc now this is gonna add the active scene in here that is the scene that is opened up within your editor so it right now I have the jet turbine scene open so it has added the objective and seen in here and once you have added the C you you can either click build and run now the build and run option will only work if your phone has developer options turned on and also it is connected to your device another one would be uh the build option okay you can simply click on build name the application anything fun for the name it jet turbine and then click on save that way your application will start building and you can test your application the way you want okay another thing you have to keep in mind is that if you want to test your application make sure uh the Google services for AR is installed within your applic within your phone you can simply search it on the Play Store and also make sure your device is supported okay that is it supports AR because a lot of the device does not support VR also if if your device does not support your code that that means you won't be able to run this application so make sure to check that out and once you have done all that your build application you have you can simply install it and test the application out by yourself now at the end of this video I'm gonna add a clip that will actually show you the demo of the particular application okay so in this lecture we are actually going to build an augmented reality application that would actually help us plant multiple different plants on our surrounding area all right and to do that we are going to use some specific features such as raycast and uh AR plane managers so without any further Ado Let's uh move forward and to get started with the project I want you guys to create a new project with unity engine I'm using the same version that I was using in the previous project so I would suggest you to go with that same version so right now what we have to do is we have to integrate their foundation and AR code package and I already know you guys already know it but let me show you how you can do that again so first of all you had to go to the package manager then you have to uh like from the package you have to select this Unity registry once you've selected that you have to search for AR Foundation and then simply uh install this AR Foundation version and the version I'm using at 4.2.7 okay so now that we have installed the AR Foundation plugin what we have to do is we have to also install the AR code plug then simply going to search for the AR code plugin in here and simply install it so now that you have installed the arcoexal plugin what you have to do is you have to set up your project so that you are able to build it for your Android devices so go to file click on build settings which are platform to Android now once you've switched your platform to Android you have to go to player settings and from resolution and presentation I would want you guys to change your default orientation to Portrait you can also keep it to auto rotation if you feel so but after that you have to remove this check mark from autographics API and remove the Vulcan API as it is not supported by our code we also have to turn off multi threadrant rendering and also change the minimum API level to Android 7 4.0 once you have done that you have to change the scripting back into i2cpp so that it supports 64 architecture because AR core doesn't really builds for a 32-bit architecture and it may cause you a lot of error and once you have changed your scripting backends what you have to do is you have to put away the plugin management and make sure to enable AR code plugin provider once you have done all of these delete the main camera from your scene then click on exact add an air session origin and then again add and AR session now once both of these are added select the IR session origin add two components arraycast manager and then The Ark in manager now the AR recast manager would actually help us throw raise uh two different different uh like the planes that would be generated in real time and the AR plane manager would actually help us to generate those planes those artificial planes on top of the ground okay by detecting the graph so now let's uh now all there is setups are done right now the next thing what we have to do is we have to import the Assets Now I already have the assets written so I'm simply going to click on import package custom package then select this garden plants asset and simply import it thank you now once the assets have been imported what you have to do is you have to create a few more folder one would be for the scripts now I'm going to create another folder for a material okay so I'm going to show you what exactly I'm creating that folder for and what we have to do in there so once the materials uh just again so once the material folder is created create a new material called uh clean material okay so I'm gonna call it plain transparent mat okay and do one thing once you've selected This Plane material go to rendering mode and change it to transparent and once you have done that go to the Albedo section from there you have this Alpha Channel decrease it down to zero that way you will have a fully transparent material on your hand and once those things have been done also you can try like you know reducing the smoothness and once all of these are done what you can do is you can simply go to the hierarchy right click in here select inksar and then add an AR default layer now make sure to prefab this AR default pin but before that what I'm gonna do is I'm gonna simply select this materials option in here and drag and drop this material options into the element 0. I mean the plane material into the elements once that has been done you have to create another folder called prefabs and then you have to drag and drop this AR default plane and delete it from the hierarchy and then select the ER session origin again and simply drag and drop this clean prefab this AR default plane into the plane prefab holder that is available in the play and match now the reason I did this because you will be able to visualize the planes that are being generated okay so the place would be transparent with a black border you can totally see that in the demo at the very end of the video so whenever whenever you will be trying to scan your ground multiple different planes will be generated and those planes will have this transpend material okay that will actually help you to visualize that yeah there are planes that are being generated and that's where if you shoot the recast it should disable the plane and also place the plants okay and we are going to implement that mechanism right now now let me like make you go through the prefab once that contains all the plant model so if you go to assets you will find this folder called models from there there this folder got plans and in here you'll be able to find this prefab now I think there are in total 12 uh plants that are totally available yeah there are total 12 plants that are available now the next thing you have to do is you have to write the script so that it can hold those plants and randomly Place those plants onto the floor so what I'm going to do is I'm gonna go to a scripts folder create a new script and let's call it plant placement manager once the script is straightened give it some time to compile once the script has compiled what you can do is you can simply open the script in your editor now I'm using visual studio code for this you can use Visual Studio ID too and any other ID that supports unit Engine Okay so let's understand what do we have to do in the script before that let's understand what exactly are we gonna Implement now the basic implementation would be after the ground planes are detected right after the grounds are detected and the planes are placed in there whenever I tap on the screen it should place uh the plants in that particular position okay now of course to make this happen there are multiple components we have to work with we have to work with the recast manager we have to work with the plane manager and we also have to work with the session origin and along with that we also have to store all the hits right whenever you tap on the spleet it should be like it would be registered as a hit so whenever the hit happens it should store those uh like positions in there okay so let's uh implement this whole script so the very first thing is we have to create a placeholder that would actually held all those uh particular plant models and yes so to do that you have to write a public variable uh and you have to give it the data type of game object now it should be an added because we want to store multiple objects and I'm gonna call this variable as flowers okay because it will be story all the flowers that are in there now save this and then go to a unit engine add this particular script to your AR session origin and make sure to add all the plants that are already available okay so I'm gonna go to the prefab and the easiest way to do is to little drag and drop whole like you know plant objects directly in that particular uh array so before doing that what I'm going to do is in the inspector menu at the right of it you will be able to see this lock option so just click on it now if you select any of these models or you can say prefab it won't really change the inspector Mini and what you can do is you can select all of these models right here and once you've selected those you can directly drag and drop it inside this particular script and you can see we got all the 12 elements so you can say 12 plants directly inside this particular placeholder that we created as an array now what you're going to do is you can again unlock all of these so that you don't have uh you know it doesn't get stuck to that property now once you have done that go back to the script again now once you've opened the script you have to reference the plane manager that we have in here okay we have to reference the plane manager we have to reference the recast manager and also the AR session voyage so to do that what you have to do is you have to write three more public variables that would contain public AR session origin okay also I forgot before this you have to include two different namespaces because uh it contains all the necessary functions for air Foundation to be able to script okay so to do that you can simply write using Unity engine dot AR Foundation just a second AR foundation and then you also have to add more ring unit engine dot exact dot AR subsystem okay so they uh these two files that is these two namespaces contains all the important uh functionalities that we need here Foundation to provide us okay so for example this we have to create a new variable and we have to call it AR session origin okay and we have to limit session origin now this AR session origin component is a part of this AR Foundation names okay similarly you have to create another variable and we have to call it AR recast manager and I'm gonna name this variable as recast manager and I'm gonna create another script called ER plane manager because we will be doing a few like you know tasks with the planes that's why we are gonna need the AR plan manager okay so I'm gonna name it plain manager once these variables are set up to what you can do is you can simply go to your unit engine and then from there drag and drop the AR session origin Windows component again drag and drop the array cast manager add also the clean manager okay once these managers have been added in here the next thing you have to do is you have to write an uh you actually have to create a list that would contain all the head positions right all the raycast it's that have been done now I will tell you what exactly is the significance of that but for now let's play in that particular list so you have to make it private private list it should be of type AR recast hit it and then also name it I'm gonna name it recast hits and then I'm gonna create a new object of it so new list array casted and we have created or you can say initialized our list in this particular scenario in this particular script now we also have to write an update condition okay or you can say update group in which we have to check for if the person has tapped on the screen or not okay so to do that what you have to do is you have to write this update function in here once this update function is in place you have to check if the person has touched the screen or not so to check that what you can do is you have to write this if condition if input dot get touched okay and then you have to uh set the parameter of the touch index to 0 and then face equals equals touch phase dot bigger okay this means that if you have touched the screen or not okay and if you have touched the speed the next thing we want to do is we want to shoot a request okay we gonna shoot array cast and once the request has been shot we want to place the objects right random we want to randomly place the objects randomly and then at the variant what we want to do is we wanna uh disable the plane manager and also we wanna remove all the planes or you can say disable on the planes that have been generated okay so that the planes don't really become a blockage to our views so we wanna what we want to do is we wanna disable the planes and the plane manager and the reason why we want to disable the plane manager is because we want we don't want the planes to be generated uh generated all over again okay once they have been designed so that's why now let's get to the first part we want to shoot the request right so what we have to do is you we have to uh like you know reference the recast manager so what I'm gonna do is I'm going to reference the request manager as request manager then I'm gonna click on like you know put the dot and ask for the recast function inside that raycast function you have to pass this input dot mouse position okay now Mouse position in your Android device would actually result in the position of your screen where you have touched right if I am touching at a certain position of your of my screen it will return that particular position within this particular function okay and once the mouth position administrative actually uh I did something wrong in here okay I what I did was I gave this parenthesis India and then a zero in it you don't have to do that okay and once this input Mouse position input.mouth position is there the next thing what you have to do is you have to pass the recast hits uh list that we just created okay now actually the raycast hit contains all the position of the like you know raycast that has been shot so we need this weight cast list and we want to store all the like whenever we are touching right yeah whenever our touch has happened it is shooting a recast so we need to store that recast into a certain uh variable or you can say into a certain list right because we want to access that recast hit because it will be giving us the position and whenever we touch right at wherever position we are touching we want the plant to be placed in that position so recast hit is actually gonna return us those position okay so we are gonna need the recast hits and then what we have to do is here to set the trackable type group plane with uh polygons within more molecule okay and once this has been done terminate the statement with an semicolon now this is going to return a Boolean value okay this is actually going to return us a Boolean value now as this function as this stripped or you can say statement we wrote is going to return a symbolian value what we have to do is we have to store it in a variable Boolean variable so I'm going to call it a collision variable right so whenever this particular Collision Boolean is true what we want to do is we want to place those objects if we want to place those objects on our ground if Collision name object I'm going to call this as object you can also call it as a flower I am going to instantiate that particular out okay instantiate flowers now take the index of the flowers and now what we want to do is we want to generate a random number from 0 to the like you know n minus 1 that is the length minus 1 so that we are able to get all the flowers from that scenario so random dot range 0 comma flowers dot length minus 1. so that way we'll be able to get all the flowers randomly and we'll be able to instantiate them and once these flowers like you know have been instantiated what we want to do is we want to set their position to where we have actually tapped so to do that object dot transform dot position equals raycast hits zero Dot uh pause dot position okay so this is why we are actually why we have actually created that list called recast head because it actually stores the position of the raycast that has been shot onto the ground and that is how we are actually going to place those objects so I hope this particular topic about uh recast hits is pretty much clear now the next thing we want to do is now basically we uh the script that we created this would be enough for this experience to work but the problem with that will will be is that we are generating those planes right so it has some material so it will be visible on top of the ground and we don't really want that because that will be a visual blockage and won't really be looking good at all right so to do that you have to like you know Loop through that whole uh planes and disable them one by one so we are going to write a for each Loop so inside that forage Loop we are going to reference all the planes that are being created so to do that where plane in plane manager dot trackables okay and once uh you have got those claims what you have to do is you have to disable them one by one so I'm gonna call play Dot Game object dot set active I set it to false so whenever the like how much like whatever number of planes that have been generated they get disabled as soon as I touch the particular screen okay and then what we want to do is after the plays have been disabled we wanna disable the plane match of clean manager dot enabled equals Fox so that way uh after like you know after you've disabled the planes we are disabling the plane manager because we don't want any more planes to visit okay and now that we are done with the script what you can do is you can simply save this particular script and go to a Unity engine editor and just make sure you have added all the flowers and also all the like you know components that were there that is the managers you have added all the managers once you have done all of that what you can do is you can simply uh you know change your scene name to main you can also call it app or anything you want and then go to file build settings click on ADD open scenes or you can simply drag and drop the scene in here then go to player settings and change the product name to anything you want now I'm going to name it garden flowers you can change it to anything you like right and once that has been done you can simply click on build and start building the application right there okay and I'm also going to attach a demo of this whole project at the very end so that you are able to see what we have built during this project and if you have any doubt make sure to join our Discord server or you can uh like you know email me you can go through my LinkedIn and ask me there also you can ask it on my Instagram okay and so I hope that you have enjoyed this particular project I will see you in the next part thank you hey everyone welcome to this lecture in this lecture I am going to teach you about building and furniture-based Tryon application so in this application the base idea is that you will be able to place multiple different Furnitures at your room with the help of again AR foundation and AR code and apart from that we will also be able to switch between those Furnitures with the help of three different buttons that we will be designing in this project video now the challenge in this video is uh what happens generally whenever you are like you know let's say we ignore the very basic things right just with the simple placement stuff so what basically is going to happen if you uh like you know touch on the UI buttons it it is going to react with the touchscreen all right by that what I mean is let's say you are trying to like you know Place some object you have placed it and then you are trying to switch switch into some other Furniture also right so once you are tapping that button even while tapping that button it is going to place that furniture in there which is a big Challenge and I'm going to show you how to solve that problem easily in this particular lecture and of course there are a lot of things that we are going to learn and I hope that it clarifies all the doubts you have till now with uh like you know plane managers they cast and all of those stuff right uh so without any further Ado let's move forward and set up the project Source the very first thing you have to do is you have to go to file then build settings then switch it to Android now this is the usual settings that we do before uh building or you can say uh start coding our project so you have to again do that uh whole process again I'm gonna show it to you again so that won't be a problem now once your build platform has been switched to Android the next thing you have to do is you have to install the AR foundation and the AR code XR plugin so to do that just go to Windows uh then package manager go to your Unity registry now it will take a few seconds to fetch the recent packages right uh so give it the time it needs and once it does that what you have to do is search for AR Foundation now install that particular plugin and once AR Foundation has been installed you have to install something called AR codex now let's say if you also want to build for uh like you know iOS devices then along with the AR core plugin you also have to install AR kit plugin right other than that uh there's the only difference is that you have to set up the build settings uh for iOS separately that's that's it there are no more like you don't have to put any more changes uh within your project so once AR Foundation has been installed you have to install AR code XR plugin so search for it simply install it that's it now once both of these plugins are installed the next thing you have to do is you have to go to edit then I think it was Project settings yeah you have to go to the project settings then you have to go to this uh player setting whereability yeah here it is so you have to go to this player settings now the more easier way would be if you if you go to file then build settings then directly so like you know click on this player setting either way you will be getting to the same settings as required now once you are into the player setting way what you have to do is you have to go to resolution and presentation and change the default orientation to Portrait because this is not an landscape orientation application so we need a portrait uh apart from that you have to go to other settings uh uncheck this Auto Graphics API because as of now uh welcome is not really supported but uh recently uh at Google I O Google announced that in the future versions of AR code will be supporting one but the current version we are using doesn't really support uh well you can graphic save me so simply just removed now apart from that we got multi-threader rendering uncheck it we don't need it then from there you have to go to this minimum API level uh change it to Android 7.0 that is API level 24 because that's the bare minimum uh Android version AR code requires to run apart from that we got the scripting backend you have to change it to file to CPP because currently it is set up in mono and once you have done that you have to go to this arm 64 and make sure to check it right make sure it is enabled because arm 64 helps you get the 64-bit architecture support now from there uh yeah almost every settings is settings are configured the next thing you have to do is you have to go to exact plugin management and make sure to turn on AR code plugin provider and that's it your project that is build settings is set up properly now what you have to do is you have to add the current scene to your build setting so I'm simply gonna click on ADD open scenes so that way we set up our whole build process now let's import the assets right let's design the UI first then we will get into the coding part so again I have packaged the assets into a small Unity package called Sony ER dot Unity package now all these assets are already available in the LMS so you to download these assets you have to go to the LMS and get these assets for yourself now just simply drag and drop this Sony share asset or you can say Unity package into your project folder and simply click on import the next thing you have to do is just simply go to the assets folder you will be finding two more different phones one is for the UI it contains three different UI buttons and then we have the Furnitures which actually contain uh the models that we have now if you like you know see on your right side you should be able to see this small window for visualizing the precepts now in most of the cases it might happen that you might not find this window that's because uh sometimes it's minimized so you have to go at the bottom and you can see that there's this two very small lines you have to drag it to the top and you will be able to visualize uh your furniture mod okay similarly I got another one that is this light brown one and then again there's another one called this white show for now this white sofa looks much better than the other three of course but uh yeah this is how you can visualize these sofas and you can also drag and drop it to the scene if you want okay now let's delete it for now because we are not gonna need it as of now the next thing we have to do is we have to create the user interface okay now the base idea behind the user interface would be uh to switch between these models right to switch between these three models now let's create the UI first the very first thing you have to do that I would suggest right this is what I actually do is I dock my game window window to the right side okay then from there you can see there's this drop down call three aspect right now we don't really need this free aspect what we want is we want to use our template now if you haven't really added a template uh like you know a custom template to your game window you can either use one of the already provided templates but I have added a few of these in my Unity project so I'm going to use that shifted to one of my templates and once the template is open there's another thing you should do is uh in the scene window you should be able to find this 2D mode okay so simply switch uh to the 2D mode because that won't be any helpful while designing the user interfaces or doing anything in 2D okay so once these are done the next thing you have to do is you have to create a canvas now simply right click in the hierarchy go to UI and then create a canvas component or you can say canvas gain object now once you've created a canvas there are two things okay one is this canvas now this canvas is responsible for uh like you know setting up the UI and doing all the stuff regarding the UI but this event system is a very important part the reason why it is very important the event system actually handles all the events that is happening within your user interface right for example the tap of a button if this event system is not available what is gonna happen is you will not be able to interact with the user interface at all so it is very important to have the event system if you want to interact with the UI within your uh like you know Unity project but apart from that that's it and now if we take a look at the canvas we got this something called canvas scalar now in here you should be able to find something called UI scale mode this is a very important thing okay because constant constant pixel size is like you know doesn't really make your UI response so you have to change it to scale with screen size which is gonna help you like you know create a more responsive user interface for your application once you've switched your like you know UI scan mode to scale with screen size the next thing you actually have to do is uh like you know create three buttons now you can either use the default buttons that Unity or text message Pro provides us with but here's what I would suggest is going for an image then adding a button component to it it makes it much more easier because uh if you if you go with a button component uh you I mean a predefined button by unity or text message Pro it's gonna take you a lot of time just to set the UI to it delete and that's a lot of hassle that we don't want to go right now into Okay so here's what we are going to do select the canvas right click go to UI add an image okay now I think the proper size of the image would be 200 by 200 so simply go to the this width and height option and change it to 200 by 21 okay and then add a button component okay see without the button component this uh like you know image will just be an image so we need this particular button component uh to be able to dis to be able to provide the button functionality to this particular image okay so once that is done you can change its name to some like you know maybe uh to one of your prefabs or you can say one of your Furnitures so I'm gonna name this one uh white sofa because that is one of the Furnitures and once you uh name this just save your C and then the next thing you have to do is you have to Anchor it okay you have to Anchor this particular image or you can say this button to the bottom left of your uh UI so again to do it simply press alt on your keyboard then indirect transform component you can see that this Center Middle option in here right so select that wrist alt and then simply select this bottom left option and you can see that this particular UI component got anchored at the bottom left of the UI now duplicate it now name it yellow I think it was something called yellow light brown so if I guess yeah it was light brown sofa that now what you have to do is you have to Anchor it to the center so again press alt on your keyboard select the same option then anchor it to the center okay now again duplicate it after duplicating it change its name to Brown sofa then select the anchor again press alt then put it like you know to the right side or you can say the bottom right of the UI candles the next thing you would want to do is select all these three and uh change its position y to maybe 200 uh is 200 too big maybe uh let's go for 150 yeah 150 same reason reasonable and from there select the white sofa change its position X to 150 and select the Browns over and again change Brown surface position it's the minus one quickly okay so that way we got a pretty even uh user interface okay now the next thing you would want to do is to apply this price or you can say the button images to these special button okay so select the white Sosa now in here you should be able to find something called Source image now here's a little dot in here so select that dot and you should be able to find all the in like you know Sprite or images that are already available so I'm going to search for sofa right here and you can see that we got the option for three different so-calls now the first button would be for the white sofa so I'm going to select the white four the second one would be for the light brown sofa so I'm gonna you know check for the light brown sofa and then I'm gonna check for for the third one I'm gonna check for the simple Brown sofa and again it is already available on the top so I don't really have to search point add this way you set up your user interface properly okay now the next thing we have to do is the next thing we have to do is we have to write this to it okay now there are a few things that you have always have to keep in mind and before that we actually have to set up our steel okay we created the UI the next thing we have to do is we have to set up our C so delete the main camera because main camera is not for augmented reality you have to add like you know AR sound sorry AR session origin and AR session so simply right click in the hierarchy go to XR add an a session origin and then again add an AR session now drag and drop both of these to the top because this just a convention that I follow it like you know it makes things much more simpler simpler for me and much more organized Palm now once you have select this AR session origin we have to add two different components okay now both of these components are very necessary for like you know placing the objects into the real world so let's see how you can do the same so the very first thing you have to add is an array cast manager okay now array cast manager would be responsible for shooting the raycasts that would at the very end would help you place the objects at a particular position okay the next thing you have to add is an AR plane manager okay now the AR plane manager would be responsible for detecting your real ground right your real surface and then it would be responsible for generity artificial planes on top of it okay and also reset the Transformers area foundation that would be much better but yeah these are the responsibilities of AR Carson Azure and AR plane okay the next thing I would suggest is to create three different folders one for materials one for prefabs and one for scripts now of course I have my reason so we will get into that now create a folder for called materials okay create another folder called uh prefabs sorry I think I named it wrong yeah these ads then create another Fork uh scripts okay now scripts will be storing the script files the prefabs will be storing the prefabing files and the material for restoring the material sites okay now the next thing we want to do is we want to visualize the planes that are being generated okay so how can you do that it's again pretty simple just right click in the hierarchy go to Exotic add an AR default clip okay simply uh the next thing what you can do is you can assign a material to it it already has a material okay but I wouldn't really suggest you going for that material so go to your materials folder create a new material so I'm gonna create a new material I'm gonna call it cleaner okay now I want it to be transparent so in the in the materials I'm gonna go to rendering mode change its uh change it to transparent and then I'm gonna like you know convert its also value to full zero okay now the next thing I want to do is I am going to select this AR default name go to its material section simply drag and drop my material up in here and then if I go to presack I simply have to drag and drop this AR default plane into the prefabs folder and it will be converted into a preset okay now once that has been done go to your AR session origin and add this AR default link to this plane prefer a preference variable okay so this is it we actually properly set up our whole project so that it can support your foundation and we also set up our UI so what's next okay the next thing is we have to now learn to place the object right switch between those objects and we have to switch it in a way so that it doesn't really affect the placement of our objects okay because uh there is a technique to do that now what uh requirements am I saying this now if you like you know if you use this simple placement stuff that I taught you in the previous lecture video okay if you configure it to place a different object switch between uh like you know those furniture by click of a UI button there will still be a problem the problem is let's say when you are pressing any sort of button in the UI okay it's still gonna place it it's of course it's gonna change but it's still gonna place it when when you are pressing at that button now that is not a behavior we want the behavior we want is when we are pressing on the buttons it should only change these Furniture okay it shouldn't place at the moment we only want to place it when we uh like you know tap on a screen outside of these buttons so that's the functionality we are looking for okay now of course the script is totally same as it was for the previous lecture just with a few modifications and in the previous lecture I forgot uh to write a piece of code okay which is uh very necessary right of course it won't break the functionality within your application it won't crash your application but it's a better option to do it because without that it's gonna throw an exception so let's let's start writing our script okay so you have to create a script I'm gonna name it uh like you know let's say what's your name let's name it furniture place or manage okay so I'm going to name it furniture placement manager okay now simply open the script in your Visual Studio code and once you've opened it just remove the start and update method okay because believe me it just makes things much more uh like you know cluttering just a second it's uh so returning some errors for some reason so let me restart the editor once because sometimes it happens with Visual Studio code this doesn't really happens with visual studio all the time but it I have seen it happening with Visual Studio code all the way so yeah let's remove the start and update method the next thing you want to do is you want to define a few variables okay but before that you have to include a few namespaces now there are two very important namespaces because they give us the functionality they give us access to the apis foundation okay so you have to write these two lines that is using Unity engine dot x r dot AR foundation and also add a Unity engine dot exact dot AR subsystems okay so these are the two namespaces we are gonna require for now of course there are two more namespaces that we need to include but we will go like you know go into that later on in this video itself okay so you have to sing the functionality is the same that is we have to implement the touch functionality we have to shoot a recast to place the objects we also have to implement a a simple function to switch between uh like you know these furnitures apart from that there's another thing that is we have to make sure whenever we are pressing the UI button we don't place that object at that very moment okay so let's write the code for it so let's create the reference variables at first first of all I'm gonna create a reference variable which will be storing our default Furniture okay so I'm gonna call it public uh game object spawnable furniture okay the next thing we are going to do is we are going to Define a variable that will be referring by referencing the AR session origin and I'm gonna call it session i j again I'm going to do the same for the AR recast manager and I'm gonna call it raycast manager and then again the same for uh the plane manager vessel AR plane management when I'm gonna call it plane manager okay and I'm also going to create a private list of raycast hits right so whenever we are shooting any sort of recast into the real world it gets stored in this particular news because we will be accessing this cleanest to get the positional data so private list array cast hit I'm going to call it recast hits equals new Nest requested and voila we actually uh initialized all the particular variables that we are gonna need okay so save the script to go to your Unity engine and let it load now make sure to attach the script to your AR session origin now simply drag and drop the components in me here that is my session noise and then the recast manager and then the plane manager and select the default furniture and you can like you know select this particular dot option in here go to the assets and select the default formation you want to have now I want to have the white sofa as the default Furniture okay so as select like you know set the respawnable for nature to the white sofa now once these are done we have to write uh the functionality so that we are able to place the object into the real okay so I'm gonna explain the logic very briefly so keep your ears open and try to understand it properly so write this update method the very first thing you have to check for and this is what I missed in the previous lecture okay you have to check for if there are any touch on the screen okay then only you have to look for where if the like you know if the person has touched on it or not okay so first of all you have to look for if there are any sort of touch that has happened or is is happening within your particular application so to do that you have to write this if condition if input Dot uh touch count is greater than zero okay and if there are one or more touches what we want to do is we wanna uh start that is we want to check if the touch has happened or not okay so if input dot get touch zero sorry uh you have to put 0 as a parameter because we wanna get the very first touch and then touch dot CS equals equals touch face dot began okay so that way whenever you tap on the screen this particular function is being called okay now inside this function we have to shoot a raycast so raycast manager daughter a cast now inside this you have to provide them like you know touch position now in the previous lecture I showed you that you can use the input.mouse function but in this I'm also going to show you the other way around that is input.getouch.position okay now there are not many difference in it the only difference is that the input dot mouth position Works universally that is it will work for Windows uh MacBooks or any sort of platform right uh where the touch is happening but this input.getouch.position only happens on your Android or iOS device that has a touchscreen okay so let's do it so input dot get touch zero dot position the next thing you have to do is you have to pass the recast hits and then you have to set the trackable type to plane width polygon okay now once it shows the raycast and the raycast has hit that particular ground it's going to return return us uh Boolean value okay that is either it has hit that particular generated plane or not so we are gonna write a Boolean Collision variable okay to detect if the Collision has happened and if the Collision has happened what we generally want to do is we wanna place that object to the position and the like you know to the position of the raycast and uh to the position a rotation of that request okay so it's Collision has happened what we want to do is we want to instantiate the game of the quest so I'm gonna name it object equals instantiate spawnables furniture then I'm gonna set the transform I mean the position of this particular object to the position of the recast head so object.transform dot position equals uh what was it point the cast hits 0 dot pose dot position okay now I'm gonna do the same but for this time for the rotation okay so I'm gonna simply name the position to rotation do the same for the this particular object now once that has been done this will actually help us place the object onto the real world okay apart from this there's another thing that we have to do is whenever we have placed our first object we want to disable the planes right we don't wanna because if the planes are still visible even after placing that object it's going to make the experience very much unrealistic and we don't want unrealism if we are going to build a very immersive uh augmented reality application so to do that you have to Loop through though the place that has been generated so for each where planes in planemanager dot trackables now these trackables actually store all the planes that has been generated so you have to do it like this names Dot Game object dot set active solves okay that way you can set all the game all the plays that has been generated to false and the last thing you have to do is you have to disable the plane manager so that no more artificial planes are generated foreign false now you can save your script okay you can simply save your script and load it in unity but there are a few more things that you have to do okay the first thing you have to do is you have to be able to switch between these Furnitures okay so open your script again see this function is pretty simple it's just a one-liner code you have to create a public function that is public void switch Furniture let's call it to its furniture for now okay then you have to pass a game object as a parameter I'm going to call it for your niche now you can simply what you can do is you can reference respawnable furniture that is uh conversation and set it to the furniture of available as a parameter okay now save it go to your Unity engine now select the UI buttons that you have add an action event action to this on click function drag and drop your AR session origin go to this particular function uh select the furniture placement manager and then click on switch formation okay then select the white sofa go to this white dot and sealing the white silver prefab now do the same for the light brown one too then again the same for the brown soup now once these are done you should be able to successfully switch between those objects okay but this is still a problem okay now see this script is enough for you to be able to place uh like you know data planes then Place uh these Furnitures over to your place but right now the problem that persist is even if you click like while you are clicking on the UI let's say if I am clicking on the UI right now the object will be placed at that moment now this is not something we want there's a very unexpected behavior and a very bad uh Behavior also we don't want that kind of behavior and application you have to create a very simple Boolean function that would check if your own button has been placed or not okay and if your button has been pressed I mean if your button is being pressed you don't want to place at that moment if your button is not being pressed then only you wanna place it okay so you have to write this particular function public move is the return type of that function because we will be returning a Boolean type that is either it would either be of false or either be a true and then you have to name that function I'm going to call it is button rest now before writing the code inside it okay you have to add two more names faces one is for uh the you accessing the UI button that is using Unity engine dot UI then also add an event system per unit because that's how we will be accessing the button so Unity engine dot I think it was called event sisters yeah this is it now once you have added these two namespaces right here let's code this particular function okay so if even system dot current dot uh current selected uh game object now we are going to put this question mark in here now this question mark isn't is more of a short form for knowledge check okay then we have to get the component now I feel like if you don't want to use this question mark you can also use another option called try get component but fauna as I have used already use this question mark I'm gonna use uh the get component in here okay so get component now inside this we have to get the button component because that's uh that's the UI components we will be pressing on okay then I'm gonna check if it has null okay now if the button is null we want to return false that is if we haven't pressed on the button we want to return false and if we have pressed on it then we are gonna return true okay as simple as that now the next thing you have to do is you have to go to this if condition where the Collision is being checked you have to add this and operator and then you have to check if the like you know button press is false or not so is button pressed equals equals false so that way we have completed our script and this script is actually gonna help us to place the object properly without the UI interfering us anymore okay the next thing you have to do is you have to click on sign click on build settings then if you already haven't added the sample scene you have to add that particular scene you are working on then you have to click on build and make you know you can name anything your build now the better way this is uh I like you know I make use of this particular method I create a new folder okay I create a new folder called uh bills now this builds folder contains all the bits that I need okay that way it's uh like I am able to keep track of all the bits that I have built in the previous uh like you know implementations that way I can test for the bugs and all of that so it's a pretty handful method so yeah that's about it this will build the application and after it builds I will try it on and put a like you know attach a video of the demo to uh to to the end of this video so that's it for this lecture thank you
Info
Channel: freeCodeCamp.org
Views: 137,881
Rating: undefined out of 5
Keywords:
Id: FJAO6jDYljs
Channel Id: undefined
Length: 122min 24sec (7344 seconds)
Published: Thu Jul 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.