A Better Way To Share Your Code! (Unity Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey man you got a second oh hey man what's up you know that library you were showing me yesterday the one with the string extensions uh yeah I remember what about it I really like it and I want to try it out with this project I'm working on do you mind if I get a copy oh yeah if you give me access to the project and like half an hour I can type the whole thing up for you whoa hold on you type it out every time you haven't exported it oh sure I do I love writing code that I just know will work it's therapeutic therapeutic I guess I can see that but listen man with unity it's super easy and there's even this new feature where you can create custom packages and then import those packages directly into your project using the package manager window yeah it just kind of looked difficult to do so I never did it oh no way man it's super simple here scoot over let me show you how to do it it's fairly simple in that all the code is located in this rich text class we'll be taking all of this code and adding it to a custom unity package so the first thing we need to do to create our package is navigate to the packages folder to get started all you need to do is create a folder to hold your package I'm gonna call mine string extensions then we'll need to create a package manifest to hold all the metadata and dependencies of our package you do that by creating a package dot JSON file the package manifest is made up of a number of attributes some are required some are mandatory and others are optional if we take a look at the documentation we can see that the name and version attributes are required under mandatory attributes we can see display name description and unity which indicates the lowest unity version that the package is compatible with now these attributes are technically optional you don't need to include them but including them does provide useful information for the user and makes for a better user experience lastly underneath the optional attributes we can see things like dependencies keywords which are great for search ability and lastly the author tag let's switch to the code editor and configure the manifest for our example package the first one we'll add is the name field and the convention here is comm dot your company name dot the name of your package next step we'll add the version and in this case following semantic versioning this is the first major release so I'll just enter 1.0.0 next we'll add the display name and this is what gets shown in the package manager window so we'll give it a nice friendly name string extensions and we can also give a description after that we'll add the version of unity that this package is compatible with and we'll just say it's 2019 and up along with some dependencies in this case it doesn't have any so we can just leave this as an empty object provide some keywords that'll make this easier to search let's say library utility strings and lastly we'll put an information about the author which is me but my name email and lastly a URL to my company's website beautiful now our package manifest file is setup and we can switch back and locate it inside of unity backing unity expand the packages folder and then locate your package and click on the package manifest file we can see here in the inspector that we have a nice editor window so we don't have to keep switching back into the raw JSON to edit it if I ever need to update the version or change the name I can do it right here and on top of that I had this nice button up here that lets me very quickly view this in the package manager and here we can see some of the fields that we had just filled out now that we've got a base for our package we can start adding in the code thankfully my code is already written so all I need to do is drag the files into the correct folders before we do that why don't we take a look at the package layout convention to get an idea of what folders are expected in a unity package taking a quick look at the documentation we can see that we already have the package JSON file but we're missing quite a few of the other files and directories for instance we can see that by convention if we add a readme changelog or license markdown file that those will be included in the package manager window on top of that we can see an editor and runtime folder that will hold our source code as well as a test folder that'll hold each of the editor and runtime scripts tests respectively and then under that a documentation folder that will hold a markdown file for our documentation in our case we're just going to create a runtime folder to hold our scripts and a corresponding test folder and then for each of those we'll create an assembly definition file so back in unity again we're going to add a runtime folder and of course a corresponding test folder now we can just drag our rich text file which contains all of our source code into the runtime folder and then our rich text test folder into the corresponding tests folder perfect now the last thing we need to do is add some assembly definition files for the runtime folder it's as simple as hitting create and then assembly definition and we're gonna call this comm dot infallible code dot string extensions following the same convention we used earlier with the name of our package and we'll do the same for our test folder but this time we're gonna call it comm dot and fallible code dot string extensions dot tests now for our test assembly we're gonna need to add an assembly definition reference to our main assembly so we'll go ahead and do that as well as a reference to the unity test Runner assemblies and then because I want these to be edit mode tests I'm gonna go ahead and uncheck any platform deselect all and then click on editor that way editor is the only platform included all right now I'll just click apply and we should see in the test runner that the tests have been loaded and that's how you know it worked when we go ahead and run those for good measure beautiful love seeing that green and now believe it or not we're done we can test this pretty easily by going into the assets folder of our project creating a new script just call this my behavior opening that up and then we can go ahead and just add a start method here and then make a reference to one of my string extensions will call bold and it worked we can see I have a reference to it fallible code string extensions which is the namespace that belongs to my source code and that package is completely encapsulated and can be pulled into any other project in fact why don't we go ahead and do that so back in unity we can see that the project is fresh and there's no reference to my package I've actually moved the whole thing to the desktop of my PC to import it all we need to do is select window and then open up the package manager and then hit the plus sign on the top left hand corner and click add a package from disk from here I can navigate to my desktop select my package folder and then select on the package JSON file and click on open and we can see that it's been imported into my project now of course this is just one way to import your package a more preferable way would be to host it on github and then use a github URL that way you can version it and keep track of its progress much easier but we'll save something like that for another tutorial dude this is awesome you know I've been meaning to extend the color method a little bit more so I think I'm gonna upload this to github and work on it Thank You Man I really do appreciate it and thank you for watching this video if you've been enjoying these little skits I've been doing then please leave a like and a comment letting me know what you thought thank you for watching and as always I'll catch you in the next video special thanks to dark rush photography NZ Thomas Trond and Wayne glows
Info
Channel: Infallible Code
Views: 18,113
Rating: undefined out of 5
Keywords: unity, unity 3d, unity tutorial, unity3d, unity 2019, unity 2019 tutorial, unity package manager, game development, unity assets, unity 2019.1, unity 2019.2, unity 2019.3, unity 2020, unity 2019.4, game dev, gamedev, game programming, game developer tips, unity tips, unity tips and trick, unity tricks, tutorial, learn, games, make a game, tutorials, how, development, develop, c#, howto, how to make a game, programming
Id: OhwP5TYgucM
Channel Id: undefined
Length: 9min 38sec (578 seconds)
Published: Fri Oct 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.