Transcripts
1. 101 – Introduction to the Course: Hello, everyone, and welcome to the scores about making a menu system for your trading card game. The scores is brought to you by my good friend. His name is Sander Kiss. He's an instructor and entrepreneur, and he shares my passion in trading card games. And my name is Vladimir Lee Marchenko. I am a unity developer with about three years off professional experience, now making mostly to the games and just recently making trading card games as well. A while ago, be already made a trading card game course together, and it was fairly successful. Our first chorus covered the topics off battle mechanics in trading card games. So making that trading card game battle when you get to play your creatures and cast your spells. So all of that stuff was covered in our first course, and the second course is dedicated entirely to making menus for a trading card game. So in this course I will show you how to manage the collection of guards that you have in your game, how to filter this collection by different parameters so that you can select the cards with a certain man, accosts the cards that contain certain keywords, the guards that belonged to certain character type and so on and so force. So all these features, they will be included into our menu system. Also in the scores will cover building custom decks from the cards that you have in your collection, and players will get to save their decks and pre make their decks so that when they want to enter play mode, they get to select one of the decks that they have previously created. So that's another challenge and another thing that will discuss in this course. And of course, the most exciting thing in trading card games is purchasing new cards, maybe new packs of guards, opening them up and seeing what kind of amazing guards you now have for your collection. So we'll also make a very simple shop and a back opening screen to show people what kind of cards do they have and to make their card collection more diverse. And also the material that we make in this course is not just isolated menus. So, together with the man use part of the course, you also get a fully functional battle scene that we have assembled in the previous scores so that you can make a custom deck at some custom cards to the project and instantly try them out in battle. There are some things that this course doesn't include, and I know that people have requested them. I'm working on them, and for now, they're not ready. So this course it focuses just on the menus, so it still doesn't have the multiplayer aspect to this game. So the project that will review and that will make in this course is still single player. You can treat the battle scene that you enter in this project, sort of like a boss battle, so you can pre configure a deck for your opponent, and you can come up with a custom deck for yourself and battle the same boss sort of over and over. But it explains all the main concepts off building trading card game menus, so it is still a single player project, but now it features quite an advanced system off menus and managing your card collection. The second limitation of this course is that it's made for more advanced students for people who have some previous experience with unity and C sharp because along with the basic techniques will be using some more advanced things, like link and do between cleaning engine. But actually, it depends on the person. I've seen people who were complete newbies who picked up the first course, and they came up with some amazing, unique projects. So if you have fashion towards trading card games than anything is possible, I encourage you to pick up this course and you learn a lot along the way. Thanks a lot for watching this intro, and we are excited to see you in the next lectures of the scores.
2. 201 – Introduction to Section 2: Hello, everyone. And thanks for choosing to watch this course in this intro for Section two Firsts. I wanted to say a couple of words about this course in general while I was making this course, I was saving the projects that I was working in occasionally. So, of course, you can download the projects in different states of completion of the scores. But my suggestion for students in all of my courses is always download the final project first, the final project is always the most recent, the most error free. And my suggestion for this course is not any different. If you want to follow along with this course, IRA command you to download the final project. It will have the word final in the title. So download that and then watch the videos from the course and treat this course more like a how to assemble some things in unity, how the code works and so on and so forth. So there is no need to recreate all the Y and all the hierarchy structure in this scene when you're following along with the course. Another thing that I wanted to let you know about the course and my courses in general. If you have any questions, please ask them in the Q and A section I treat you and Avery seriously. And usually I answer questions within 24 hours, sometimes even faster than that. So if you have any questions, suggestions, interesting ideas, just ask the question in the Q and A and I'll reach out to you and try to help you with your ideas. And in this section, the first educational section off our course will mostly talk about cards. We'll talk about storing cards in our project so these objects in our S. It's folder, they are actually cards, and I can switch them. They have different images here, and these fields are all the fuels that are required to describe one card in this project, these files or assets in our Essence folder there called Script Herbal Object Assets, and we'll talk about what they do, how you can make these what they mean in depth in the next lectures in this section. Another objective off this section is to check out the script card collection that a let us keep all the information about our cards in certain order will be able to sort cards, filter cards and so on and so forth. It is very useful script that is used across the whole application for different purposes. And finally, in the last lecture off, this section will make this simple menu. It will be made with unity. You I and it will have all the menu items that who have, even in the final version off our application. So this play button it'll take us to play mode will be able to select the deck and play against the AI or against ourselves. This collection menu item is the most complex. It will take us to collection browsing and will be able to build a deck if we go into this collection. Many item and this next shop item is probably the simplest. One will be able to buy packs and open booster packs and add new cards into our collection , and this quiz item will just quit the application. I would like to thank you for watching this course, and I am looking forward to seeing you in the next lecture
3. 202 – Storing Cards as ScriptableObject Assets Part 1: Hello, everyone. And thanks a lot for watching discourse about making trading card game menus. And before we start developing the app and actually making something, I wanted to talk about how to be handled cards in this project. How do we store this info about cards? And essentially, if you think about this card is just a certain collection off data data about their stats, data about their abilities and also dated both images that he used and the text descriptions and all that. So in this project, we store them as so called script herbal objects. So if I go to assets the root of our S folder, our cards, they're stored in this resource is folder and unity treats everything that is under the resource is folder as stuff that you can access on runtime so later will actually say resource is load all off type guard asset, and we'll get all the card assets from our project. So if I go to my folded resource is there is a sub folder s O assets. We have two kinds off assets in our project. One of them is a character asset that defines the character class for example, in Harsh Stone, there are nine character classes, and in this project I have only made two of them. But you can extend the amount of character classes and add your own, and then we'll have cards. They're split up into two categories and two folders here, creatures and spells. So let's open the creature folder. And, as can see, each card is a separate object in our Assets folder, and we can create them by right clicking I can go to create, and here I can select card asset. So if I press on card asset, let's do that. It will create a new object like this. It will be called New Card Asset. I can give it a custom name something something hit Enter and then I get to edit this guard and this card is automatically added into my project. It will be loaded through resource is load all So we have just created a new card. I will not need this card, so of deleted for now. And let's take a look at some of the existing cards in our project and to understand how it works faster, let us take a look at what we get here in the inspector side by side with the script that defines our card Essent. So I'll go and open my model develop. And here is a class that defines the card in our project. We have several fields and all of the fields that we get here. They are reflected over here. First, let's start from the beginning, the classes gold card asset and it's a script herbal object. So making our card asset script herbal object It enables us to create these guards inside off our assets folder, but right, clicking and selecting card asset. And to do this, the first thing that you have to do make your class scriptural object. And the second thing you have to write another custom class to integrate it into your unity editor. Luckily, that glass is very short. So if we go over to the next class that we have here, it is gold card, unity, integration and this class it is supposed to sit inside of the editor folder. So if I go over to unity, will go to our assets scripts. So where these scripts that handle card assets are S. O s. It's scripts. Guard asset. There's our card asset, and right beside it we have an editor folder. So these are the scripts that take care off unity, integration so that we right click and we get this option in the menu, create guard assets. And there's another script that is a custom inspector. So if we made it without the custom, inspector, our inspector for card assets would look pretty blend, and it wouldn't be as convenient to edit everything. So in this lecture, I think we'll discuss this process off, creating script, herbal object assets in Unity and in our next lecture will take a look at the editor that I use for card assets. So one of thes scripts card asset, unity, integration, this one. As you can see, it's really short if we go back to mono develop. It looks like this. So it is using the Unity editor. It is aesthetic class gold card unity, integration. The name doesn't matter that much. We have an attributes. So these things in square brackets, they are attributes. This one is used in Unity Editor. It's called menu Item, and we specify where in our right click menu will have this option off creating card assets . So we have put it in assets, create guard asset. We have a public static method, create your scriptural object, and he just calls a method on some other class scriptural object utility to. And this is just a piece of code that I found on the Internet that helps us creating these script herbal object assets, and it takes care of the process. So if we take a look at it, it's also a very simple, very short class that contains Onley several lines of code, and it'll create an asset off our type t. So this method create asset is a generic method and it will create the asset in the folder where we currently are in the editor. So making all these like clever manipulations, it enables us to create these script herbal object assets in our S. It's folder and actually it is really big deal for us. So it enables us to store all the data about our cards and easily added them. Add new cards were removed cards, so it is very convenient. And now I'll return back to our card asset class and also go over to assets resource is as oh assets. Let's go to creatures and select the first cart so that we can see our guard asset inspector here. And also we'll take a look at the glass sideway side. So the first thing that our card, as it is, is a script herbal object, and second, we can make it implement any number off interfaces, and in this case, we want to make our card assets comparable. So we want to be able to compare one card acid to the other because in our project will sort our card assets and the sorting will happen according to their mana costs. And the second criteria off sorting will be their alphabetical order, so that when you select the cards that have a certain man a cost if they all have a man accosts off three, for example, individual cards will be sorted in alphabetical order, and it's really convenient
4. 203 – Storing Cards as ScriptableObject Assets Part 2: all these public fields that we have, they translate really well into the stuff that we have here in the Inspector. So we have had, er, general info. There it is. We have a public character asset character asset so it will define to which class does this card belong? If it is set to none or no like it is right now. It means that this card is neutral if we make a change and will drag some character asset from our projects onto this field than this card will belong to certain character class. Then we have this next view that is public string description. And if we just had its say public string description without this attribute text area, it will be just a plain one line string. And since we want to be able to see better and edit it easier and more convenient, we have added this attribute text area. So we have a two line tax spokes and these numbers two and three there the minimum number of flying's. So currently we have just two lines in the text area and it will start typing. And if the description will be very long, then it will expand as much as three lines. Next, we have a similar text area for tags and the tags there, just some added criterias that will show up in search in our collection. So, for example, here I wrote an example tag that is called Death Rattle. Although this feature doesn't really have death rattle and something similar to death right in harsh Stone. But I've added this tag, so if you'll search for death rattle in our collection search, you will get this card show up. Then, compared to the previous project off my previous course, I've added one new feature to the cards, which is rarity. So if we have the collection and if we want to open the backs rarity, it really makes sense and place nicely with the concept off the game. So the cards there separated by rarity, and they can be either a basic, common, rare epic or legendary, very similar to harsh stone. And I'm often inspired by this game because I think it's just amazing. We have this in, um, public rarity options sitting here on top. So there are several hair helper Denham's inside off our card asset class file and they will be accessible throughout the whole project because they have we have made them public . There is also this other in I'm targeting options that will be all the way down at the bottom off our card s class. And also we have an enema that defines the type of a card. And in this project, we don't have weapons. We don't have secrets. So we're keeping it really basic. And we have just creatures and spells. And next, let's go over all the next fields in our card asset. Next field is the public sprite card image. And instead of having just this field, it's as card image and beside will have just the name off the Sprite. So you can't actually see this. It would be actually helpful if you could see the sprite that you're using on the card. Because you look instantly remember and you will have an idea off. Which guard are you editing right now and which properties that you want this car to have? So I am using this thing that it's called preview Sprite. There is this script somewhere in my folder that enables this custom attribute, and it makes this sprite, not just empty, blank like card image and nothing else. But it adds this little preview below the image so that you can see which sprite you're using right now for this card, and I think that it's pretty need. I will not stop on this preview Sprite thinking for now because they haven't road this. I found it somewhere on the Internet, and I'm using it. I think it works quite nicely in our project. Next, we have public integer mana costs, so each guard will have its own mana cost where we played, and it will be really important in collection, so we'll sort the cards. But there, man accosts and also you will be able to filter the collection and show on Lee the guards that have a certain man a cost. This next field is also really interesting. It is a public Boolean token card, so there are some cards that you might not want to show them in collection, and you might not want to let players at this card into your deck, for example, like in harsh stone. If you go second, you get a coin card. So there is a Korean card in the game, but you cannot see this card, and you cannot add this card to your deck when you're building a deck. So for this case, I've made this bullion that is called token card. So if you don't want this guard to be featured in your collection and if you don't want players to be able to add the card to their decks, then you just check this check mark and said it to true, and then they will not be able to add it to their deck or seat in their collection. The next line override limits off this card in the deck, so there is usually a limit to the number of the same card that you can use in the deck. And in our project, there is a central place where we set this limit. It is currently set to, so you only can have two instances off the same guard, for example, this one in the deck and if you want to make it different, so currently set to minus one so it doesn't make any sense. If you want to make this limit different, for example, like in Harsh Zone, you could only have one instance off a legendary card in the deck that you said this override limit to one. Or maybe you want to have some of the cards. You want to have three instances off them in the deck than you said this to three. So this number it serves this purpose here override limits off this card and deck. Then I've made these, like sort of spaces and enters here to make this next field public types of guards type of card visible so types of cards is our Inam that defines whether it's creature or a spell. And it plays a big role here in our card assets script because it'll also change how the editor for our card looks so currently it is a creature we can change it to a spell, and spells are much simpler than creatures. If it is set to spell, then our whole game, our whole engine will treat this card as a spell. It'll look like a spell. It'll play like a spell, and, uh, the whole behaviour of the card will change four spells. We have several fields that are listed here. Spell script, name and ah, I'll jump back to mono developed to show this to you. So we have the Hatter spell info. We have the spell script name here, and four spells will have to ride custom scripts to define what the spelled us. So either it can deal damage or it can, Hugh. Or maybe it can give you a man a bonus, like the Korean card. So Spells will have custom scripts written for them and to attach these custom scripts to our cars will have to list their names here in this spell strip name field. We also have this special spell amount. For example, you can have a coin card that gives you one man a bonus for one turn. Or you can have another card that will give you hire man a bonus for one turn. For example, in harsh stone, there is a dream guard that gives you two man of bonus for one turn. So just by changing this spell amount, you don't have to come up within you spell script. You can just control the amount off, man, a bonus or amount of damage with this special spell amount and also the targets. So some of the spells they don't have any target. For example, a spell that says Do five damage to all opponents. Creatures. It is a powerful spell, and when you played, you just drag it onto the battlefield and it just deals. It's damage. It just plays its effects, so you don't have to select any particular target on the battlefield. You display the spell, and it does the job. And some spells, they say something like Deal six. Damage to a target or deal one damage to an opponent creature. And for these spells, where you can actually select the target, you can select the group off available targets for the spell here. It might sound a bit complicated, but spells they might target either old creatures, so this limits the group of targets with old creatures. You can no longer target your character and your enemy character so Onley creatures. You can target enemy creatures, or you can target to your creatures old characters so you can basically big any target for your spell enemy characters so you can target either your enemy hero or his creatures, or you can target your characters so yourself or your creatures. These are all the available groups of targets in our project. And if we go and select creature here, this is a bit more complicated for creatures. We have some other properties, like, let's go back to our project Max Health. And here we can see not as simple integer but as this range sort of selector so currently set to four. And by controlling this range slider, we can easily change the value. Oregon, just type it in here. So we have our max health, the starting health that our creature uses when he enters the battle. We have his attack and it can change from 1 30 just in case we have our attacks for one turn. And by altering this value off attacks for one turn, you can make your median have something similar to wind fury effect in her stone when a quick can have to a tax return or maybe three or four attacks per turn. So it might not be appropriate for some games, but it might be perfectly fine for the game that you are planning to make so you can select the amount off times that your creature can attack the return. You can also make your creatures be able to charge so you plays and it can instantly attack . Or you can make them taunt. So you make it so that other creatures, your opponents, creatures, they have to attack this creature first. And this is pretty much everything that we need to know in order to make a creature in the game or a spell in the game. So this set of data, it defines everything that we need to know about our card in order to make it and show it to her players and know which properties does the card have? And I almost forgot this creatures they can have their own scripts that can give them certain abilities, for example, creature scripts they can give your creatures battle cry, so the fact that it causes when it is entering the battlefield, it can also give your creatures death rattle something that happens when your creature dies . Or you can make your creature scripts execute some crazy effects. When certain events happen in the game, for example, this creature it has the fact that it's called bite owner. It'll deal to damage to the owner of this creature in the end of the turn. So this feature, it is pretty overpowered by its stats. So it is a 44 creature, and it costs just to Mana. Since it is a bit overpowered, you gotta have some sort of a setback off having this creature. So by the end of each turn, it will bite your player for two health. And I think that this is gonna be it for this lecture. So we have discussed everything that is related to our card asset and storing this data in our next lecture will discuss sorting our card assets. So we have this card asset also derived from I comparable interface were implementing this interface. It will discuss that, and we'll also take a brief look at the customs inspector for our card asset. And how are we able to hide these fields or show these fields in the inspector when we change from creature to spell and actually fields, they're always there. So even when we select the creature, it still has the spell strip name. It still has the spell script amount. They just don't matter if this card is a creature, that's why they're hidden. And if we go to the inspector. You can actually switch this inspector to debug mode so I can right click and switch it from normal to debug. And you will see this. So we still have our special creature amount spell script, name, special spell amount. We have our spells targets. So our card assets, they have all this data stored in them and we can either show it or hide it by using a custom inspector. So I'd like to thank you for watching the course and will complete our discussion off guard assets in the next lecture.
5. 204 – The CardCollection class Part 1: Hello, everyone. And thanks for watching this course. You already know everything about card assets and this class that is called the Card Collection. We have seen it in the scene. And if I minimize Monta developed again, it is attached. Do this object guards and chars or characters by name. So we have the card collection and character assets by name, and we should have an instance off this glass somewhere, at least in our menu seen. So I have done that. And now if we go back to mono develop, let us check out what this class has and what it does. It is not long at all about 100 something lines, and it could have been shorter if I removed some of the comments. It starts with a public integer default number off basic guards. So, just like in any card game, if you launch the game and you don't have any cards, it is not going to be fun. So in every single card game, you should have some sort of basic guards in the beginning off the game and and we're just setting the number off guards that have the rare ET off basic to be equal to three. So you launch the game for the first time, and you have three off each off your basic cards. But you can edit this number yourself, and you can make it whatever you like or if you want. You can even make the default number of basic card zero. Exclude the basic cards entirely from your project and make your players have no cards. In the beginning of the game. It is entirely your choice. Then we have this next field public static card collections. So it is a variable off the same type, and it s static. Instance. And here in a week, we say instance, equals to this. So this glass is actually so called lazy Singleton. And we do this because we only have one instance off this glass at a time in the scene. So we don't want to create several card collections. We'll always have just one. And to simplify the access to this glass from other classes will be able to just say card collection, dot instance and get to this glass. So it's really convenient. Next, we have several dictionaries. The first dictionary is off type string and card assets, so we'll have our string keys and guard asset values. It is gold old cards dictionary, and I think that will include the cards into this dictionary by their names. So in Old Cars Dictionary, you'll be able to get a card with a certain name. And then we also have another dictionary that has keys off type card asset. And it has values of type integer that is called quantity off each card. So in this dictionary will actually keep track off the cards that our player currently has . So for each card he will have a certain number like he has three of this card for of this guard and so on and so forth. So this dictionary quantity of each card will keep track of that. And we have to initialize thes dictionaries with something so you can just put semi colon in the end here. So you're saying you dictionary and they're both initialized with empty dictionaries off their type. Then we have a private card asset array that it's called all cards array, and we're using it right in the beginning off our awake method. We say old cards array equals two resource is load old. Like I said in the BDS lecture and load. All is a generic method, so you can pass a type and we're loading all the card assets. And as a path to where inside of our assets folder would be like to search for guard assets were passing in empty string. Several search everywhere for all the card assets that we have in our project. So by this time this glass has already found all the card assets that you have configured in the project. Then we iterated over this array off all the card assets and we say for each card, s etc. A in old cards ary. If this card has not been added to our old guards dictionary, then we are adding this card into the dictionary. So we say old cards, dictionary add and this method takes two arguments. The 1st 1 is a string, so a key at which is the name off our card acid. So we say, see a dot name and it's the name off our script oval object. And the second argument is our card assets. So we say, see a and then in awake. We also want to load the quantity off our cards and in this project will store them in player preps. So we'll find a way to right this info about the quantity off each card that our player has into player preps. But I wanted to look at this method a bit later. If you look at the top off this glass, were using something interesting and you name space. Well, for some, it might be new. For some, it might not be new. I have not used Link a lot before making this project. So it was new and interesting for me, were using system dot Link, and we use link to filter the collection off our cards in many different ways. And I wanted to scroll all the way down to the end of this class and show you the method that is used most often the and it is responsible for getting subsets off our whole guard collection. So else grow a bit lower and here in the very end off our class, we have the method get cards. It is, as the comment says, the most general method that will use multiple filters. As you can see the method returns a list off guard asset. So it is a certain collection off our card s, it's and it will return all the card assets that satisfy all these different criterias that we have here. So let's run through them real quick. So the 1st 1 is cold showing cards Blair doesn't own. And if we have some card that we don't have So the quantity off this card in our collection is equal to zero, we have a choice. Either we want to show these guards or we don't want to show these cards. And in Hearthstone, this is somewhat similar to the crafting mode. So in crafting mode, you are able to see even those cards that you do not own and you are able to craft them. So for this purpose we have this Boolean here were either showing these guards or we are not showing these cards. Then we also have this bullion that is called include all rarities, which is pretty much what it says. So we can either include guards off a certain rarity or we can include just all of them. We also have a boolean include all characters, So if we want to include all characters. We will show both the neutral cards and the cards that belong to any off our characters. If this Boolean is set to false than will either show the neutral cards or will show on Lee the cards that belong to a certain character Nextel scroll a bit further here, then we have an option to specify the rarity of cards that we'd like to get. So if include, all rarities is set to false, then it will take this value off rarity, and it'll return on Lee the cards that have a certain verity currently set to basic. But you can change this, and you can select legendary cards or rare cards or any other set of cards. Next, we have a character assets. So if this brilliant include off all characters is set to false, then if you have this asset equal to know, you will get all the neutral cards. If you have this asset set to one of the existing character assets in your project, then you'll get only the cards that belong to that character. Next feels to have the strength keyword, and it is a string that you type into that search bar in the bottom off your collection tab or collection screen. It's just a matter of how you call it, so you can type a word into that input field into that search bar, and it'll show you on Lee the cards that feature this word, either in their name or in their tags. Or maybe in their description. Next, we have an integer mana cost, which is very important for filtering our cards. So if the man accosts will have its default value minus one, which doesn't make any sense, then it will include the cards with all the mana costs. And finally we have a Boolean include token cards, and we spoke about the token cards in the previous lecture. For example, according card is a token card, so you don't want to allow your players to feature this card in the deck, or you don't want to allow them to see this card in their collection. So I think in this project, I'm not using this at all, and this value off include token cards is always set to false. But if you want to show the token cards for some reason than it is also fine. And then we have some link code here and actually were just using the same operator that it's cold Where? So first we get all the cards and I don't know if it is even necessary. But we say var so it will determine the type by itself cards, which will be a collection off our cars. So it says I innumerable off type card asset. We are selecting from our old cards array and we say from card select cards. So we're just selecting all the cards that are in there and putting them into our collection that is called cards. And then we are gradually applying all these filters that we have listed here. So if we are not showing cards that the player doesn't own than we have to exclude them. So we exclude all the cards that have the quantity off zero in our collection. So we say cards equals guards. Start where, and we select only those guards. So here there is a bit of this weird syntax with an arrow and everything. I suggest that if you're not familiar with this, you should look it up in a C sharp book or somewhere online. So we select only those cards that satisfy this criteria quantity of each guard, which is a dictionary. And because it's a dictionary, we can use this card as a key to the dictionary. So we use sort of an array like Syntex. But in these square brackets we don't use an index. Instead, we use our card. So we say quantity of each card. In these square brackets we have the same card is greater than zero. So we select Onley those cards that our character actually has next. If we are not including token cards, which happens all the time in this project than we are saying that we want to leave Onley those cards that have the buoy and token card set to falls. So each one of these, if statements and of these cards, equal statements, it makes this collection off guards more narrow and more specific. Then with the next if statement, if we are not including all rarities, so we want to include only one off our rarities, then we select only those guards that have a certain rarity that we have specified here as a parameter off our method. If we're not including all the characters. Then we want to get on Lee the cards that have character asset set to the value that we have specified in the parameters of this method. Next, it's a bit more interesting and not so trivial. So if we have key word and it's not equal to no, it is not equal to an empty string. Then we are selecting all the cards that contain this keyword. But to make the search easier, I didn't want capitalization off letters to matter at all. So each of the strings that I am comparing if it contains something, I'm putting it to lower case so that the case doesn't matter. So if you type old the letters uppercase one of the letters uppercase all of the letters lower case, it will be just all the same. And we're checking if this keyword is contained in our cards name or if the ski word is contained in our cards tags and we want to also check that the ski word is not a space. So if you type in a space symbol, it will not matter at all and you might get all the cards and this is not exactly what you want and then we have a man accost filter that is also a bit clever in our project. If the mana cost that we pass into this method will be equal to seven, it'll mean that we want to select the cards that have a man accosts off seven and greater. So we'll select all the cards where card mana cost is greater or equal than seven. So we'll include 789 10 11 and whatever higher man accosts you want to have in your game and else if mana cost is not equal to minus one. So if we have to filter our collection at all and if we have changed and modified this man a cost, then we'll select the cards that have the mana cost that we have specified here. So this will be true for 01 and all the way through to six. In the end of this method, we save our which in this case will be a list off card asset will say cards to list off type card asset. So this is something that we're going to return and we also say returned list dot sort and it'll sword our list based on that method compared to so the cards, they will be first sorted by their mana cost. And in each Mana cost group, the guards will be sorted in alphabetical order. So I think that this is going to be it for this lecture. Now, I think you understand the most complex part about this class and about managing your collection that you have all the cards, all the card assets that you have defined in your project. And you want to get certain subsets from this collection and you have this very general method that is gold get cards. And based on all these criteria that you can put into this method as arguments, you can select certain subsets off guards and the can be really, really specific. For example, you want to select the guards that have the mana cost off. Six. At the same time, they have to belong to a certain character class and they should have certain keywords in their name or in their tags, and it will return you this very narrow and very specific list off guards that satisfy this criteria in the next lecture will take a look at the rest off the methods in this card collection class. Some of them just used this method. Get guards to make it less general search. And there are through methods for saving and loading the cards that our player has into Player Braff's so thank you for watching and I will see you in the next lecture.
6. 205 – The CardCollection class Part 2: Hello, everyone. And thanks for watching the course. In our previous lecture, we have started looking at the class that he's gold card collection that takes care off, storing the data about all the cards that we have in the project. It is also responsible for knowing which guards are player has and how many of them does he have. And we can also use this very general method that he's cold, get cards to get certain subsets off all the cards that we have in the project. And now that we have covered this the most difficult part over this glass and maybe even of the whole project that we're working in, let's take a look at some other methods that we have in this glass. So there are these two methods. Get guards of character and get cards with Rarity. And I have several lines commented out in each of these methods because I used an old way with separate doing query to get a collection off thes cards. And now that I have this very general method get cards, I can just call that method. So if we are searching for cards that belong to certain character then we just passed the following arguments into our get cards. True. So we're showing the guards that player doesn't own. Yes, we are including all rarities, which is also true. We are including all characters, which is false. So we want to get the cards that belong on Lee to this character. Asset character Asset acid Rarity options Basic. We have to say something here because these are optional arguments and this argument rarity options basic. It will not matter at all because we are including the guards off all rarities. And now that we have got to our character asset, we can just see asset and all the other arguments. They will just be set to their default values, so the key word will be set an empty string. The mana cost will be set to minus one, so we'll include all the mana costs and include token cards. It will be set to false so to the default value in our get cards method, and we have a similar method that is gold get cards with rarity, and this time we don't have to get as deep into these different arguments that we have in our get cars method, so we are showing cards that the player doesn't own. We are including all rarities. We have it set the false because we want to have a specific rarity off guards that is returned by this method. And we want to have cards off Rarity that we have specified as an argument off this method , and I can instantly tell you where we use this method. This method is going to be used for getting certain cards from our packs. So when you open the back, you want to generate a card of certain rarity, and you want to make sure that characters are not ultra lucky and they get legendary is not that often and the yet common cards more often and so on and so forth. So when you are opening a pack, you want to generate a card of a certain rarity, and that's where we'll use this method. There are these other methods. We have a method guard asset. Get guard acid by name, since we have this old cards dictionary that contains all the cards that we have in our project by name, and there might be a situation where you made a typo somewhere, and it wants to search our old cards Dictionary four and name that it doesn't even have. So then we are checking. If all cards dictionary contains the key, then we return all cards. Dictionary with the key off name and elsewhere We turn no so there is no such guard acid in our dictionary on application quit. So since this glass is Amona behavior, we can use methods like awake and on application. Quit is also part off Monta behavior. So when we quit the application, we want to save the quantity off guards into player preps, which is this method, and it's cold exactly like that. And when we are just opening our scene and the scene is loaded, this awake method will be cold, and we'll load the quantity off cards from player preps into our quantity of each card dictionary. First, let's take a look at saving when we're saving something into player. Perhaps we are iterating over all the cards in our old cards array. If the rarity off this card is set to basic, then who put this integer into player breaths and player preps is a certain place that is not wiped even when you close the application and it works, even if you are running the app in the unity editor and to store some data in player, perhaps you have to specify a string key, and then you put your value into player breaths. So if we are saving this quantity for a basic guard than we say, number off plus card asset name. So this way we will ensure that all the keys in player perhaps their unique and different. Because all the names off our cards, they're also unique and different. Well, say Player Pref set into number off, followed by the name of your card, and you put the default number off basic cards, which is set it three right now and else. So if it is not a basic card and it is a card that you can actually obtain from opening a pack, maybe a legendary, maybe a rare card or some other rarity. Then we say player, perhaps set into we use the same way off getting this string kiwi say number off, plus the name off our card s it, and we put the value from our dictionary into the player preps so we say quantity off each card as a key. We use our card assets sort of as an index, and it will return an integer and will save it into player preps. And similar to this. We use a very similar technique when we are loading the quantity of guards from player breaths, which happens here in the end off our awake method. We are also iterating over old cards array because we have already obtained all the card assets and they're already in this race. So we it Torri through all the card assets. If this card has a basic rarity, then we are not bothering searching for something in the player preps. So actually, I could have just excluded these lines that fill in the default number of basic cards into player breath. So if the card is basic, will definitely load the default number off basic guards as a quantity else. If our player perhaps has a key that says number off plus see a name so it has a key that corresponds to this card, then we'll say quantity of each card will add See a so this card asset and will use this same key to get an integer value that it's stored in player. Perhaps so will say player Braff's dot get into number off, plus see a name and else. So if there is no key that we confined in player preps. So Blair perhaps, has key number off. See, a name equals two false, then we'll just set the quantity off this card to be equal to zero. So this is everything that we do in our card collection class. And even though it is not that long, it is a major, major class, and it helps us with a lot of stuff in our project. So essentially, if you think about this, we already have a way off getting any subset off our cards, which is very useful for browsing in your collection. And also we already have a way to save the quantity off guards that your player has into the player breaths and we can save it and loaded. So it is really very versatile, and it already sold a couple of major issues that we want to solve in this project. So now that we've done a lot of theory, you know everything about guard assets, you know about the ways that they're managed in our card collection. I think that in the next lecture will finally do something more practical. I would like to thank you a lot for watching the scores and I'll see you in the next lecture.
7. 206 – Making a Menu and Establishing the Scene Layout: Hello, everyone. And thanks a lot for watching this course about making menus for your trading card game. So in this lecture, I wanted to start doing some practical stuff and assembling some of the things that we need for our menu seen. So instead off using my scene just to show you how some of the stuff is made. Let's make a new scene. For example, I'll go to SS folder. I'll go to file Select New Seen Here, and I can go to file again and select Save Seen As and we'll call this one menu Seen course , right, So the scene is just empty, and it has nothing but the main camera. And our goal for this lecture is to work a bit with unity. You I and two greed the main menu. So the menu that says shop play, browse the collection and open packs some other options that will have their first thing that we can actually do is we can go to sprites and find our background. Sprite and I can select our seen view, and I could just drop our stride strikes into the scene view. So that's the first thing now, if we switch back to game mode, we can see that our scene has this nice background. I think l position this at 00 Okay, Looks nice. So the next thing that who do the main menu is actually drawn on a canvas. So let me just create that. I'll go into hierarchy, create you, I and here I know that you are not able to see this menu. Actually, let me just grab the corner off our unity window so that I can show this to you. So I'm going to create I'm going to you. I and I am creating a canvas. So after I do that, we have two new objects created. One of them is a canvas. The other one is event system that will manage clicking on the buttons on the canvas and a lot more stuff. Actually. So first thing, let's discuss what is a canvas. So the cannabis is meant to hold different You. I elements and in unity, we have several of them. There are images there, stacks and images in tax. They are arranged into different combinations and they also form buttons, sliders and scroll lists and so on. And so forth. But at the core of this that we have just two main. You are elements, images and texts. So first thing, let's right quick and I'll go and create a u I. I will not show you each time how the many looks and what exactly do we create? I'll just mentioned this verbally. So right now I'm creating a panel, and a panel is something that will span across the whole area off its parent. So currently, this panel, it just stretches across the whole canvas. And there are several things that we want to change on this panel. So the first thing is, the source image by default is set to background, and we want to change that into none. So I just want this panel to give a certain shade off a darker color to our scene. So I'll set it to none. And it also gets read off the rounded corners. So if oppressed controls that, then you can see that here we had a slight rounded corners. And again, if I switch it back to none, then we just have solid color on the panel. Second thing, I'd like to switch this color to darker black collar and the Alfa Weaken just come up with some value that we like that will darken, are seen a little bit. So then you can see that even though this you element is called the panel, the panel is just an image. So the only script component that this game object has is still an image. And next we'll go and create our you I for the background of the menu. And I don't like doing all the work from scratch, so I'll go and grab some prefab. That sort of has some resemblance with the why that we want to create. So I'll go to pre fabs and let's just check out what we have here. I think that this thing that is called message Manager let's instead she ate that into our seen. It is a bit like the thing that we want to create for this menu, so I'll expand this. I will go into the canvas and we don't want to bring this canvas into our campus and make it a child of the panel Soil just created duplicate off this background thing, and I can do that by either right clicking and selecting duplicate here from the menu Oregon Press Control De or Command D on a Mac. That'll create just a copy off this object, and I'll bring it here and make it a child off our panel. And then, of course, I will remove the message manager because we don't want to change that, and we don't want to mess with it. So now we have this background that is a child off our panel. It might seem like it has disappeared, and it is not visible in our scene, and there is a quick way to return it back to its original position so I can select its so called anchoring percent, which controls the positioning off little triangular things that are cold anchors. So if I go back to the scene, interestingly enough, it turns out that our background object is right in the center off our screen right now. So if I go and select custom, l pressed old control shift and also like this percent, which will fit this image to occupy the whole panel. So no, if a double click and go here, there's probably another reason that makes this image so small, which is its scale. So for our message manager, we used a different scale. So now if I set the scale back to one, then this battle should finally occupy the whole area off our screen. And now what we want to do is I'll go in and I'll give this battle some betting. I can actually do it manually here. So let me give 100 pixels of betting on each side. Then I can go in and manually reorganize some of the things so that I like how it's placed . And then I'll apply these things that are called anchors into the corners off our many just like this. Instead of calling it background one, I can rename it into the menu background. If we expand the menu background, it has several elements. 1st 1 is called card bag decoration, which is the skull image. The 2nd 1 is the frame that is so called nine sliced Sprite and let me show you what that is. So the frame is made out of this sprite that it's called frame eight gray, and if we select and open despite in the Sprite editor, then you'll be able to see that there are these little green lines on the Sprite, and we can actually drag them and rearrange them in a way so that we create nine pieces of this sprite. There are the corners, four of them. There are four sides in the middle, so in total it gives us nine different elements. And the corners, they're not stretched at all and not distorted. So the corners are reflected as is, and these horizontal elements, these vertical elements, they are only stretched in one directions, and the middle is just stretched unit formally. And for our sprite, the one that we have here, it doesn't matter at all because the middle is completely transparent. So you're not able to see what happens there. I can just close this Sprite editor. I can press revert because we already had old the right settings for it. And now, under menu background, I want to organize our buttons and our games title automatically. So to do that, I can right click and create an empty game object. So all the objects that I want to organize here, they will go under this empty game object. I can give it an anchoring percent really fast all control shift on my keyboard. Stretch it across the whole span off our menu background object, this object alcohol it bottoms parent. And to organize our buttons really fast and really efficiently. I can go and add a new component to our buttons parent, which is called a horizontal layout group. You can just type in something here under at Component, and it'll find all the components that are combating well with your keyword. So let's add the horizontal layout group. Oh, actually, my bet. We should have added the vertical layout group because we want to organize our buttons vertically, so I'll redo that. I'll find vertical layout group here. Let's add that. And now let's just create a single button so I right quick, go to you. I create a button. We can control the placing and spacing off the buttons that will be created as a child off our buttons parent in the settings for our Button spirit Vertical layout group. So, for example, I would like this route to control child size, both in terms of with and height. So currently, this button doesn't look that appealing. It just occupies the whole span off our buttons parent. But when we create more of these buttons, it will all start to make sense. So, for example, let's change the name of this button into play button. Let us change the text that is reflected on this bottom into play. I will change the font on this bottom into our Devean slash the fund that we use for everything in this game. Actually mistyped play here, so I'll type that again. I don't want to enable best fit yet, so I'll later come up with value off phone size that will be appropriate for all the buttons that will have. So I will not touch that for now. And I want to apply another image to our button. Currently, it said to you, I Sprite and I had difference brides for our buttons. There is a set of these buttons. Sprites there are barely noticeable here and there. Gold buttons, zero buttons, one button stoop. So these sprites, they reflect the state off our buttons when they are oppressed, hovered over and so on and so forth. So let's just select button zero as the defaults bright for our button and a look like this , and it doesn't look very good because it is stretched. So we want to nail down everything for this one button and then we'll change it for all the other buttons. The text. I can change its color because it's barely noticeable on our background. So let's make the text white. And currently the transition is set to color tint. We want to change that to spread swept so that rules specify the sprite that is used for our bottom when it's highlighted, pressed, disabled and so on. So for now, let's select the highlight. It's right. I think it should be this brighter one. Let us select the breaths bright. I think that it's going to be either this button three or this other one buttons one. So currently I'm just guessing and you can rearrange these sprites that you want to show when the button is pressed, highlighted another thing that I want to disable. Since our game is mostly operated with a mouths and we don't want players to operated with their keyboard or game bad, we can turn off the navigation and navigation is something that you're mostly encounter in games for platforms like PlayStation or Xbox or some computer platform Er's where you want to be able to press the arrows to navigate your menu. In our case, we don't want that. So let's select navigation and said it's none. And even though it doesn't look good at all, let's launch the game and check out how our button behaves. So when we launched the game, it is all stretched and not pretty at all. But now when I hover over the button, the sprite changes. It is brighter, and if I press on the button, then it becomes darker, which makes sense. And if I go and disable or de activate the button, which weaken Dubai on shaking this interactive option, if I on paused the game than the bottom would just go dark and grey like this. So I think we have nailed down all the sprites that we wanted to use for the button, and I will exit blame old for now, we want to create several buttons like these. So now watch what happens when I start creating copies of these buttons. Old press control de with my play button, selected once, twice, three times, and I think that that is its We need just four buttons like this. The second button will be cold collection buttons. So right now, I just don't want this to take too long. So I will rename all the buttons myself and then I'll get back to you. So I have typed in the names off our buttons. They will be play collection, shop and quit. And now I'd like to change the tax on all these buttons. So I have the text selected and I'd like to change the font size so that it's a bit larger like this. And then after this change, actually might go and revise this so I'll make them a bit smaller than that. I'll go to our buttons parent. And if we go back to the scene, remember that this thing about Insp Arent it stretches across the whole span off our menu background so I can make it a bit smaller so that we can fit the title on top, and I'll also give it some spacing here, and we can readjust the anchors so that it doesn't stretch awkwardly. And now I can at the text another text on top off our buttons parent so I can go and as a child off our menu background creating you, you, I text. And for this one, I also want to select our Devyn slash font. I'll keep it aligned in the center both horizontally and vertically. I'll change its color to whites. Or maybe we'll pick something darker later end type the game title here, and you can type anything you want here. Or actually, this menu is just a place holder. So later you replace it with some of the stuff that you want to feature in your game and something that you want to your game to be cold and memorized by this unique name. So ours will say just game title and l said the anchors to the corners off this game title text rectangle Just like that. And for this one, I actually think that I will use best fit. So this text game tile it'll be a bit larger, even more than 40 actually, something like that, and I think I have a component in this project that I've found on the Internet that it's gold circular outlines. So let's go and try to find that So l search for circle outline and it is a script that is a bit better than unity is built in outline and we can increase the circle count, increase the effect distance so that L client is more pronounced and more visible and in white direction. I think something like this will do so. We already have sort of a template for our main menu. And the last thing that I wanted to discuss in this lecture in our game. We also had a lot of the objects that were outside off our canvas. So right now I can just collapse everything that beers under this canvas, go and create another empty game object all the different screens that we're going to use and that we're going to show our players in this project. They will have very common where a similar structure. So, for example, this will this game object will be called a screen, and the child game object will be called screen content or something like that. So I'll say screen content here and the screen out rather set it to 00 so that it appears in the center off our scene right here. So all those different screens that you have seen in our intro lecture like the back opening screen and the collection browsing screen. They will not actually be apart off our canvas, but they will be arranged here in the scene on top off our background. So if we use other canvases and other buttons for that, they will be so called world space canvases. While this canvas that we use here it is set to render mode screen space overlay. So it's just laid over the screen that we're showing to our players and world space can be used. For example, if you want to show some tax, do your players in the game like written on the wall or something similar to that? And in this scene, we'll have several screens like this. For example, one of them will be called the Shop screen. This will be the 1st 1 that we're going to make, and I can duplicate this screen. The 2nd 1 will be called Deck Building Screen. We'll have another screen that will be called ready made deck selection streams. So again, just call it shorter deck selection screen and we'll have another one that will be cold character selection screen. So when you want to build a deck you have to select for what character class are you building it So we'll have that as well and selection. I've misspelled that and here as well. And I'm using this screen structure. You will see why. So, to each off these screens will attach a script that will be a singleton and the way unity works. And the way C Sharp works the game objects that have singleton scripts. When you're seen loads, they have to be set active in the Inspector. So this check mark on top of the Inspector should be set to true and these things that are called the stream content that will hold everything that is blazed on our speed. We will actually be able to turn it on our off, and there will be methods to show, screen, hide, screen and so on and so forth. You will be very familiar with this concept by the end of this course. So I'd like to thank you very much for hanging on through this section. We have discussed a lot of theoretical stuff that is really important, like getting certain subsets off different guard assets from our collection. We've discussed what the card as it is and how he can include something like that into your unity project. You have seen what script herbal objects are and how you can make assets in your project out of them, and in our next section will have more ambitious goal. We want to assemble a shop screen where your players will be able to buy packs, and they will also be able to open the packs that they have and get some rewards. So thank you for watching the course, and I will see you in the next section.
8. 301 – Introduction to Section 3: Hello, everyone. And thanks a lot for watching the course. This section will be entirely dedicated to opening card packs, and our goal for this section is to bring this shop menu item to life so that by the end of the section it will look like this will be able to press on this shop menu item and we'll get to this screen. The design of this screen is entirely up to you. I just wanted to make it functional and understandable on the stream will be able to buy new packs. So when we press on this by button, some amount will be subtracted from the amount of gold that we have and will get this object that represents a new card pack. With this card pack object will be able to drag it around on our screen. And if we are dragging it here, it should just snap back to its original position so nothing will happen. And this area of the screen represents the pack opening area. If we drag the pack onto the pack opening area, it should snap to its center. So I'm starting to dragged the pack. I leave it here and ah it turns out that it's not on the pack. Opening area was bring it closer to the center. Closer to the center. It'll snap. It'll show this little glow when we hover over the pack. If we click on the pack, it will do this little shake, and it will review these five cards. You can also notice that while we're doing this, the back button is now not interact herbal. So we cannot go back from this screen until we have experienced the food process off back opening. So now I have to reveal the cards one by one and turn them over. And this back has four common cards and one rare card that is shown by this little glow. So let's flip over the rare card and let's sleep over all the other cards. When I flip over all the cards, this Dunbarton lights up and we can press this button to complete one pack opening. So if I pressed on the cards disappear, the back button activates. We can open a couple of more packs like that, okay? And get some other cards and the cards note on Lee. They get shown to your players. They also get added into their collection. Remember, in the previous section, we have seen the class that is called card Collection. So all the cards that your players get from their packs, they get added into a dictionary in that guard collection class. And then they mount off each card that your player has gets saved into player breaths. So let's turn over some more cards. Here. We got an epic card, a rare card and another epic I can press done, and this back button returns us back to the main menu. So in this section will cover all the streets and all the you I elements that make our shop and back opening screen work. I would like to thank you for watching the course, and I will see you in the next lecture.
9. 302 – Making the Money and Dust or Spare Parts HUD: Hello, everyone. And thanks a lot for watching the scores about making menus for your trading card game. In the previous section, it was more like an introductory section. So we've discussed some scripts that will be very important for our game, like the card collection that lets us big, certain self sets or certain collections off cards that satisfy certain criteria. And we have also assembled this main menu, which wasn't very difficult. So in this section, our goal is to add the shop screen so that we can buy packs, open packs and so on and so forth. So the menu currently looks like this. And if we exit play mode and return to the same scene, we have to add a couple more empty game objects and populate them with our scripts. So I'll go to create create an empty game object and this one. I'm going to rename it into the card collection, so I'll type in card collection, and I'll attach the script card collection to this object. So we'll see card collection here like this, and our next step is we want to attach something to our shop screen, so we want to go and add the component that will be cold shop manager and instantly we can establish several connections. So, for example, this screen content the 1st 1 we have to drag our game object that we have under our shop screen that will contain everything. All the graphical stuff that we're going to show on the screen and this structure will be very similar for all the other screens. So for the deck building deck selection is going to be almost the same thing. We also have a public feud here that it's called back prefab. For now. We already have it in our project. We'll take a look at it later. Maybe we'll assemble one manually so that you see how that is done. Then we have our packs. Price weaken Set it to 100 for example, have our packs parent the transform that all the new packs will be parented to our initial pack spot, which is the game object where the packs will appear when they're dropped onto our shop, screen or or shop manager, and you will see how that works in our next lecturers. Also, when we buy packs in our game, the position for our pack will be generated randomly, so we have our position X range. So there is a certain like plus four minus four thing. Currently it's set to four that will be added to our initial packed spot position, I guess, and position why Range is the same thing for our why co ordinates So we can either spawn are pack higher or lower. We also have our rotation range. So when we spawn in you back, it'll not just fall flat onto the surface but also be rotated at a certain angle, which I think is a nice touch. Then we have several references to stuff that we won't have under our shop manager screen, and I think that who creates all these things in our current lecture? So next we have the money taxed, the dust taxed money hard and the dust heart. So these will be two different huts that will be shown at different moments and stages in our game, and they will be created as Children off our canvas game object Opening area is a script that will be a child off another component under our screen content who add it later, and we also have these values, that starting amount of dust and the starting amount off money. So if our Blair launches the game for the first time, these are the amounts of dust and money that our character will get. The money is used for buying packs, and the dust is used for crafting, and you get thus from dis enchanting cards. Now I think let's go back into our scene. I'll double click on the canvas so that we can see the entire canvas here and let us add our hearts, the money hot and the dust hard. So I'll go into our canvas and create an empty game object that will serve as a parent for both off our huts. I think they'll be pretty similar, and they will be located somewhere over here in the lower right corner. Then we can attach these anchors here to the corner off our screen, and here they will be placed like this. You can change the anchoring percent, but this one will just ensure that our new hot parent, it will remain in the same spot when we play the game. So calculus. One H U D parent and as a child off our heart. Parent. Let us create one of the hoods and the 2nd 1 will be just made by analogy. So I'll right click go to you. Why? And create an image. We want to make sure that this image spends across the whole span off our hard like this. I pressed old control shift on my keyboard and selected this angry percent. So when I press old control shift, you can see that you are able to notice some of the changes here in the anchoring percents that you are applying through your image. So when you breast old control shift, it stretches the image and applies the anchors through the corners of the image. Let's rename the image to money. H you d like this. And then I think that will select a sprite for this right away. So I want to select one of the sprites that we use for our buttons. For example, this bottoms one. I think it looks pretty good. And then we want to add another image component. I'll go to you. I create another image. This one I think I'll go in and place manually. So this image it should be placed here and I want to make it. It's smaller and I'll apply the anchors to the coroner's like it did before. I might want to readjust the anchoring percent later, and for this image I'd like it to be the ICANN that we show on the hut. So alcohol, this one I can. And for the ICANN, for our money hard. I'll select one of the Aikens with coins that I have in the project. Maybe this one with a single coin or if we have something else. I don't think that we have something else now, So let's just like this one with a coin. There we go. And for this image, I also want to enable reserve aspect so that when we have different aspect ratios and different screen resolutions, it doesn't get distorted. I will also resize this. I don't like that. It's so huge this I can and then anchors. I'll be apply them to the corners of this image. So that's the ICANN. And now we should have the text. So as a child off our money hot, I'll also go to you. I and I'll create a text component and this one it will be placed similarly to our Aiken. I'll give it a little spacing relative to our I can handle. Stretch it to go all the way to the end off our Hud. Then I'll reapply the anchors to the corners off this text like this, and then for the text. Of course, you want to change its color to white. Then we want to apply our custom fund, which is this deviance wesh. Then I want to make the phone size larger. I think something like this will do, and we'll make it so that in a horizontal direction will still leave this alignment to the left side, off our text and vertically, I'll make the tax appear in the center off our hut. So let's type in some number like 1000 here. Or maybe it's a good idea to change the alignment to something like this and make the text a bit smaller so that it doesn't stick to our coin that much So that is basically one off these huts. We can create another one by just creating a copy off this one that we have just created soil press control De instead of calling this one money hard. I'll call this one dust hard and I'll change the ICANN. So instead of using the coin, I had a little Aiken that shows like something relative to crafting. I think it's over here the I can with the tools. And now that we have both of these huts, we can go into our shop screen because it uses them and we have to establish the connection with all the elements on our hearts that are required. So first we want to drag the money tax onto here, and we'll drag the dust text onto here and these game object references. They're just references to these parent objects off our huts. So this one is the money hot here, and this one is the dust hot over here by default in the scene, we can set them to on active so we can de activate both of them, and they will be activated when we need to show them through our shop screen. So in our next lecture will continue studying and constructing our shop screen, and I think we'll take our first look at the script. Shop manager will discuss what it does, and how does it handle the amounts of money and dust that our character has and will approach the actual part with packs, maybe make a prefab off a pack. And then we also have to examine what is this other script that it's called the opening area? That will do a lot of work for us when we are dragging the pack and it actually shows us The card opening spawns five new cards for us, and they are added into our collection, So I'd like to thank you very much for watching the course and I will see you in the next lecture.
10. 303 – The ShopManager Script: Hello, everyone. In our previous lecture, we have made these two new objects. One of them is gold money, HUD. The other one is called the Dust Hut to reflect the amounts off money and dust that our player has and these objects there over the hidden. So in this lecture, I wanted to discuss the script shop manager. This is one of the scripts that will help us manage the back opening and the process off buying packs. So there are all these different public fields we have filled in. Some of them, some of them are still blank, and we'll discuss what they do in our next lectures. So will jump two Monta develop and let's take a look at this glass. So among all the public feuds that this class has, we also have a public static shop manager. Instance In awake, we say instance equals this. So this is a so called lazy Singleton and will use this script to access everything that we want to know about the shop, current amount of packs, and so on and so forth because I've ran into a couple of problems. I tried to make the scripts that are child objects off our screens. Singleton's as well. And when I did this, since our screens and all the content off this shop screen when we just launched the game, we see only the main menu and the screens are deactivated. So the awake is not getting cold, and the script doesn't get initialized properly. So we have concentrated all the information that we have to access at old times in this shop manager and the shop manager, we're making sure that the game object that has this script it'll be activated at old times . So we're going to enable and disable just this game object that is called screen content. So in awake, we say instance equals to this. We hide the screen, so when the awake is cold, it means that we have just launched the game and right away we don't want to show this screen, so we are hiding it. It is a special method that we use here, and another thing that we're doing. We are loading the amount off backs that our player might have from player breath. So we're checking. If Blair Crafts has key unopened backs and later on you'll see that we'll write something into player breaths with this key in this script as well. So if we have some unopened packs, we are starting a quarantine and a core team because we also want to visualize the process off getting packs. That's why we're using, according here, that it's called Give Backs the amount of backs that we use here. Player breaths get end on open backs. So we're getting it from the player breaths and this true sense, for instance. So in this case, we cannot even see the screen. So we might just give these backs to our players instantly and not show the animations. Then there is this next method that says load, dust and money actually says to, But it should say from player preps. But just for the sake off being consistent, I'm not changing anything here so actually means low dust and money from player preps. So this class, it will also manage the amount of dust and the amount of money that our player has. As you can see here we have these two properties that are very similar, so when our player gets or when he spends money, it will all go through this property that is called money. And when we set something to money, we are also making sure that we are updating the tax in our money hut. So we say money tax dot taxed equals money to string and the same thing we're doing with this dust text. Then we have this method that is called BIPAC, which is really simple. We're just checking if we have enough money. So if money is greater than or equal to pack price So if we have enough funds to buy the back, then we are subtracting the back price from our property money that is right here. And when this is happening, the property also updates the text like a set. So all the information will be just actual and you will see the updated amount of money that you have just from calling this one line. Money minus equals back price. And then we're starting this. Gordon, give packs. We're giving just one pack to our player and actually right after this method BIPAC, we have this quarantine and you can also see that here this second argument Boolean instant . It is in so called optional argument. I have it set to false by default. So if we are calling this method without a second argument like we do here, it means that instant who be set to false, which means that when we give our player back will show a certain animation of this back peering and going from one place to another. So let's take a look at what happens in our quarantine. I e numerator give packs. It looks like a method, but it returns this weird type ia numerator, and we have to call this method by saying start 14 give backs. In this case we're using according to interrupt the execution off our code and wait for a certain period of time like we do in this line, you would return. You wait for seconds and we cannot do this with an ordinary method. So that's why we need this Corentin Syntex and Corzine functionality and right in the beginning, off our recording, we have a four Luke. So we're going to repeat everything that is going on in this four loop until we give our player all the packs that are specified. Here are a number off backs, so we're saying and I from zero to or a number of packs I plus plus. Then we're going to inst Enshi eight. New game object and this game object will be stored in a prefab that it will be called pack prefab. It is also a public field off this class. You will talk about the back prefab in our next lectures. So far, we're just insane. She ating this prefab that we haven't made yet. We are in censure, hating it as a child off backs parent object. So this backs parent object is just to transform. That will be apparent off all the packs that we make And then we're doing this to spice it up a little. And to make this back buring process more interesting, we are random izing the starting position off our back. First we say vector three loco position foreign. You pack for the first coordinate, we say random dot range and we have these variables in this class. That's a position X range and position. Why range so in X coordinate, we're picking a random number from minus position X range two plus position X range, so we can shifted position X range to the right or position X range to the left and the same thing we're doing with our Y coordinates so we can shifted position. Why range to the top or position? Why range to the bottom off our screen? And in that coordinates, I just didn't want these backs to stick onto one another, and they all have a three d collider. So to make sure that we're able to pick one of the packs accurately, I'm also giving them a certain displacement in set Gordon AIDS. So we're multiplying backs created by back placement offset. And we're going to place the most recent back that we have made on top off all the other packs when we created back. We also say packs created, plus plus and packs created is just a property. I think we have already seen it here, and this property is here just to track the amount off unopened packs that we have when we exit the game. It will also be used to write something into our player preps to make sure that our players will not lose any packs that they have earned in the game. Next, we're doing the same thing with its canvas so to make the last back that we create appear on top off other backs. Sorting wise, we're seeing you back dot get component in Children. We're getting the canvas so our pack will actually be made from you. I like our cards like our card backs. And we're setting the sorting order off the canvas to backs created as well. And then we have this if statement, we're checking if instant. So if you want to reward this back to our player instantly, for example, this happens in awake when we want to load the amount off packs from player preps. So if we are doing this, we don't actually care about showing the animation or this back traveling from one spot to another. We just want to make it so that when players enter the shop, they already see that they have some off the packs that they earned previously. So we just say you back transform local position equals to this local position for a new pack that we have generated and otherwise were first setting you back. Transform position to initial packed position dot position. So we're setting the position off this back to some different spot and then from there we're locally moving this back to our local position from you back that we have generated here in 0.5 seconds and to wait for this event to fully play and not create all the packs at once we are returning this were saying you'd return. You wait for seconds. So we want to make sure that this animation do Local move is fully played. By the way, if you are in you to this, we can say transform dot do local move on Lee because we're using do between in this project and between is so called Tween ing engine. It is spelled like this do between without 1/3 e. So like this between. And if you have no previous experience with twinning engines and tweeting in general, I encourage you to try out between because it is. First, it's free. It is very simple to use, and it really simplifies a lot off things that you can do in your project. For example, if we used unity built in stuff, we should have used our update function and in update we would learn up our pack to position or smooth Europe or smooth, damp or something else. So it would be a pain to just make our pack move from point A to B and with between it makes these little teeny tiny animations a lot simpler. And it is all achieved just with one line of code. We have used between a lot for making the card game battle functionality. So all the car drove and the guard has to travel from the deck into your hand. It is old done with do between, and it is very convenient. So if you're new to Tween ing and do between, check it out, it is really simple and it is used a lot throughout this project. And so for each back, even if we want to give our player six or 10 packs, it'll just go through this process off, creating in you pack, picking a correct position for the Pac, making sure that it is incorrect spot in terms off sorting and then twinning or moving this back to our selected local position for new back in 0.5 seconds. So all these packs will appear gradually one by one, and I think that in our project, we're not actually using this, so we're constantly giving just one pack to our player. But if you'd like, you can make it worked in your project so that when he presses by, he gets two or three packs and so on and so forth. Then we have this next method on application quit and this method we can use it because this shop manager is a model behavior so we can use awake on application, quit and so on and so forth and on application quit. It's gold. Well, quite obviously, when you quit the game. When we quit the game, we call the method save dust and money into player breaths that does this. It just writes T mounts off dust and money into player preps with these keys, dust and money. So we have done that and also on application quit. We're checking the amount of packs that we have in our packs created property, and we are writing it into our player preps by the key unopened packs so that when we launched the game next time we can maintain the amount off unopened packs that our player has in the shop. This method that we used in awake load, dust and money. Actually, it should say from Let's leave it it to, for now low dust and money to player preps. We're checking if player perhaps Haski dust. So if we have saved something into player breath, so if we don't have a key, it is most likely that we're launching this up for the first time. So if we have the key that says Dust, then we should get the integer value off the amount of dust that we have, and we assign it to our dust property and else if we don't have the key in our player breaths like a sad, it means that we're launching the game for the first time. Then we want to give our player the starting amount off dust. So if you want to let your players craft some cards right away and you want to give them some starting amount than this is the perfect place where you can do this and we're doing the same thing for money attempting to load the amount of money from player preps. If we don't have anything written into player preps, we are initializing or money with this starting amount and finally, the methods for showing the screen and hiding the shop screen. We say stream content. And if we're showing the screen, we said it active and say True here. If we are hiding the screen, we are deactivating the screen surreal, calling the method set active and we are passing false as an argument here. And also, if we are showing the screen, we want to show our money hot to make sure that our players have some visual feedback about how many money can they spend? How many more packs can they buy? So money? Hot said Active. We're showing the screen, sir, we're passing true into the method, and if we are hiding the screen, then we're passing false into the method. So I think that this is going to be it for our current lecture. Now you know how our shop manager class works. It is quite simple and straightforward. The methods are not that long, and this glass, it takes care off several things. It takes care off, showing and hiding our screen and storing some values that might be accessed by other aspect off our game as well. Like the amounts off dust and money. It manages the amount off unopened packs that we already have and also weaken buybacks through this glass. In the next lecture, I think we'll talk more about the pack. Opening process will look at the stripped back opening area that is located right here in our shop folder as well, and will also construct a prefab off our pack, which we haven't done yet. So I'd like to thank you very much for watching and I will see you in the next lectures of the course.
11. 304 – Making a Layout of the Pack Opening Screen: Hello, everyone, and welcome back to the course. So in the previous lecture, you have seen this script that is attached to our shop screen that is called the shop Manager. And in this lecture, I think we'll add some visual stuff, too. Our screen contents there will actually start populating and adding something to our shop screen in the course in this project. It was fairly simple, so I checked back with my previous scene, the one that's already made and fully functional and one of the objects that we had here. It's called Unopened Back Area. It is just an ordinary empty game object. So let's just create one. Rename it to unopened back area just like this, actually, to make sure that we're doing it correctly and that we are editing everything. Let's double click on the unopened back area so that we see where it is. And as a child off our unopened back area, we want to have some graphical something visual, some graphical representation off this area. So let's go to our Sprites folder and let's locate this by free pick image. I think I'll grab this stole one, and I'll make it a child off our unopened pack area. I'll control the scale. I think this will do and in why Direction as well, Then I'll check back with my game view. So in the game it will look like this, which is better. And then out also shifted to this side, make it a bit smaller and shifted to the side by controlling its exposition. So let's try and bring it here. Maybe make it a bit more narrow like this. So that's our background for the PAC opening area. I think it doesn't look too bad, so it'll just sit here. If we don't want this main menu to distract us while we're working on our shop screen weaken. Just deactivate our canvas so I can just deactivate this canvas object in the scene and Roaches get to work on our pack opening scream. Then in the scene, I'll also create another child object off our unopened pack area. All right, click create an empty game object and this game object will be called initial packed position. So we had a reference like this in our shop manager script initial back position, and now we can establish several more references in our shop manager. So this unopened back area, it will serve as a packs parent. This transform, and this initial back position will serve as this trends from initial pack spot. So the idea is that the PAC appears here and then we dragged the unopened packs from here into this part of the screen. And here we experience the back opening the purpose off our initial packed position is we want to drop the pack sort of from above. And to achieve this I think I have said this that position to something like minus five. Here we can check it later. So with the perspective camera, it will result in an illusion that the back is dropped from the top and also a bit from the side right onto this area, which is what we are going for. And next we'll create another empty object. I will right click here in our screen, content creates empty, and this game object will be called the opening area later will re adjust the position of this object. I don't think that it will have some visual representation, or you can add some visual stuff to this opening area as well I know for sure that it will have a collider and it will be a box collider. So I'm trying to go here and search for a component. Let's type inbox Collider. So this is not a duty collider. This is actually a three d collider. We are adding a box collider to this object. And I also want to resize this collider so we can make it manually by going to edit collider here. Or I could just resize it by altering its size. So I'll make it more wide like this, and I also make it Toller. I'm sorry. This is the wrong control. I will also make it toller like this and will change the position off our opening area. So drag it over here. I guess that's right. And this opening area will have another script attached to that is important for our pack opening experience. I'll go to add component Anil, search for pack opening area and attach it to this object and the back opening area Script has several interesting controls. For instance, you have these controls their gold colors, where you get to select the legendary epic, rare and common color, and these are the colors of the glow that you will show around the card. So, you know, like in, for example, like a harsh tone. So, yes, this is actually inspired by harsh Stone. You are hovering over a card, and you instantly see that this is a legendary or in epic or just a common card by its glow , so you can go in and pick a color for each off these categories. I think that l pick all of these colors myself, but for each of these colors, you don't have to forget to bring the Alfa all the way up. Otherwise, these objects that you will show the glows, they'll just be transparent. So bring the Alfa all the way up to 255 to make sure that you're glows are not transparent . So I have selected these colors for globes. We also have another interesting option that's has give at least one rare card. So the cards that you get from PACs, they're always randomly generated, and if you want to encourage your players and give them at least one card that is rare or off higher, rarity. But then you can enable this check mark and say, Give at least one rare card. You also get to control the probabilities off getting each card, so the legendary probability it should be the lowest. But just for the sake of testing, we want to get legendary is more often so. The ratio off getting legendary rare or epic card should be something like this. So legendary is the lowest rates epic, a bit higher and rare, the highest rate percentage probability off getting a rare card. We also have these references spelled guard from back prefab and will make that later. Or we'll use a pre made brief up, but we'll discuss how that is made with our packs. We have only one prefab because our pack is just something that looks like a card back, and it doesn't have any variations. But once you start opening the packs, you can get either a spell card or a creature card, at least in our project. So we should have pre fabs for all of them, and we should check whether we generated a spell or a creature and then based on that. But instead she ate either a spell card or a creature card We also have references to these two buttons. One of them is called the Done button, so the done button it is the bottom that who appear Once you have dragged the pack from here onto your pack opening area, you click on the back. You get five cards spawned around the back. You open each of these guards, and only then the done button appears, and only after you press the done button you can go back. So this makes sure that you cannot exit this screen and you cannot leave your pack on opened, sort of so to speak. And the back button is something that will see it right here in the corner. And you can press the back button to just go back to the main menu and hide the sharp screen. And the last thing in the script that we haven't covered for. Now it is this array in the end slots for cards, and this ray should actually have five elements because we air spawning five cards from our pack, and these are the places where you want these cards to spawn or to end up if they sort of fly out of the pack. So as a child off our opening area, I'll right click create an empty game object. Let's call this one slot and Al, just read duplicates of this game. Objects oil, press control de control de until I have five of them and then with this, too, I can place them around the back, for example, like this. This one can be placed over here. The 3rd 1 can be placed here, and these two can be placed here in the lower part of the screen. Later. You actually readjust the positions off these objects, but it might actually be pretty accurate. And just for the sake of testing, this might do so I'll go back to my opening area. Actually, there is an easier way off operating this race so I can just change its size back to zero. I can lock the inspector just so that it doesn't get changed for something else. If we select some other objects in the scene, I'll select all these slots and I'll just track them onto the name off our array slots for cards. And once I release you, see that this ray is populated with these objects, which is very convenient, I think, and just to address as many issues as we can in this video. Let's also create several buttons. So as a child off our screen, content to have a bottom who also need a canvas. So I am creating in you canvas, unlocking the inspector here I am changing it to world space. I am changing its position 200 just for our convenience. And I'm changing its scale to something much smaller like 0.1 actually, one, It's too small. So let's go with 05 maybe here and 05 here as well. Then we can change the width and the high to control its size. So I think something appropriate for a button will be this. And then, as a child of this canvas, I can rightly go to you I and create a button. I know that you are not able to see this menu, but when I go to you, I I'm selecting your bottom here. So this button, it's currently too small and we wanted to occupy the whole span off our canvas like this. We will also change the taxed. So let's say we are making a done button right now, so we'll make this tax say, Don, change our phone to defense wash and we can control the text size on this bottom manually. Then we can also changed the sprite on this bottom. So this is a pretty standard procedure that Ugo over with each off our buttons and later you can also add a frame. Actually, let's go and add a frame right now, so I'll add another image on top of the button. I'll make it span across the whole bottom, and then I'll go and select one of the frames that we have here, for example, this one. Or let's use this one because it's nine sliced. So I have selected this nine sliced frame and this will be the bottom that will be spawned . Actually, maybe it will be spawned here in the center, and I don't have to forget that it's a child of the canvas. The canvas is world space, so we have to move this bottom together with the canvas. Let's rename this bottom to our done button like this, and we also want to create another bottle like this so I'll just copy this canvas Bush Control de here and this button movie located here in the corner instead of done it should say back. So I will change its name to back Button A here, and I will change the text on this button to say back like this, and I'll adjust the position off this bottom just a little bit like this. For now, we should have on Lee the back about invisible, so I'll disable our done button and we can establish some connections this time in our opening areas, so it should have a reference to our done bottom, which is this one. It should also have a reference to our back button, which is this one. So the only two references that we have left out for now is the spell card from Pack and the Creature Card from Pack. And in our shop screen. The only reference that we've left out is our pack prefab and also the opening area that we have just made. So I'll just drag opening area, and this way the back will be the only reference that we have left out for now. So in the next lecture will talk about all these objects the back prefab, the guard pre fabs. The cards that we get from our packs and hopefully in one or two lectures will get to experiment and open some packs. Thanks a lot for watching, and I will see you in the next lecture.
12. 305 – Pack Opening Screen Adjustments and Overview of Dragging: Hello, everyone. And welcome back to the course Now, before we discuss the card backs the card back prefab. I wanted to make a couple of quick adjustments to the scene. So we have made several buttons. The done button that is currently invisible. The back button. We want to create one more, and I forgot about this. One more button will serve for us as a BIPAC button. So when we pressed this button, our player will buy one pack. I'll expand the shop screen again. Find the canvas off, one off our buttons. Let's have this one. The one that says back I will created duplicate of this canvas and now I can drag it over here. I think it will be located here and I will resize this button and I will change the text to see by like this And another fix that I wanted to apply is to this area. I got one thing not 100% accurate. So currently, if we select this other to that marks the position off our game objects in space. Our on open peck area is located here, and I wanted this game object. The parent for packs to be located here in the center off our panel sort of that serves as a background for our new packs. So in order to do that, I will adjust the position of this by free pick Sprite. I will put it at zero in X X is and this initial back position. I think it is already located correctly. So it's where our unopened pack area is now. I'm going to grab this on opened pack area and bring it here. And I also think that will bring this area bit higher and will make the background for our packs a bit smaller in it's why scaled. So l control the Y scale. So now we fixed a couple of things on our shop screen and I wanted to go and show you What is this back prefab that will create on the shop screen? So this field in our shop manager is currently empty. Let us go to assets pre fabs menu pre fabs. So everything that will insane she ate and create in this course is located in our menu. Brief. EPPS and all these other pre fabs there the prefects that are used in the battle scene. Sometimes they're very helpful for creating the menu prefects because the cards, they will look the same in the menu. But the scripts on the cards, they will be different. So the cards in the game, the cards in the menu and even those cards that we show in the PAC opening their old, different game objects. So they all have different script. The old have to accomplish different tasks. So inside the folder menu pre fabs Let's go and find the pack prefab and bring it into our scene so that we can studied and figure out how it's made right away. I think that there is something wrong with the scale off all the objects in my scene, because in the scene that was used in the starting project, the packs they appeared much smaller. So what Me check back with my previous menu scene and fix the scale in this scene, and this will probably involve fixing the main cameras perspective angle. So I checked back with my menu scene, and one of the things that wasn't working for us is that we created this scene from scratch and the camera was set by default to Ortho graphic, and in this case, we want to still keep it the perspective camera. It will not play a huge role in the scene. So I'm changing this to perspective, and the feud of you will be set to 65 the same as in my previous scene. And also, I'm not exactly sure how this camera was positioned, so I'll check back with my previous scene, the one that's cold, many seen. Let's save the changes. Check out the camera and the camera in that scene was positioned in minus 14 ends that coordinate. So I'm returning back to the menu, seen course, selecting my main camera and speaking minus 14 as a displacement in set. Gordon. So now we have this back prefab that I have pre made in correct scale, which is appropriate for our seen. Everything else is, ah, change, but it is very easy to fix, and it is great that we have noticed it on such an early stage. So I'll change the scale of the background to Dubai to this way, it'll again occupy the whole span off are seen and will also have to inspect our sharp screen again. So on the sharp screen. I'll double click on the screen content. It is all displaced and in the wrong position. Right now, I think that will have to said this marble texture to appear behind everything. So I'll give it an order in layer off, minus 20. Return back to this scene. Now we can see our buttons, this little panel where our packs will appear and we can readjust everything again. So I'll go to screen content. Select our on opened back area. We adjust this sprite. It should be larger in X scale and in why scale? Then I'll grab our unopened pack area and change its position. We'll make it appear here and a bit higher, I guess something like this. Then I will grab our button that is responsible for buying packs. I'll also change its position in X coordinate and in why coordinates so that it appears below this pedal. I could go to the scene, select this too, and make it so that this spot in has roughly the same with as our panel for packs and make it a bit higher. And I will also have to reposition our back button. So let's do that the back button will appear here in this corner. Let's return to the game and check if this position is appropriate. And I also think that these slots that we have made in our opening area they can be repositioned as well. And actually the done button. So the done button should appear here in the center, and this loss should be organized around this done button. So this one lets located here this next slot here, these lower ones. I think we can leave them like they are right now, except for this one and the top one. The top slot. Let's make it appear right here and top off our done button, and that's it. So we can finally inspect how our card pack is made, and the card back is a very simple game object. It looks just like the card back in the game, and you can actually make different card packs for your game in our game will have only one that will look like the card back that we use in the battle scene. So in order to achieve this, I can just grab any of the cards from our Prefects folder, the cards that we use in the game or there is this need game object that it's called the card back so I can just use that and parented to an empty game object. And then I have changed the scale of this object to two in X and y directions, so the card back will not need this in the scene. And the next thing that I wanted to discuss is the scripts that are attached to our pack. One of the components is the box collider, and we need this box collider to be able to drag the pack and to be able to detect clicks on the pack. And there are several scripts. One of them is called Drag a Ble. It is used in the game as well, and the other one is called Drag Pack, opening the way I have made dragging in this game, I broke it into two different components. The script that is called Drag a ble. Let me open it and show it to you in mono develop. So now that Mona Develop is open drag, a ble is a very basic script that allows us to drag any object in the game, so we'll drag cards in the battle scene and in the menu seen. The only thing that will drag is the pack. Another component that is required for dragging in this project is a script off type dragging actions, and it is an abstract class, so there might be many other classes of type dragging actions, and it defines the dragging behavior. So what do you want to do when you just start dragging this object? Maybe you want to show some particle effect, or maybe you want to play a sound or do something else. So this method is responsible for that. What do you want to do when you end dragging? Now, this is a very responsible moment. So when you actually release the object that you are dragging, you want some action to happen. For example, maybe you will want one creature to attack another when you are dragging a target in the game, or in our case, when we are dragging our pack, we want it to stick to our pack opening area and to show the back opening so on And drag is also very important method in this relation. On dragging in update now, It will not be used for our pack, I guess. But if you want to continuously do something when you were dragging like, for instance, in our battle scene, our creature attacks used this method. So when we are dragging our creature in update, the creature is actually staying in place. But we are dragging a special Aiken that we call the targets or the targeting system. And in update, we show the line render the line that connects our creature and the target so that we have some visual representation off our attack. And here we also have several helper properties and methods that are mostly used in the battle scene. I don't think that will use them that much for our pack. So now if we are going back to our drinkable script, we have on miles down method, so this method will detect the initial click on the collider. We also have our update method. It's the place where we'll call d a on dragging in update and our own mouse up method. And this is the place where we actually stop dragging the object. We're releasing the object and we are making some final actions and decisions as to what has happened as a result off our dragging, there are also these methods start dragging canceled drag. And the important part is that when you are dragging an object like this, you also have to keep in mind that you have to recalculate your most position, depending on how far is this from the camera. So there is this set displacement that initial distance in that coordinate from the camera and you have to recalculate mouse in world coordinates so that your object maintains a certain position from the camera. Otherwise, you're dragging will not work properly. So I'll leave it up to you to study this struggle script because it was used in our battle scene and there are plenty off different examples.
13. 306 – Custom Scripts for Pack Dragging and Pack Opening: and the script of five dragging actions that we use for our pack is called Drag Back Opening. As you can see here, we don't inherit from on a behavior. Instead, we inherit from dragging actions. This means that we have to implement all those abstract methods. So if there was an abstract method in dragging actions like on Star Trek on and Drag, absolutely without, any implementation will have to implement this method. In our drag pack opening script, we are even redefining. Some of the properties like this can drag, and we can also define some custom fields that will be used on Lee by this script like this . Boolean canceling, Boolean moving or reached opening spot. So these are the things that are only specific to this drag back opening script. Now we can drag our pack if our shop manager instance opening area, which is our openings area script that we haven't seen yet, says allowed to drag a pack. So it is a property that will tell us if we are allowed to drag it back or not, and the situations when we are not allowed to drag a pack is, for example, when we are already opening a pack, so we don't want to be able to drag another pack onto the opening areas. So when you are in the middle off back opening, you don't want to be able to open another pack. Also, if we are not canceling, so canceling is something that might happen if you drag your pack. But you didn't hit the back opening area, so you have not dragged it onto that collider off the pack opening area that we have introduced in the scene. Then what should happen is your pack should just return to its original position, which we are storing in this private sector three variable safety position, and we are also allowed to drag back only if it is not moving or if it hasn't reached the opening spot already. So if you drag a pack, drop it on top off your opening spot area and it gets sort of attracted to the center off the back opening area. Then you are no longer able to drag this back and drag it outside of the opening area, so you only get to push the buttons and experience back opening. Let's go over the methods in this class. So on start drag, we're saving the position off our pack just so that we can return it to its original position. If our dragging did not result in bringing this back on top off our opening area, we also say shop manager instance, opening area allowed to drag back equals false. So if we have drag this back somewhere, it means that we're not allowed to drag any other packs until we open this back that we have started dragging. So that is appropriate. Then we have the method on dragging in update and here we are not doing anything when we're dragging in update so it it is just an empty method on and drag. We're checking if drugs successful. I think that this method is also redefined here. So dragging is successful if we have our cursor over the pack opening area. So if we release the back on top off the pack opening area, we consider the dragging successful. So we check if our dragging is successful. Then we do this. We transform, which is our pack. We move it to our shop manager Instance opening area transformed position. So if the Pac was released on top off the back opening area. We make this little Tween with between that will move it to the center, off our pack opening area on complete. We're getting another script component that is attached to our pack, that it's gold script to open one pack and we say allow to open this back before we were not allowed to open the pack. If you haven't dragged it onto the opening area, it means that you cannot experience the packed opening yet. And when we know for sure that this back has reached the pack opening area, it means that we are allowed to click on the back once, and we'll see all those guards spawned from the pack and else. So if our dragging was not successful, then we call the method on cancel drag and here, in on council drag will say counselling True. And the purpose is to not allow to drag any other packs. Then we say transform do local move. So we move this back back to its original position in the unopened back area, and when this movement is complete, we say canceling equals false. So now that we have canceled this action, we are ready to drag other packs or this back again. And we also say Shop manager instance, opening area allowed to drag a pack truth. So we are allowed to drag it back again. If we have dragged the back successfully onto the pack opening area, then we'll say this shop manager instance. Opening area allowed to drag it back later on on Lee after the back is opened, and we have pressed that done button. So that is how our pact dragging script works in general and what it does. And if we go back to unity, there is another component that is called Script to open one pack that is attached to the pack as well, and we try to access it in our drag back opening script. So let's double click on that and inspect how that looks in Wanna develop so it has several public fields. The 1st 1 is image glow image and the color glow color. So when we are hovering over a pack that is already on top off our pack opening area, we want to show a little glow when we enter it where the cursor just to indicate that we are able to open this back, So that's what we do here. We have a private Boolean allowed to open and this method allowed to open this back that sets allowed to open to troops in this class. It also has access to the box collider that we have attached to this back. And we need this so that we can detect. Rather, our players are hovering over this pact with their cursor or not. So in a way, qui se c u l equals get component box collider In the method allowed to open this back the one that is called from our drag back opening on and drag here you're getting the component and calling the method allowed to open this back, we say allowed to open equals true shop manager Instance opening area allowed to drag it back. We said it to false again. I think this line might not be necessary because we have already said it too falls in our drag back opening. But why not? It'll just said it too falls again. You also say shop manager Instance opening area back bottom. So we are accessing the bottom that can return is back to the main menu and we say Interact , herbal equals false, which will sort of disable this button. And it will not allow us to press this button until we have experience the full pack opening. And we also check if the cursor is over a back, which is this method in this glass, we say glow image dot do collar, which is also a method in between and in order to use between. We also include this using statement using D g twinning, and it will change the color of the glow image to glow caller in half a second in this method cursor over a pack. We do some ray casting because Ray from the camera into our most position, the length of the ray will be 30 f, so it will be far more than our minus 14. Distance off, the cameras will go right through the pack. And this code was actually taken from another method that was managing if our cursor is over the table, so I still have an old name here bullion passed through Table Collider. But it actually means that the rate cast has passed through the collider on our pack So for each ray cast hit in hits just in case if we hit something else as well, we're also checking if h dot collider equals two c o L. So the collider on our pack we have passed through table Collider, meaning that we have passed through the collider on our pack and we returned this value passed through Table Collider and finally these couple of methods on mouse enter. If we are allowed to open the back, we should highlight this back with collar, so we do the same thing. Glow image Do collar glow color 0.5 F in 0.5 seconds. We changed the color off glow image to glow color on mouse exit. We changed the collar back to this interesting value collar dot clear and color dot clear is a 100% transparent color. It is a black color, I think. With the value off Alfa set to zero so hour glow image will just gradually fade away. And in this method all miles down, this is where all the action happens. So if we are allowed to open this back, meaning that this back has got all the way to the center off our pack opening area. It is highlighted with color, so the glow image shows a certain glow around the pack. If we are pressing on this back with our mouse, then we say allowed to open equals false so that we are not allowed to open this back again . So some people might double click on the pack and get to pack openings at the same time. So we don't want that we were setting allowed to open false. So we are only allowed to open this back once, then in between. You can also boot Tweens in a so called sequence. So you say sequence s equals between dot sequence and then you can add Tweens to the sequence by saying as dot upend. So the first wean that we are adding to the sequence is do local moves at which will just raise this back above our table area or pack opening area. Another between that, we're adding to the sequence. Is this one? Do shake rotation and you can play with all these parameters. So when you are opening a pack, it'll jump up from the surface of the table, so to speak, and it'll also shake to show some graphical effect off back opening. And then here in on complete, we say Shop manager Instance Opening Area Show Pack opening in this position. So where this back currently is will show the pack opening. We also say shop manager instance backs created minus minus. So we're subtracting one pack. We have already opened it. So if the player exits the game, he should no longer get this back in his saved packs. And once all this is done, we're also destroying this game object. So the whole pack object. It just gets destroyed. It has already done everything that it had to. All the rest will be done in this method opening area show pack opening. This is where the cards will be selected and instance she ated So the back has already served its purpose. And now we can just destroyed in this method show back opening. The five cards will appear around the back, and the player will get to turn them over and see what he got into his collection. Thanks for watching story for such a long lecture, but it is kind of important for understanding how packs work how dragging works in the game if you will inspect the battle scene and tried to change something in there as well. So in the next lecture will take a look at two other brief, perhaps the pre fabs off the cards that we get from the pack. And I think that by the end off the next lecture or the lecture after that, we'll actually get to test the pack opening and get some cards into our collection. Thanks a lot for watching, and I will see you in the next lecture.
14. 307 – Prefabs of Creature and Spell Cards from Packs: Hello, everyone. And thanks for watching the scores vote making menus for your trading guard game. In this lecture, I wanted to show you how the cards that we get from packs are made, and luckily we have an example. So but not only we have thes cards pre configured, but also we have the pre fabs off the cards that we use in the game. So let's check out our creature card that we use in the game. It has a different scale, but it doesn't matter that much because we can easily fix the scale. And the most important part for us are the scripts that we use on the cards. So here's our creature card, and here's our spell card, and we also have the folder with the menu brief EPS, and here we have our let me find those spell card from pack. There's one, and we also have our creature card from back. There's the 2nd 1 and they're set to rotation 180 we can easily rotate them. We can see that the script that shows the card backs and car faces is still on the card, and it's still functional, so let's check out how these guards are different from the ones that we have in the game. The obvious thing is that they're set to a different scale so that they match the scale off our pack in the menu scene. That's one, and they also differ by the scripts that they have on the card. So in our game we have some scripts that are similar. So, for example, we have the better card rotation. And this is the script that takes care off, showing card back or card face, depending on how the card is rotated. And we had to make this work around because our cards, they're not three D objects. They use canvases. So we have to figure this out somehow and either show the card back or the card face for this script to work and for other scripts to work. We also have the Books collider on our card, and it's not the Books collider duty. So the card, even though it is like a duty object, we're treating it as if it is a three D objects. We have a box collider on the card that is really thin. It is just 0.1 in Zed size. That's another component that we have on the guards both in the game and in the menus. The next component is called Juan card manager, and we have used it a lot in the course where we discussed the battle mechanics. Essentially, this component takes care off, re skinning your card and showing the correct information. Correct images on the face off your card. So it has references to all the tax, all the graphical elements on the card, and it takes in a card asset. So it takes in like all the information that we can pass for our card, and it adjusts the card accordingly. So we are still going to have this on our creature and spell cards in the menu. Serve as you can see Box Collider, one card manager, Better card irritation. So these are all the common components in the game. We also have several other components, like we have to be able to drag these cards so we have drag a ble dreck spell no target. These are the scripts. There are similar to the dragging scripts that we've seen for the pack, but for the cards that we get from our pact. We don't need to have any of that. So we just click on the pack. The cards appear and were not allowed to drag them. We have to just turn them over, face up and see what we got. So we don't need the dragging scripts and you will not find them on our creature card from back and spell card from pack pre fabs. Another thing that we don't need theirs this component, Where is the card or creature that is used for resolving the sorting order issues in the battle scene and also this component that it's called the hover Preview. So in the battle scene, we want to hover over the card and we want to see so have blown up and shown closer to us so that we can seal the images and read all the texts. And in the many seen for the PAC opening. We don't need these features to be present on our card, so the cards are actually much simpler, even though they have some common components on them with our game cards. And it's a nice example off reusing the code that you have so you don't have to ride any custom scripts. You just use as much stuff as you can from the battle scene, too. Implement your menu cards, and the only component that is new for us is this one turned over a card for impact. It has reference to the glow image on the card. So both for Creature guard from back in firms for spell card from back. We have references to his glow image because we want to show this glue when we are hovering over card. Now let me open Mona, develop and show you this new turn over card from pack script. And now that Mona Develop has opened, we can all see that the Stripped is very simple, very trivial. Here's our public image glow reference. We have a private float initial scale. So when we hover over a card, we still want to sort of play with the scale so that when you hover over, the card gets a bit bigger. So for that purpose, we save the initial scale off our card because the card is scaled union formally so we don't have any just distortion in scale. So the value self zed Why an ex scale are the same as initial scale. We can just save any of the values of the local scale we can say transformed out local scale dot Exe. We also have this variable that it's called the scale factor and it's just preset to 1.1, and it represents the amount that will make our card larger. When we are hovering over the card, we'll make this effect. When we are hovering over the guard with dude mean, we'll see that in a couple of seconds. We also have this variable that is go private Boolean turned over so we don't want to turn over the cards twice or return the back. So we have to keep this memorized somewhere when we turn over a card from pack. If weakly conducts again, we don't want it to make any other actions. So it has already been turned over and we also have a reference to our one card manager that be cold manager. And I guess we're using it on Lee for figuring out the cards. Rarity. So, through our one card manager, we have access to the card asset that this card has in this card represents, and the card assets stores the information about rarity. So that's what we're using this four. Let's run through all the methods in awake. We are saving the initial scale of this card. Then we're getting our one card manager. And then let's look at these methods first on most enter and own most exit. So when we are entering this card with our cursor, we are first saying Transform dot do scale. So we're using between and this function do scale. It will change the scale off our card uniformly so X wines that scales will be equal to this initial scale multiplied by scale factor. And it will do this in 0.5 seconds and next. In this method, we will also change the color of that glow or just show the glow. So we are saying glow do collar, and to find the color that we need, we have to go a long ways that we go through our shop manager. Instance because our shop manager is a singleton. We go to our opening pack area script that will look at in our next lecturer. Guess we say glo colors by rarity, and this is the array, where we store all the Glo colors for like legendary Xray, where's epics and so on? And because it's a dictionary, you get to use this weird syntax. We have the square brackets here and as an index, sort of. We can use a value off rarity on our card, so it's a manager card asset rarity, and this will give us the correct color that we want to use for this card's glow. And we are changing the glow color in 0.5 seconds on mouse exit. We're just doing the reverse. So we are changing the scale back to the initial scale off the scarred, and we're changing the color of the glow to the clear caller. So the color that is 100% transparent. So when we do this, you will no longer see the glow. And finally, the method on miles down. And it's a nice trick that you can do. You are checking if this card is turned over, then return. So if this card is already turned over, we don't care if your user clicked on this card again, and we don't have to take any action. So if turned over is already true. Then we just return and don't do anything else in this method. And if turned over, is false. The first thing that we do is set turned over to true so that we cannot enter this method again. Then we say transformed. Do Rotate were rotating the card to Vector 30 so that it's facing Our users face up in 0.5 seconds and we also say shop manager instance. Opening area number off cards open from back plus. Plus this line. Let's our opening area know that we have turned over one more card. And when we turn over all the cards that we got from pack the bottom will appear that will say done and we re Preston. We can now either return back from this man, you or we can dragon open another pack. So that is how this script works. I think that in the next lecture will try to establish all the connections in unity and finally check out how the pack opening works. Thanks a lot for watching, and I'm looking forward to seeing you in the next video and finally showing you the back opening
15. 308 – Connecting Everything in Unity and Testing Pack Opening: Hello, everyone, and welcome back to the course. So in the previous lecture we have taken, a look at the cards will get from packs will generate them. When the pack it's open and sort of exploded. And these cards that will serve just one purpose, we will be able to turn them over and show our players. What did they get from the pack? So the pre fabs are quite simple. They use most of the components that we already had in our main game scene. The books Collider. One card manager. Better card irritation. The only one that is do You is turnover card from Pack, and you've already seen that. So now we don't need these card pre fabs in our scene, so I'll just select all of them both the many ones and the game ones and Al just delete them. Then we'll have to find the script that requires these connections to our pre facts. I think it might be either our shop screen that has to have a reference to our pack prefab . So let's establish that we have the pack prefab in the scene. We who not needed as well so I can just lead it. Go to my assets. Brief APS folder. All the pre fabs for the many horse are stored in the folder menu pre fabs, and here we have our pack prefab. So I'll go to our shop screen and drag our pack prefab onto this field that says, Back prefab. And also I will have to find the script that's cold pack opening area, and it should have references to our spell card from back and creature card from back, so I'll just establish these connections. I've also noticed that our opening area is not that large so we can readjust the collider. We can make it wider in X direction and toller in wide erections so that there's less like a margin off error when we are dragging the card onto this area. And another thing that we can do right now. When we launch the game, everything's just disappears and we get to see our menu. If a breast shop, then nothing happens. So these buttons are not hooked up to anything right now, so let's go over that and attach our screens to the buttons. Our menu is located under our main canvas that is set to overlay. I have to go all the way to many background and find our buttons, parent object and for the shop. Baden. We want to do several things. We re press this button first. We want to de activate the visuals that show our main menu. I think will use this panel. So I'll drag our panel on to this object and else select game object set active and I'll deactivate this panel. So when we press on the bottom, that has to lead us to the shop. We want to hide the main menu, and the second thing that I'll add here is the reference to our shop screen on the shop screen object. We want to find the script shop manager, and here I know that you are not probably able to see this drop down, but here I'm selecting the method show Speen on our shop manager here. It's as shop manager dot show screen, and this will ensure that shop manager is visible for our players. And then I think we should do the same thing for our back button in our shop manager. So when I select the back button when pressed back what do you want to do? I think that we want to have a reference to our shop screen here as well. I'll go to shop manager and this time I'll select hide screen so we no longer want to show it. And instead we want to return to our main menu. So I'll grab our panel object that represents the main menu, and I will go to game object and select Set active, and this time I will activate. So I'll best true into the method set active. Finally, I don't know if our buy button is hooked up to anything, and it turns out that it is not connected to anything. So I'll hit. Plus here, drag our shop screen onto our buy button, and in our shop manager, I will try to find a function BIPAC so it will buy one pack for our player. Now let's go and test this and hopefully we get no errors. So if I launched the game, the first thing that we want to test is if our buttons work, so if oppressed shop it should take us to the shop. If I present back, it should take me back to the main menu, so that works. Now we have this amount of gold and we can try to buy packs. So if I buy a pack, I guess that works as well. We might want to readjust the values off minimum and maximum offset because this back, obviously it appeared to high on our panel. But that can be easily fixed if we just adjust the numbers. And then if we drag this back onto our pack opening area that sits right here, So on top of that collider and we don't have to drag it into in the center, off our pack opening area, we can try and drag it here on the side. So this back it gets attracted towards the center. And then when we hover over the pack, I thought that we should be able to see the glow on the pack and this is not happening. I should check out why that is not happening. If we press on the pack also, it doesn't work for us for now. So he didn't run as smooth as expected. I will have to exit and search for an error that we have somewhere. So I'm back and I wanted to provide a quick update on the pack opening situation, so I have checked. And one of the things that wasn't set up correctly is the collider on the pack opening area . So the reason why our pack opening didn't work before is that our collider was just sitting there in the center. It center was set to 000 and it might have caused that when we were pressing on the pack, it was detecting a click not on the pack but on the opening area itself. And that's not what we want to achieve here. So an easy fix for this is to shift the opening area collider further away from us so that the packs they always appear on top of the opening area, and we check if the pack is on top of the opening area if our cursor is in top of the opening area. When we dragged the pack by saying Ray cast all so it will ray cast through the pack in that case. But when we are clicking on the pack, we just use simple own miles down, so this a pack has to be the front most object the closest one to the camera. So I have shifted it further away from the camera. And now if I launch the game, I will have another error and I will look into fixing that right now. So I just wanted to show you shop and the amount of packs that we have. It's also saved correctly. I'll have to change the numbers here as well. But now, if I drag the pack onto the pack opening area, when I hover over the pack, it detects the fact that were hovering over correctly. When I press on the back of the pack shakes and it starts incense, she ating cards. I get an error here in my one card manager and a do between error that I will inspect right quick and fix them. And I'll return back to you with the fix for this issue. And now I've just figured out the issue with our cards, spawning incorrectly from our pack as well. So that is caused by the fact, and I can show you that in Mona develop the script. One card manager writing the end of the script. It also says rarity stone image, which is the image that will mark rarity on our card. I used another script that it's cold rarity colors, and we have not added it to our scenes. So when it says rarity colors dot instance, it can find anything here. So it's essentially like saying no dot colors dictionary. And we don't have access to that from no. So we have to add a script off type A rarity collars into our scene. It's a very simple script that it has the only purpose just holding the colors for our card glows. So let's do that. I will go to Project and locate our Assets Scripts folder. We should have our rarity collars somewhere in this menu folder. Or actually, we can carry out a quick search. So let's search for rarity collars, and I have already prefab this object so I can just drag it into my scene. But it's very simple object that just holds this script that you have access to this, like simple to let's go data and you can add it. The collars for rarities like basic basic cards, will have 100% transparent rarity stone. Then common cards will have white swear, easy sewn rare cards, Blue epic purple and legendary is we'll have this gold orange color so I'll just grab our rarity color spree FAP, and will bring it into the scene. It doesn't have any visual representation, just a script that sits there and we should be able to get our ready to collar is that instance now? So I will launch the game. I think it'll work, so I'll maximize the game view. I'll go to shop. We have the packs. I have also readjusted the settings in our shop manager. I made the packs appear a bit closer together by changing position, X range and position. Why range? And so now I am dragging this back onto our opening area. Now the repress on the back will get these five cards for Is there? Appearing in this funny pattern will have to adjust the positions for these cards. But now you can already notice that when they hover over the cards, they're showing different collard glow. So all these cards, they seem to be rare, and we have one common. So let's start turning them over. We have a source, sir. The Pew Pew spell another one. The envision spell and another Pew pew spell. I don't have that much card assets in my game. So now I can just press done. And I also realized that the done button is not connected to anything. So let's just go and do that. I will return to my scene. I think that if this is our cannabis that we use for the done button and here we have to find, I guess it's our opening area. So let's try that. I will drag our opening area onto this object, find our pack opening area, and there's this method that just says Done So that serves the purpose off, letting our system know that. Okay, we have open the pack, and now we can either open another one or return back to the menu. So finally, let's try that again. We'll go into our shop now we have three packs here, so it seems like the system has found out that we have opened one pack already. So let's open this one. We're getting the cards who we got a legendary. Here's the rarity stone that marks that its legendary and the glow is orange. Ah, let's turn over old. They'll their cards, and now the done button should work. So now that I press done, you can see that, um and that Deng button doesn't disappear. I'm sorry. I can go back, go back into the shop. That on button still sits there. So we have to establish this reference to the buttons somewhere. I tried to find something that will deactivate this done button in one of the scripts, and I haven't found it, but I guess that we can always do just directly in unity because we have this nifty system off on click events so we can create another event on our done button weaken Dragged the done button itself as a game object onto this event, we can access the game object and everything that we have here. We can set this button active to false so that when we so that when we press the button, it just disappears. And let's try this again. Hopefully our last time. So I will launch the game, go to the shop. We have two packs left. I will open this back. We have a legendary again with stern over, or we have an epic now and right. So we have opened all the cards. Now that we press done, everything disappears. So both the guards are destroyed and the done button has also disappeared. If we press back, we go back to the main menu. If we go back to the shop, we can buy packs again and open them when a I am in the middle off opening. In fact, I shouldn't be able to drag this other pack onto the pack opening areas. So if I start turning over the cards, I'm still not able to drag this back. And when the done button has appeared, I am still not able to drag the next back, and I'm not able to return back because the back button is not interact herbal now. And when a press done, I can return back and I can drag another pack. So that's exactly what we have intended for this menu in the game and all these cards. When we turn them over, they are also added into our card collection. So our system is aware that if we got this card from pack, it means that it is now accessible for us to add it into our deck. So in the next lecture will take a look at the Onley script that we haven't seen yet that it's called the pack opening area. And then this whole back opening topic will be over and we can approach the other topics, like building a deck and browsing our card collection that are a bit more complex. So I would like to thank you a lot for watching story for all the errors that we have experienced in this lecture, and I'm looking forward to seeing you in the next lecturers of the course.
16. 309 – Inspecting the PackOpeningArea Script: how everyone, as I promised in this lecture will wrap up the topic off back opening in the scores and we'll check out the last strip that we haven't seen so far, which is the back opening area. So let's jump right into it on top of this script pack opening area. I've included this attribute that says Require component type off Books Collider so that we know for sure that the Books collider is missing and we don't forget to add it to our pack opening area. We have all the public fields here. This public property, allowed to drag a pack, will not be able to seat in Inspector and will use it to know that we're not currently in the middle off the pack opening. So we are allowed to drag it back on Lee. When we are not doing anything else and we have opened the previous back, we have to game objects that are our cart brief APS that we have discussed in one of the previous lectures. We have references to our done button and back button for done button. We want to set it active and show it when we have turned over all the cards from pack and for the back button. We want to set it, interact, herbal or not interact, Herbal, depending on where in the process are we right now? So if we are in the middle off the back opening, we don't want to be able to go back. Then we have these probabilities and I included this range attributes on top of each of these probabilities. And generally, if I go back to unity and show this to you. So if I expand our shop screen, select the back opening area, the probabilities should look similar to this. So the legendary probability should be much smaller than the epic, and then rare probability should be much larger. I think that the correct values are actually a lot smaller than the ones that I have right now. So legendary should be even less Pro Bowl. The epic should be something like this, and then the rare probability should be a bit smaller as well. But you can adjust all these values and experiment to get the right field for your game. Then let's return back to mono develop. We have the collars here, but I don't know if we actually use them. I think we mostly used the colors form that script rarity collars that caused an error for us in one of the previous lectures. So we'll inspect how this collar situation works when we will go through the code in this class. Then we have this check mark public buoy and give at least one rare. So this insurers that if you generate the cards that you want to give your player in a pack and he didn't get at least one rare card. So all the cards are Commons. It will try to generate one extra card that will be at least rare or better. So that's the purpose that this Boolean serves. Then we have public transform array slots for guards. We have to readjust them to make the card opening look prettier in the scene. These are the references to those little slots objects that the cards are sort of drawn to when you open the back, the back explodes and the cards fly into old directions so they are flying towards these slots. Then we have several private references. Private reference to the Box collider on our back opening area. That's really straightforward. We have the cards from pack created that are stored as game objects. See why we need that in a couple of seconds. We also have a property number off guards opened. Get just returns, the value numb off guards open that we have here. And when we set the value, we check if the value is equal to slots for cards dot length. So if we have opened all the cards on all the slots of, for example, this will work even if you don't want to have five cards given to your player from one pack . You can make the length of this slots three, for example, six or even 10 so that he gets a lot of guards, and then it will just check when you have opened all the cards. Then it will show the done button that you can press to end this process off. Back opening now in awake, Get the collider Surrey say get Component Box Collider. We sat allowed to drag it back to true, so when we have just launched the game, we're definitely allowed to drag packs if there are any. So we know that we are not in the middle off the PAC opening, so we're setting this property to true. We also populate our dictionary with colors. Glow colors by rarity will see if it is used here in a couple of seconds about the syntax. For this is Glo Colors by Mary T. Add And unlike adding something to a list where you have just one argument in your ad method, here we have the so called key value pair. So we passed the key. That is our rarity options. And we pass a caller that is one of the colors that we have here. Then this method cursor over area, and we used a similar code construction for figuring out if we are dragging the card onto the table. So there we say something like cursor over table. And here we use, as they said in the previous lectures, we use rate casts old, so we don't care if something is blocking our ray cast. As long as we get through this stable collider or through this area collider that is our c o l collider, we're fine, and it'll detect that our cursor is over it. So we just yet all the hits we have a Boolean passed through table collider. We check all the hits. If we have hit our collider CEO L that is attached to this area, then we say passed through table collider equals true and we return this value. So this method is an easier way to check if we are hovering over this area with our cursor and will need this for our pack dragging. Then we have this method show pack opening. I don't know if we want to inspect it right now, so it's a bit more like complex. Let's take a look at our next methods. So the final method is called done and this method will be cold when we press our done button. So when we're done opening, get back, we are allowed to drag back again and we're setting it to true than number of guards open from pack. We set it to zero. So we just reset the value and then we also have to destroy all the game objects that we have created while we were showing the pack opening. So we looked through our cards from pack creative and we select the zeroth objects if we have any and We're just destroying it, and we're doing it over and over until our guards from back created list is completely empty. So once the back opening is over, we destroy all the cards that we were showing to our player, and we also sat back Button interact, herbal to true. So now that we have opened the PAC, we can return back to the menu and we have this next interesting methods. So to get a card for impact, the only thing that will matter for us here is the rarity of the card. It's a private method, and it returns a fully ready game object. So it'll instant she ate a game object like we do here. We say card, instant shade, and it will make sure that this card has the rarity that we supply here into this method. First, we go into our card collection and we get all the cards that have the rarity that we have given here as an argument to our methods. So we say card collection instance. Get cards with very T, and we're passing this rarity from here. So now that we have retrieved this list, we can find one card asset from this list, and we can do that by saying cards of this rarity. And as an index, we're generating a random index from zero to this a raise or to this lists count. So we're just selecting 100% randomly. We're selecting one card out of this list now that we have the card asset A. We're also adding it to our collection. So even before your player turns the card over, even the moment this card is just generated. It's already added to your player collection so that, for example, if you will make this game and converted into multiplayer, if the game disconnects, it will not be so important for your player because he has already got all the cards, even if he hasn't turned them over. Then we have a game object guard. Here we just declare this game object, and the reason for this is we don't know if this card is the creature or a spell. So to check that we say if a dot type of card and A is our card asset that we got from collection. If the card is a creature than we instance, she ate creature card from back prefab creature and spell cards. They're just different by their visuals in this situation. So the creature card it has an oval frame around the image, and it's also different because it has the values off attack and health while spell cards. They don't have that, so we. Instead, she ate the creature card from Pack as game object. And if it's a spell card, then we instance she ate the spell card from pack prefab. We want to make sure that our card is rotated correctly and it's facing with its card back towards us. So we say card transform rotation and we apply 180 degrees rotation in Why excess? Then we find the one card manager on our card, and you've made sure that our guards from PACs have it. So one card manager, we get the component. We say manager dot card asset equals a so that the manager knows how to re skin the card and which graphic elements to apply to the card. And then we say manager read guard from asset and in the end return card. So now that the card has been returned to us, this card is already facing away from us. It has been re skinned, so it looks exactly like we needed to, and now it's ready for our player to turn it over. And finally, let's go through this method Show Pack opening in show back opening were first making the rarity options array rarities There is in you array, and it is of sides off our slots for cards length. So we have to generate five rarities that corresponds to our five slots for cards. We have a boolean, at least one rare given. We want to know this information because if we have not given our player at least one rare card and we have this option enabled, give at least one rare. Then we just substitute one off the elements in our rarities array, with the value off rarity options that rare so that he gets at least one rare card. And the way that we generate these rarities is we go through our rarities array from I equals zero to our rarities. That length we generates a random number from 0 to 1, and then we check if our probability is less than legendary probability. Then we say brevity is with an index off. I is a legendary At least one rare given is true in this case else. So if it's not a legendary, so we haven't like the random number, it didn't lend in this margin like it's not less than legendary probability than it might be less than an epic durability. So if it's less than hour epic probability value, then it's an epic card. And similarly, if it's not an epic card, it might be a rare card. And if it's not a rare card, then it's for sure a common card. But then we don't say at least one were given equals True. Then there is this check that substitutes one off the rarities that we have generated for our rarity options rare. So in this method, until this point, we don't even have the actual cards. And now that we have determined they're rarities for the five cards that we have made, we go into this next loop from I equals Zero i e. It's less than rarities length, So we are looping over our muli generated rarities rate again, and here we say game object guard card from pack rarities. I so here we are actually calling this next method that we have already seen and making actual cards for each card that we make. We are adding it to our cards from pack created Array. We are setting it's transformed position to card, initial position and cars. Initial position is just given to us as an argument off this method. And then we say card transform, Do move, and we're moving this guard towards its respective slot. So each card will be moved towards its own slot in 0.5 seconds, creating this effect that the cards fly out from the pack into different sides and lend into these spots where we can turn them over. So that's how the pack opening works. I know that it's sometimes interlaced and all interconnected and not that easy to understand. But we have a nice example in our other scene that is already pre configured and it works. We have achieved the same result in our course seen, so if you have any questions, please feel free to ask them in the Q and A section off, the scores in the next section will take on an even more interesting topic, which is browsing our card collection. Thank you very much for watching the scores and I will see you in the next section.
17. 401 – Introduction to Section 4: Hello, everyone, and thanks a lot for watching the course. So in the previous section we have taken care off the shop and the PAC opening experience in our game and in this section will take on another part before game, which is browsing the collection, making decks out of cards that players have in their collection, crafting cards and so on and so forth. So I wanted to take this lecture to show you how the collection screen looks like in very general terms. I will tell you how it's made, and then we can, like, approach and start actually making the collection screen. So let's get right into it. I'll launch the game, by the way, Right now, I'm showing this to you in the scene that was pre made. The scene is called menu Scene, and it was included in our initial unity project, and we're trying to recreate the same stuff in our menu. Seen course. So now if I press the collection button, it will get us to this part of the game, this menu that lets us do several things. First, we can browse our collection, filter it by a lot of different parameters like we can check out the cards that belong to our classes, and we have only two of them. Elf Monk neutral cards that can be featured in the decks for both off our characters. We can go to this old tab that will just contain a mix off all the cards off all the classes. The cards are sorted by their man accosts, so we get the one man accost cards first than the two mana cost cards. And if we scroll further into our collection, then we'll get four and six. If you include more cards, they will all be sorted by their mana cost. We can apply a custom filter. For example. I want to get on Lee the three man accost cards. If there they are, all the cards that we currently have in the game that require three managed to play them, so there are several constructive elements in this screen. And let me just break this down for you. First we have these tabs. That's a elf monk unusual hole, and these are just bottoms that sit behind this window, sorting wise. So they're behind this window when we press on one of them it gets a little bigger in scale , and that's why we have this effect. Then in the lower part off our screen we have this man, a filter that lets us select guards that costs zero man a one man to money and so on and so forth. So this is another interactive object that we have here. This next thing that says show X zero cards. It is a simple unity total, and I just change the way it looks. So you can put the check mark here or unchecked this check mark. And if you had cards that you don't have in your collection, so the quantity of this certain garden your collection is zero, then you would just see those cards, or it would hide those cards from you. You can also search your collection by certain key word so you can type something here, press enter, and because our cards they don't have this like letters in their name or in their description will not get anything beautiful. Search for vole, for example, would get this Vulcan card. If we go to all, we'll find out that there is a neutral Vulcan. There is a Vulcan one that belongs to one of our classes, and there is a Vulcan to this one. Belongs to Elf, I guess, and this one belongs to Monk. We can right click on the cards, and this will open this next screen that is called the crafting screen, where you can either disenchanted or cards or craft this card. So there's a lot of different functionality, and we have mostly covered this area that is on the left side, off our screen. If we talk about the cards, the cards are very similar to the cards that we used in the game. Except for one little addition. I have added this like rectangle that sits behind our card. And on that rectangle I've added attacks that shows the amount off this card, the guards in the menu. They're very simple objects. We don't have to rotate them. We don't have to do anything with them, so they just have a component that will change their appearance. For example, for each creature you can load a custom image. You can load the custom name and the stats, and it's all handled by our script that is gold, one card manager and the same thing will be true for spells. And the only script component that our cards will have is the component that will handle two things. First, our right clicking that will total this crafting screen where we can like disenchanted this card and it'll show you like you have 13 of these disenchanted again, and your dust count or spare parts count will go up in the lower writes Bart of your screen . You can exit this screen just by clicking away off the card. And then this script component will also control the behavior of this card when we press on it, when we click on it when we are in deck building mode. So right now we're not in the deck building mode were just in our collection. If you look here on the right, we have this list that is called your decks, and we can either. Like if I press this cross mark will delete, ADAC begin creates in you duck where we can just edit one off the existing decks. So these items in our your decks list there just buttons and their buttons with a custom script. So this script it Olsen knows that it has to load the image of the character. It has to load the deck name. So these are essentially the decks that we have pre made in the game, and our characters can use them. So now we can enter one of the decks that we have pre built, and you can see that the screen will change when we enter into one of the dec's first change is that now we only have two taps were making the deck for our elf class, so we only have the Elf tab and the neutral class stab. We can no longer use monk cards here, and we also have these little ribbons that represent our deck least. They show us which cards are currently in our deck and how many of them are in the deck. If I press on one of these ribbons, the ribbons also have their own functionality. So if I press on one of the ribbons, it will remove the card from our deck and it'll go back into our collection. So let's try that I have this Elvin card that says, Beast one. There it is. And if a press on the ribbon that represents discard in our deck. It will just remove itself and bring it back into our collection. If a press on its in our collection, it will add this card again into or deck, we can change the name of the deck. This is an input field so you can type anything you want here, and the name will be saved into player preps. Once you're done editing the deck, you can press done and you will return back to your collection browsing. So as we have seen in this deck building mode, when the pressing one of these ribbons it removes the card from our deck. And it also removes this little frame that we had around the deck when it's full. Currently, our decks are Onley, made off 10 cards and have made it for simplicity because we don't have that many cards, so I can include another card. I guess we already have these. So I've just included one more card, and the frame around this window is back, which means that this that is full and ready to play, and also when we press on these ribbons when we press on our cards, the cards also have a script that if we click on the card, it will get automatically added to our deck. So in our next lectures will start rebuilding this screen, rebooting this layout sort of element by element. And the main elements here are this main window that features the cards. The cards they get spawned automatically on top, off the slopes that are made for cards. So the slot is Justin Empty game object. So here we have an empty game object here and these game objects they form this five by two grid. We have the taps that let us filter and select the cards that belong either to a certain glass or that are neutral. You also have this meant a filter. We have the struggle, which is the simplest element. Probably we have this input field with a cross mark that can help us add a keyword filter to our collection. And here on the right, we have two different objects. This 1st 1 is the deck list object that helps us edit the deck. And when we press done, we also have a different object, which is a list off our pre made decks. So we'll also have to make those two to make it old functional. And, of course, along the way we'll look at a lot of the scripts that make it all tied together and make it a work as a Rio card collection in a trading card game. I would like to thank you very much for watching and I will see you in the next lecture.
18. 402 – Collection Window Layout: Hello, everyone, and welcome back to the course. In the previous lecture, we have seen how our card collection should feel and how it should function when we have it all set up. But currently in our scene that is called menu seen course, we have absolutely nothing set up for the stream, so we'll have to do it all from scratch. And let's start by adding some graphical elements to our scene that who represent all those like panels, buttons, tabs and so on and so forth just for our convenience. Do not obscure our view. With this menu, I will disable the canvas object El De activated. So it's our main canvas that is gold canvas over everything in my other scene that is an overly canvas that shows our main menu will deactivate that than in our shop screen that we have already made in our previous section. We can just deactivate the screen content. So were left, sort of with an empty scene that has just the background and for our deck building screen. Let's start by creating another canvas, so I'll go, and in this menu I'll go to you. I you probably can't see this context menu, but I'm creating a canvas and I'm setting it to world space. Now that I've said it to world space, I have to reset its position 200 the width and the height who readjust later. I actually think that most of the games there something like 1920 by 1000 and 80. So let's use these dimensions, and then we will readjust the scale to make a few appropriate on our screen. Now that this canvas is world space, let's probably rename it to background canvas. I remember it was cold like this in my other scenes. So let's just keep the names consistent and then just to have something visual in our scene , let's right click on our canvas. I'll go to you I and create a panel as a child off this canvas object. Now, if I go to the scene, our canvas is actually much bigger than our background. If I double click on the campus, it's huge and we have to readjust its scale in X and y direction and we can try some values . I think something like zero point let's go with 0.2 for now, And now if I said it to zero Z or two, if I double click, we almost get the correct size. The size is very close to the size off our background, which is good. The next thing that we can do is began readjust its with, so we don't actually need it to be this wide. We wanted to leave this part off our screen for showing either our deck list or the collection off our pre made decks so I could make it even more narrow. And then this panel, it will represent the background off our scene so I can go and select another sprite for it . I think I was you using this sprite for everything. It is set to be semi transparent so I can return. It's L for all the way 2 to 55 here and I can write Quick, go to you. I create another panel. On top of it. That'll be our frame so I can go and find one off our frames. I think I was using the same frame for everything, but we can try and be creative and use something else. So if I select this frame, I don't want it to be semi transparent. So I also go and boost the transparency all the way 2 to 55 and now this panel will serve as a background, so its name it that and the next battle that we have will serve as a frame. So let's also rename this object now. We don't want this background object to occupy the whole canvas. So we wanted to be a bit smaller to leave space for our tabs on top. And we wanted to leave some space for our lower area where we have all the filters here on the bottom off our screens. So if I go back to the game, I think this looks acceptable and I just want to make sure that we have this area. This part of the frame fit into our screen as well, so I'll make the canvas a bit smaller. Let's try that again. You can actually set the game view and the scene view to be side by side, and it will be easier to make all these adjustments. And now let's just mark two areas and tell before screen will mark the area that it's occupied by our taps. So I will go and as a child off our canvas, because we have to remember that our canvas is still larger than this panel as a child off our canvas. I'll right, quick go to you I or actually I can just create an empty game object and this empty game object. I wanted to stick to the upper part off our canvas. I wanted to stretch to the borders off our canvas. And now I also have to apply an anchoring percent to this object. So it's currently anchored in the center off our screen, and I wanted to be anchored to this area where this object currently is. So let's do that. I will rename this object to Tabs Parent and the tabs. They're made in a very simple manner. We just add a new component to this object, which is called the Horizontal Layout Group. So immunity can use thes layered groups there either like horizontal layout group, vertical layout group or grid layout group. In this case, we need the horizontal layered group. We can search for this component and add this to our tabs parent. We do want to control the child size by with and height and let's create a button just for example, I'll go to you I and Creative Button as a child off our tabs parent. If I create a copy of this button, I will press control D than these two buttons. They will occupy our whole taps parent, and it's happening because this horizontal layout group it takes care off placing and spacing off these buttons. So now I can give these objects impacting on the left on the right top and bottom. I can give them some spacing to make them stand out a little away from each other. I think that this failure of betting is too much and we can give it some betting on the right as well. And then we have one little issue in our pre made seen. These tabs there appeared sort of behind our main window, and here they appear in front of for remain window and all the sorting issues when we are working under a canvas there, solved by the order off things in higher so I can just grab thes stabs with them on top off our background object, and this way our tabs, they will be hidden behind our bread ground object in our scene and in our game view. The game view also shows me that I can make some adjustments. For example, let's actually put the game view and the scene view side by side. So one of the things that I can do is I can readjust my background to make it a bit to make it appear a bit lower. And now that I know that this upper border off our tabs parent, it doesn't fit into our screens. So let's make it our tabs fit into the screen by reciting the canvas. Then I'll grab our taps parent and I will make it shorter like this. I don't have to forget that I have to readjust the anchoring, and now I can grab my background and make it so that the bottom part of the tabs is masked by our background. So it's all not that hard. You get the idea for now, I can do eat these buttons where it can leave them in there. I think the later when we connect all the scripts, they will be deleted automatically. When we launched the game and replace by our actual tabs. So there will be a script that will handle the tabs for us. And another thing that we can create under our background canvas is the object. Uh, that will sort of cover the whole lower area off our cannabis, and it'll contain various filters. So I will right click create another empty game object and here in the scene tub. Let's just get rid off the game tab or pair it with our seen tub like it looked before. I can put this game object here in the lower part off our canvass and make it touch. This time, we don't want it to be behind or in front off our background. We wanted to touch or background, and I want to reapply the anchors so that they're in the corners of this empty game object . And by the fact that I didn't get the anchor snapping here. I know that probably my anchoring percent on the background has to be readjusted as well, so the background will be anchored here and on top the background. It should also be anchored to where it currently is and this game object. It will be anchored so that it doesn't get onto the background. Let's go this game object, lower battle or something similar, and it'll later hold our men a fielder. It'll hold our show cards that your player doesn't have. Tuggle that is somewhat similar to a crafting mode in harsh stone. So if you want to show the cards that your player doesn't have, and you want to let him craft those cards than you said that toggle on and also it'll have an input field as a key word filter here. So these are all the things that will add to this lower panel in our next lecture. I would like to thank you for watching this course, and I will see you in our next lecture.
19. 403 – Mana Filter: Hello, everyone and welcome back to the course In this lecture will discuss all the controls that are located in the lower part off our collection browsing screen, which is the MENA filter. The input Field D lets us enter different keywords and filter our collection by those keywords. And also we have a toggle that lets us show the cards that we don't have or hide them. So these three elements, I think that I will cheat and I will not recreate them all from scratch will just go and thoroughly examine how they're made in our menu scene. And then we'll just create a prefab out of them, and we'll just bring them into this scene. So now I will go into our menu scene, and in this scene I will expand our deck building screen, enable the screen content so that we can see everything here. Let's expand the background canvas object. It has several areas, so, as it turns out, I organized it a bit differently. It has the collection area that has both the collection and the tabs, and it has the lower area. It doesn't really matter, and in this lecture were concerned Onley with this lower area, This man a filter object. If you are familiar with the previous course that I have made, it is actually made out of our mana pool. So we used a very similar object as a man Apu in the game. It also featured thes mana crystals. But they didn't have these numbers here 12 and all the way up to seven plus. So I had to add those. And it also had, like, Tana manic wrestles. And now it has only eight from 0 to 7 plus. So that was an easy change. Just removing several many crystals. The way men a filter works first, it has the manna filter script that will figure out if we have clicked on one of those mana crystals. It has an array off old thes mana crystals. It has two colors. 1st 1 is the highlighted color that is just white. So it doesn't change the graphic off our man a crystal in any way. And the 2nd 1 is a negative color. If we select one off the manna crystals, it goes highlighted. And all the other ones they go on active under our men. If Ilter object. We have an object. They scold BG and frame, so it's very common. We have backgrounds and frames everywhere, and they're just images that are made so that one of them serves sort of as a background to this element. And then we have a frame surrounding it. Nothing special. Then we have this crystals object. It is just an empty wreck. Transform like we have created empty game objects. In our previous lecture, you can just right click and in this context menu go to create empty. And we have connected a horizontal layout group to this object, just like we've done for tabs in our previous lecture. If we expand this game, object that is called crystals will find all these little gems from 0 to 7 plus and each of these gems. It also has a child object, which is a text mash pro text. I like to use text much pro text reason. One. It has become free just recently, And reason number two, it provides smoother outlines. So if you don't have text mesh, bro, you can now download it on Unity Assets Store for free. And I think that it's a great asset to render text in your game, and we're not changing this text in code. So these are just like pre made tax values 01 and so on and so forth. Each gem has its own text element, and I think, Let's not jump to our keyword input field and total just yet. Let's check out our man a future script and figure out how that works. So if I double quick on our men a filter script, it'll open it for us in Mona Develop. And now that this script is open, it's super short. It has several public fields. 1st 1 is the images array. There there is gold crystals, and we have already seen that our two colors their preset to white and gray. We have our private integer current index that is set to minus one and by minus one. Here we mean that we're not filtering anything, and we're not selecting any off hour crystals. We just want to show all the cards and this man a filter class. It has three methods. One of them is called instantly in start, that is called remove. All filters remove all filters. It rates through all the images in our crystals array, and it sets idled color to a negative color so none of the images is selected. None of the images is highlighted, and we want to show cards off old man A values to your players. After calling this method, remove old filters. We also sat current index to minus one, and each time when we make a change to our state of this man a filter, we want to report this change to our deck building screen. Instance. Collection browser script dot mana cost in this case, So this collection browser script will definitely take a look at it. In our next lectures, it gathers all the information from all the filters. So from the Manaf Ilter, it can figure out the mana costs of the cards that we want to show. It will also take information from our tabs that help us figure out if you want to show cards of a certain class or just neutral cards or all the cards. It will also take information from our keyword filter and so on and so forth. So we'll just report all the data that we have on our filters into this script. So here we say deck building, screen dot instance, collection, browser script dot mana cost and we said it to current index, even though it's equal to minus one hour. Collection Browser script will be aware off how to handle this situation. It'll just show us cards with all man accosts. Then, when we have pressed on one off our crystals first, we call the same method. Remove old filters that just removes highlights from all the other manner crystals. Then we check if the index is not equal to current index. So if we have breasts on a different man a crystal, then we just update the value off current index. We highlight the respective Mana Krystle we said its color to highlight it. Else we said the current index to minus one. So if one of the manna crystals was selected, for example, we were showing the cards that cost three manner repressed on the manna crystal with the cost of three again. So it should d highlight it, and it should show us all the cards again. So that's what's happening here else. We were setting our current index to minus one, and then we do the same thing as in start. We just say deck building collection, rows of script and we report this mana cost information to that script and this method public void Press on crystal. I'm pretty sure that it works as a bottom handler, So let's go and try to find button components on our mana crystals. If I expand and select our gem, each of these gems it actually acts as a button. So this button, it has a handler. It refers to our man If Ilter object and it calls this method press on crystal and sends the index off zero in this case. So this is our first crystal that has the value of zero. So they all past the values that are written on them, for example, is gem. With number five. It will pass the value off five into our method pressed on crystal. So that's the way our Manaf Ilter will function in the game, and it will report all the information into our collection browsing script in the next lecture. I think we'll take a look at these two elements that we have next. First is this simple toggle that is just a re skinned unity total. And then we'll take a look at this custom keyword filled with an X button to cancel out all the changes. So I'd like to thank you for watching the scores and I will see you in the next lecture.
20. 404 – Crafting Toggle and Keyword Filter: Hello, everyone, and welcome back to the course. So in this lecture we are continuing figuring out how the elements in the lower part off our DEG building screen work and we have covered our Manaf ilter that lets us show blares the cards with a certain man accosts. Now we have this little total that says Show X zero cards and also this keyword search bar input field that lets us filter our collection by certain keyword. I think let's go from left to right and start from the toggle. So the toggle, it's actually a slightly modified unity total. I have just added a little background to the text area. I have decorated them with frames, which is very similar to everything else that we were doing. Our background now has a frame graphic here, and it also has a check mark object. Here in the center and on the side, we have an image also with the frame and this thing that is called label. It's taken from the unity default ago, and in our case, it says show X zero cards, meaning that rule show cards that are not present in our collection. So if we go to the toggle. The toggle has one script that is very simple. Let me open. Show that for you In Wana develop the script has just several methods. We have private reference to our total that were getting in awake. We have a method sat value if we want to explicitly say that. Okay, we want to turn the total on or off, and we also have this method value change. So it turns out that for toggles in unity, you can make a method that is called when the value off the total is changed and similarly to our men a filter. We also report the data that is set through the struggle to our deck building screen. Instance Collection Roeser script. And there is a public property that is cold showing cards that player doesn't own. And we're setting this to total, So tea is our total dot is on. So all these scripts, they just serve a purpose off, feeding this information into our collection, browse or script. And now let's go back to unity and check out how our keyword input field is made. So it's also based on the unity standard input field. I have added a frame to just to make it look similar to all the other elements that we have in the game. And this cross mark that sits here on the side is actually a button. So when we press on this cross mark, we execute a method in the script on our keyword input field. So let's check out the script. It is called that way. Keyword input field. I'm also using this input field. Enter submit, which is not my script. So this script, make sure that if we're over this input field and repress, enter Rouco a method in our keyword input field class. That's gold. Enter submit and the input field script is also not very long. So we have a private reference to our input feud that we're getting in awake, very similar structure to what we had with our total. We also have several methods. One of them is called clear, which sets the text on our input feud to an empty string, and we also do the same thing. We report this information that's featured on our input field to our collection brows of script. This time we're referring to it's public property that is gold key word, and we're setting this property to be equal to whatever text we have on our input field. And if we press enter while editing this input field, we do the same thing. So we just pass the text from the input field as a key word into our collection browser script. And the collection browser script will figure everything that it needs to show the correct collection off cards to our players. And now that we have discussed all this, we actually know how old elements in this lower area function. I think not to recreate them manually from scratch because it'll definitely take a long time. Let's try to transfer this slower area object from this scene into the other scene, the scene that we're making in this course. So I will go to assets pre fabs menu pre fabs. I don't think this is already featured in our menu pre fabs. So if I drag our lower area into the prefect's folder, it creates a new prefab for us, and there is one thing that I wanted to show you. One script that I've found on the Internet, which I love and unity system of pre fabs is sometimes very tricky because you added a prefab in one place and it makes changes to your objects in other places. If you pressed, apply or revert accidentally. So if you don't want the object to be linked to your prefab and you want to use the prefab just for the sake of saving something or transferring something from one scene to the other , I've added the script to your project that adds this new context menu item that says Break prefab instance. Definitive it on links the object from the prefect. So right now our object appears as blue in hierarchy. So all the names of these objects in hierarchy are highlighted in blue, which means that they're a part of a prefab. And if I go and press brake prefab instance definitive. The lower area that we had in our seen stays the same. It is now saved here as a prefab, but we no longer have a link between these two objects. So if I make changes to this prefab in here, they will not be reflected in our lower area, and it means that we will not a mess up are seen in anyway, so I think it's very useful. You confined this script. I think if you search for break brief, of instance, the script is gold prefab break menu items. And unless you do just that, break the link to your pre Febreze and don't let us go to our S. It's folder. Let's go to our many seen course. I will save this scene. We haven't made any significant changes here, and I will go to our brief EPS folder menu pre fabs. I will locate our lower area and we want to find the parenting object for our lower area. Like instead of this lower panel, I think we can just lead that. And instead of the lower panel, let's add our lower area to the background canvas so it flips right in. There are several like inconsistencies. For example, this total it is not anchored correctly. I am not sure if it's angered correctly that scene as well, but we can manually readjust this, then figure out the anchoring by just dragging the anchors, applying them to the corners off this object. So it turns out that he was just anchored to the central area and then if we go back to our game tab, one of the things that you can notice is that this area is not visible in your game depth at all, so it's just cut off by the boundary off our screen. So right now, actually, before making any changes, I want to make sure that a break brief up instance that it's just a object that we have copied from another scene. And also I can select the background canvas and I can make it shorter so that our men a filter, our toggle and our keyword bar they all appear and become visible in our game tab. So what's returned the game tap to its original position. There's our set up with all these new elements and now we can also go to the scene and readjust our panel just a little. So let's go to the background and I will make this panel touch our lower area and incurred appropriately. So in our next lectures will gradually move through the other elements that we need to bring into our scene to make this collection browsing screen functional, who add agreed off empty game objects to this window to give our cards some markers. Where do we want to instance she ate them. We'll add two buttons here on the sites, even though they were hidden in our previous scene. And we had those funky sliding arrows that were letting us switch Bages in this collection screen, actually, in the background there just buttons that span across the whole, like height, oath, this window. So we'll add those and will work towards making this fully functional in our new scene while also looking at all the scripts. I'd like to thank you for watching the course, and I will see you in the next lectures.
21. 405 – Character Tabs for Collection Filtering: Hello, everyone. And thanks a lot for watching this course. So in this lecture, I wanted to cover the topic that we have sort of skipped. We have touched it just briefly, the topic off having these tabs on top off our collection window. And it turns out that it's not as automated as a thought and will have to create all these tabs manually. And there will actually be two different layouts of these steps Right now, you see that my tabs object is just an empty object with a script character selection, tabs that you look at in this lecture or in the next lecture. And I have two different sets off tabs. One of them is called tab Buttons for collection browsing. It has horizontal layout group, just as we try to organize our tubs in the scene. And it has just told the different tabs that you can have in your game. You know, in advance that you will have certain classes like elf monk and so on and so forth. You will have your neutral cards, and I also included an option off showing all the cards at once. So whatever classes you will have in your game. You know them in events, and you can manually create all these taps. And then there is also the second objects. So if I deactivate this one and actuate the 2nd 1 this one will be activated on Lee when we are building a deck. So if we switch our collection to deck building mode, we can only access the cards that belong to our class, the one that we're building the deck for and also the neutral cards, the cards that can be included into any deck. So let's our goal for this lecture. Let's just go into our scene because this is my pre made seen that we are looking at right now and let's recreate the same situation in our course seen. So I'll just leave everything like it was before. I go to our project assets switch to our menu, seen course, the one that we're working in, and let's try and achieve the same result here. So I'll expand our deck building, screen screen content and as a child off our background canvas. We have our tabs parent. Right now, it is already holding these two buttons, but as you remember, we have to include several empty game objects or Justin Empty game object on top of this stabs parent. So let's call these stabs, for example, the tabs for during deck Building. So let's say tabs deck building. Then I will create an empty game object as a child off our background canvas. Just click, create empty, and I will put it into exactly the same spot where our tabs card the art. So I will just match the position off the tabs and the anchoring as well. So I don't want to be anchored in the center. I wanted to sit where our tabs are, and this is going to become a future parent for our taps. So let's call this one tubs, and I'll grab our tabs that building and bring it onto the stabs object. And I also have to change the order of the stabs object to make it appear behind the background so that we don't get our tabs on top of the window. And then let's work a bit on one off our tabs. We have to do this only once. I can do it. One of the tabs that we don't need. Let's work in this button. So for this button, we want to change the image on the bottom instead of you. I Sprite, we're going to use the common image that we use for all the U I in the game. I think it's this one. And then we also want to apply a frame to this button so well, right click, go to you. I select an image who make this image fit to this button by pressing old control shift, selecting this stretching preset. And then I will go and select one of the frames that we have for this button. I think something like this will do. And then for text, we want to change the fund to our default Devyn slash phone to that we use everywhere In this project we can increase the phone size manually or we can just enable best fit. And actually, we probably want to do one more thing with the fund. Let's at some batting to the fund so that it doesn't stick so much to the lower part off our tab. It wasn't strictly necessary, but I think it will look better this way. So here we have one like pre made tab Currently, says Button, let's change the tax to, say class or neutral was your class for this stab. And let's create a copy of it by pressing control de with its selected in the hierarchy. And let's call this stub neutral. Now that we have built the tubs for deck building, let's create a copy of this game. Object Soil breasts, control de here And instead of tips for deck building, let's rename this one into tabs collection, browsing and for collection browsing. We want to have the tabs that describe each off our character classes neutral and the old character stab So taps for deck building. Let's deactivate that object. I will select our neutral tab and create several copies of it. And then I will rename all these stabs accordingly, just changing their texts. All right, so it seems like our tab buttons are ready, but we have two scripts that are responsible for controlling our tabs. One of them is attached to every tab so we can just collapse all these extra objects that we have as Children off our tabs, select all the tabs that we have created, and I can go to add component. I think it had tab in the name, So I will search for Tab and it's cold character filter tap. So let's add this script to each off our tabs. So this script is relatively simple to set up, at least in the editor. So let's start from our tabs for collection browsing. For example. This stub represents the cards that belonged to the Elf class, so I can go to this field that says Asset, and we should find the character asset that belongs to our health class. We can switch this window from scene to assets, find the Elf asset and select that. So we want this step to select Elf Guards Force, then the second taboo. We're doing the same thing for a monk, so we're going to assets and selecting them long here and for the neutral tab. The next step. We don't have to do anything so neutral cards. They're the ones where the character asset isn't set to anything, so it's set to know. So that's why we don't have to change anything. It's already set up correctly, and for this last tab we can just enable this little Tuggle show. Old characters So I enabled this check Mark and we have all these steps set for the other tabs that we have tabs for deck building. We don't have to change anything there because they will be set up in code. Our neutral tab will not change that much, the one that is for Deck Building and our character tab. This asset will be applied automatically. It will depend on the type of character that we are building the Deck four. And there's another script that controls our tabs behavior more like a tab manager that handles all the tabs at once so we can go to our tabs object. I will go to add component. And there is a script that he's cold characters selection tabs. So let's add that it has an array off tabs where we have to feature all the tabs that we have in or project. So I will just like the inspector on this tabs object with the script that we have just added, and I will select all the buttons by holding control so well, select the buttons for deck building and for collection browsing, and I'll drag all of them onto this array, which will populate this array and at all the tabs that we have to the array. And we have a couple more references to certain tabs, and we mostly need them just to default our selection to these steps. For example, when we are building a deck, we want to default our selection to the class stab so that when the player selects that he wants to build a deck for a certain class, he will first see all the class cards. So let's do that. I think that this one is our glass tab for deck building. So let's drag it onto here. And another tab that we need a reference for is gold neutral tab when collection browsing there when we are collection browsing the first want to see the neutral cards that can be featured in any class is just our preference to show this star players so also like this button to that is supposed to be the neutral tab. That's right, and I'll drag it onto this neutral tab when collection browsing. I think that the work that we've done is enough for this lecture in the next lecture will take a look at all these scripts first, the character selection tab script that manages all the tabs and then on the script that is featured on each and every tab in our scene that's called character filter tab. I would like to thank you very much for watching the course, and I will see you in the next lecture.
22. 406 – Character Tabs Scripts: Hello, everyone, and welcome back to the course in the previous lecture. We have set up the character selection tabs in our projects, and we know that they're controlled by these two scripts. The 1st 1 is Gold Character Filter Tab, and it's featured on every single tab that we've made in the previous lecture. So let's take a look at what it does and how it functions we have the public feels that you've already seen the one that says Asset, Character Asset and the common here says, If no, this is the tab that select usual cards that is true. And we also have the second check mark that shows in the Inspector. It's gold show old characters. It is very specific, and we're doing it only for that tab that shows us all the cards, both neutral and the cards that belongs to all the characters. For that tab, we have to set it equal to truth. We have a private character selection, tabs tab script. I don't think that it's used here, so let's see if I come in this out. It'll not do anything just for the sake of not changing the code, I will not do anything to it here, but it seems like it's not used in this script, so you can just move it if you'd like, then private floats, selection, transition time. And this is the time that will use to change the scales off our taps. When we press on one of them, it will be sort of zoom in a little blown up, and it will happen in 0.5 seconds. Then we have private Sector three initial scale that is set to Vector 31 if you will have a different scale for if you will have a different scale for your tabs, you can change it to some other value and will use it to de select our tub and return it to its normal state. And we also have this private float scale multiplier. So when we select one of the taps will make it 1.2 times bigger than all the other tabs. We have this method public. Avoid Tab button handler. It will refer to our deck building screen instance, tab script, which is that other script that we haven't seen yet. We'll take a look at it in this lecture and will call a method Select tab as arguments into this method will pass this and the second fulls argument it refers to instant. So whether we want to select the stop instantly or show that little sort of animation off a tab being selected, we need this instant way off showing the tabs just like they are, too, said their initial state when we just enter the screen. So when you enter the screen, you probably don't want to show any animations. You want the players to enter the screen and see tabs in a certain, like initial state. So that's why we need this four. And if we are pressing on the tab button and the tab button handler is cold, we certainly want to show this animation. And then we have these two methods select and de select that are cold from that other character selection tabs script. So they're called externally, and here we are, checking if instant then we are just setting our transformed local scale to be equal to something. In this case we're selecting. So we're multiplying our initial scale by the scale multiplier and else if we want to show a little sort of animation then we're using between. So we have included using dg dot twinning here on top of our class, and that enables us to say transformed up do scale. And as the first argument into this method, we have to pass the float. So this do scale. It changes the scale off our object union, formerly in old directions. So we just grab initial scale dot acts. We have to take just one of the values multiplied by scale multiplier, and we are showing this animation during the selection transition time. So in our case, it 0.5 seconds and a very similar thing we're doing if we are de selecting. So if it is instant, we're just setting our local scale to initial scale. And if it's not instant than we are using between again and we are tweeting scale towards initial scale during our selection transition time. Now that we have covered this script, let's take a look at the tab script and what this method select Abdo's. So I will go to character selection tabs. We have all these public feuds that you've already seen. The 1st 1 is the list of tabs that covers all the taps. Then we have a public character, future tab, class stab. Then we have those two special tabs. One of them is the class stab that we used during deck building. The other one is the neutral tab that we use when we are collection browsing. And these are the default tabs that we show to our player when he enters this screen. And we also have this very important private field that's called into current index. So we actually track which one of those tabs among all the tabs that we have in the project is selected. The Method Select AB is cold when we pressed on one of the tabs and we passed the tab itself. So that's scraped character filter tab tab and we're saying Bruin instant. It might be an instant selection or it might be not instant selection. So first we are trying to figure out the index of the new tab that we have selected Surrey say tabs, which is our list, and we say dot index off tab. So the tap that we have just clicked on we're trying to find the index off this stab in our tabs list. If our new index is equal to our current index. So we have the neutral tab selected and we just click on that tab again. Then we don't have to do anything. And we just returned from the method. And the only way for us to full through this statement and continue into our method is if our current index and this new index are different. So then we set our current index to be equal to this new index. As the comments see, we have to select in you tab. In order to do this, we first have to remove the highlights from old other tabs. So we iterated through all the tabs in our tabs list, and we are checking if he is not equal to our selected tub. So we're doing this for all the tabs, except for the one that we have selected. We say d adult de select and we passed this value off instant. That is an argument off this method. Then we also have to select the tab that we wanted to select. So we say tab dot select and instant, and this is just the visual tricks or just changing the scale and indicating that the tab is selected for our players. You can include some sort of a particle system spawning above the tab when you press on its in this select methods, so you can just extend the functionality of this package to your personal liking. And then, like everything else. So remember, like for our men, a filter like for our keyword filter and the little Tuggle that we have in the lower area off our screen were reporting our selection to our collection. Bro's their script. So we see Doug booting screen instance collection browser script. It has a public property that he's cold asset that represents a character asset, and we're passing tab dot ass it into this asset field and also just a special case. It has another public field that says, include all characters and into this include old characters, property were passing that value off show all characters bullion on our tab, and we have another method here that says SAT class on Class step. It takes character asset asset, and it's done because we don't know in advance. You might have several character classes in your project, and when you enter deck building, you want to make sure that that class stab shows you the correct cards. So in order to do this, we'll call this method set class on class stab, we would say Class stabbed, Old asset, Equal stoop asset. So the argument of this method and we'll also change the name on our class stop. So we say class, stab dot get component in Children because the class stab is a button and the tax component sits on the child object off our bottom severe finding the text on the tab. We say dot text and we are setting it equal to asset adult name. So now it will not say just class. It'll say, monk or elf or the name off any of the classes that you create and one last thing to make it fully functional. We can go and select the tabs in our project. And as a button handler on all these steps, we can add a handler to this own quick event. And I think I have to do this personally for each and every tab. You can just grab the component character filter tab, drag it onto each off your tabs. Here we can go to character filter tab, and we have to find that method Tab. Botton. Handler, I know that you're probably not able to see this, so you have to select the method Tab Botton handler to be called from your character Food or tab script on each tab. So I'll just do this action for all the taps Character filter tab into here. Find component character filter tab and call the tab. Bottom handler When we pressed on this bottom and now that this is done, we can say that in this lecture we have covered everything that you had to know about. These tabs in the next lecture weaken touch on different topics off our collection screen. And they are the greed for cards on top of this collection window. We haven't made a couple of buttons here on the sides off our collection screen that will switch the pages in our collection. And we also haven't covered the lists that we have here. One of them is the least off ready made decks. And another one is the list off cards that we have in our deck. So we still have a plenty of stuff to cover. Thanks a lot for watching the course and I will see you in the next lecture.
23. 407 – CollectionBrowser Script Part 1: Hello and welcome back to the course In our previous lectures, we've done most of the filtering elements that will help us select certain subsets off cards in our collection. We have done the mana pool, the stock go, the keyword filter and the tabs on top off our collection window. Now let's talk about the content off this window. How will the cards get there and what is located in the center of this window? So I am currently in the scene that I have pre made. So this is not the scene that we're working in. And I just wanted to show you what are the contents of this window? So returns out that on top of this window I have this object that it's called Greed Four cards, and it has the Component collection browser that we have already talked about. And in this lecture or in one of our next lectures will take a look at the script and check out what it does. But then, if we zoom in, we can not see anything under this grid for cards. It has some objects, so these row for cards they're just clones off each other's through these air 100% similar objects and all of these objects are just empty. They're called card slot and they mark the positions. Where do we want to instance she ate our card pre fabs when we want to show cards to our players in the collection. So I have just placed the manually. So this first guard is located at X minus eight to the second card, minus four. The middle card is located at 000 and the next card is it for the next card. Is that eight in exposition and these numbers? They seem to work well for our task. And then I just copied this row off cards. So the 1st 1 it sits on, why equals three. So it's a bit above the midpoint off our collection window, and the 2nd 1 is probably at minus three. That's right. And then, in our Grade four cards, there is this object that it's called slots, and it has references to all the card slots. You can drag them one by one manually so it goes like this from the 1st 1 and it goes through the first row off cards and then it goes on to the second row off cards, so this object is not that complicated, and we don't have to re create it manually in our other scenes. So what I'm offering is we can just transfer it to that other scene. And it turns out that there is a much easier way. We don't have to create pre fabs or do anything like that. We can just right click on our grid off cards, object breasts, copy here, and then we can go to our other. Seen the one that we're working in. It's called the menu Seen course. Let's go to our deck building screen and find the screen content. And, as a child of screen content, weaken just based this object great for cards. I think that I've basted it as a child off deck building screen instead of so I want to change that and make it a child off screen content. And after we have done this, we have several missing references because those references they were linked to those objects that are left in that other scenes, so we'll have to re establish them. The first couple of references are one character tabs and all character taps that are references to game objects. So let us find those. I'll go to tabs, and I think, by one character tabs we mean the tabs that air used for deck building. So I'll drag those onto here and Debs for collection Browsing are cold old character tabs. So in collection browsing Weekend select all the characters. We also want to have a reference to our keyword input field, and that's under our lower area. The script should be on the key word input field object itself, so I'll drag that onto this field. Then we have a reference to our cards that we don't have Togo and this script should be attached to our toggle. So I'll drag that onto this field, and the last one is the MENA filter. So I'll drag the MENA filter and re establish this reference. And now let's open our collection, grows a script and Monta develop and check out what it does. So I'll double click here, And now that this script is open, we can see all the public fields, most of them we have already checked. Right now, when we've set them up for this, you seen the new ones forests are these game objects spell menu, prefab and game object creature menu prefab. And we'll take a look at those card pre fabs in our next lecture, so we haven't seen them yet. All these references to the keyword input field and MENA filter we've just set them up in this lecture. We have a private reference to the character asset and that sense for the character that we're building a Deck four. We also have a private list off game objects created cards. So because the cards will be instance, she ated and ruin Sten. She ate these spell menu cards or creature menu cards. We have to keep track of these objects that we've made. So if you, for example, want to switch to the next page in your card collection, you want to destroy all the previous cards that you were showing through the player and you want to make the new ones. So for that purpose, we keep track of them and we add them into this created cards list. And then we've already talked about most off this stuff. We have all these properties, so properties with this model developed theme they show up in red color, and most of the properties should already be familiar for you. For example, this showing cards that player doesn't own. We take the value of this property from our total. So if you press on that total like show X zero cards or show cards that your player doesn't own, it sets the value of this property. Next we have the page index, and the page index is something that we introduced only in this lecture, and most of the code that works with it will be in this script. Then we have another property include all rarities. This property isn't used for our collection browsing. So just in case, if you want to make another filter that who include Onley, legendary cards or Onley rare cards, you can do that and hook it up to this. Include already teas property, and it will show Onley those cards that have a certain rarity that you want to show to your players. Then we have this next step include old characters and that is used on Lee for our old characters. Stab. So remember there is this special character tab that says all, and it just passes that Boolean. So if we have selected that tab, it'll let our collection browser know that we want to include the cards for old characters into our collection and the same thing with Verity. I don't think that we're filtering the cars vier air it, ian anyway. But if you want to add that filter, you can connect this to this rarity option, and you can show the guards off certain very T or you have an option off, including already t setting this true or false the same way we work with characters. Next, we have the field for our character assets. Private character, asset underscore asset. So when we switch between their tabs that symbolize either and neutral cards or the cards that belong to a certain character from the tab script, we set this property asset and then we show the cards that belong to this certain character . We have the same property for our keywords that we drove from the keyword input field. We have the property for the mana cost that we get from our men, a theater and all these properties. They're very similar by their structure. So first we set the value in some of the properties. We also reset our collection to the zeroth page. So is the first page that we can show to our players, and then we also call the Method Update page. Sometimes we don't reset the page index to zero, but we always call this method update page that who show the cards that correspond to all these filters we have This next bullion include token cards and an example off a token card . It might be a coin that you give to your players in the beginning off the game. You don't want them to add this card to their collection. Like while browsing the collection. They shouldn't be able to ed the coin into their deck. That's why you call this card a token, and you can make it so that the tokens are just not showing in our collection. And that's how it's done. So the default value off include token cards is always set to false. If you want to show token steer players for some reason, you can set it to truth
24. 408 – CollectionBrowser Script Part 2: And then we moved into the most interesting part off this script. We have these two situations when we want to let our player browse their collection. One is just for collection browsing, so they're not building a deck. They're just viewing, selecting cards, crafting them. Oh, they're just viewing, evaluating, selecting cars, crafting them and so on and so forth. And the second way is when they actually want to build a deck. So for these two cases, we have the following methods. The 1st 1 says show collection for browsing, and the next one says show collection for deck building. They are very similar. The first part off both of these methods serves for resetting our keyword input field, resetting our total script and resetting our men a filter so that they're all set to their default values. The keyword input field is just clear, the total it said two fools. So we're not showing players guards that they do not own, and the men a future is not filtering anything, so it's showing cards off all the mana costs. What's different is if we are showing collection for deck building. We had this private field that is gold character. And then we're setting the value off character to this argument of this method building for this character. So we're letting this collection bro's of script know that. Okay, we want to show the cards just for this character or the neutral cards. Then, in both of these methods, we have a cold to this universal method. Show cards that does all the work in our collection browser script will take a look at it in a couple of seconds, so this coal will actually display some cards for our characters so that they can see them . The pre fabs will be incense, she ated, and that grid in our scene will be filled with guards and these two next lines there included to select a default tab in our collection. For example, if we are collection browsing, we want to default to the neutral tab. And that's why we had this reference to neutral tab when collection, browsing. And if we are building a deck, we want to default to the class stab. So we want to show the cards that belong to a certain class first. If we scroll down, we have this method clear created cards. Created cards is that list that we used to keep track off all the card pre fabs that we instance she ate. So we it raid through this created cards list in a while loop and we check while it has elements in it. So while count is greater than zero, and if this list has elements, we always speak the first element, the one with the index off zero and we remove it from the list than we destroy the game object. So after calling this clear created cards, your collection browser will show absolutely no cards, and the grid will be 100% empty. The method update quantities on page. It serves a bit more advanced purpose. So let's say you are reading cards from your collection to your deck list into the deck that you're building. And there are several ways that you can use to manage numbers or quantities off cards that your player has. You can still maintain the same number in the collection. For example, if your player has two instances of a certain card, if you add the card into the deck, this number in the collection, like how many cards does he have? It can be unaffected, so it will always display the total amount off guards that your player has, or you can make it so that if the card is moved from the collection into the deck, it can be subtracted from the total amount that you're player has. So it's a bit of a more advanced feature and will not get too deep into this. But this method serves this purpose. When you add the card from the collection into your deck, you can update the quantity off this card in collection and make it so that you display different amount. We have the Method update page that we call in each of the properties, and it's very simple. If we look at the update page method, it just calls the method show cards, the one that does all the work. But it passes the values from all the properties that we have in our collection browser script. So these are just all the underlying values off each off our properties, showing cards that player doesn't own, etcetera, etcetera include token cards. We just pass all those values into this method, and then this private method that does all the work it takes in the arguments that are enough to set the values off all the properties that we have, and that's exactly what we're doing here. We're not setting them through the properties because that'll cause unnecessary updates. We're just setting the underlying values like showing guards Player doesn't own with an underscore and all the other values with an underscore. We are setting them equal to the arguments that we pass into this method. And then once we know all these different parameters, we have to figure out what kind of card assets to be want to show on this page. So in our case, I've made this collection work with imagination. So we have a certain page off guards displayed in front of us, and we can switch to the next page or to the previous page. So we want to get the page selection, which is another important method that returns us the list off guard assets. And once we know the list off guard s, it's based on that. We can creates all those pre fabs off our menu cards and risk in them make them look like those card assets that we have selected in our page selection will look at page selection in a couple of seconds. First, we have to clear the list off created cards, so we have to remove all the cards that we have displayed previously and replace them with new cards. We can also make a quick check, like if guards on this page. If our page selection is equal to zero, then we just returned from the method and we don't have to do anything. So we have made sure that the page is clear and then we don't have to. Instead, she ate any new cards so we can just return from the method. If this is not the case, so we get through this statement, then we enter this for loop, and we're its rating over our cards on this page array from zero to its count, we're creating a new game object, depending on the quality off our card. So if we have a creature than we instance, she ate the creature menu prefab, and we instantly said its position two slots with an index off I position. That's why we use not a four each loop, but this four loop so that we have an index and we can always place the card on the appropriate slot. Once the card is instance, she ated we set the parent for this card. So we parent all the cards, too. This transform, which is that objects in the scene that is called grid off guards. We don't have to forget to add this newly incense. She ate ID card into our created guards list. And then we have these two important steps. One of them. We get the one card manager on our menu card and we make it so that this card is re skinned and it looks like our cars in this page I card asset and the next step we do the same thing with our ad card to deck script that we haven't seen yet. Add card to Deck Script is the main script that will be attached to all the menu cards, and we have to set the card asset to let the strip know what kind of a card asset will be added to the deck. If we click on this card and we also call the Method update quantity to show the appropriate quantity off this card that our player has in their collection. If we scroll lower, we have these two methods and these two methods. They are buttoned handlers, so we'll have two buttons on the sides off our collection left and right next in previous. And when we press on those buttons, we have to select a new page, and we have to show the cards that are located on this page. So if we breast next we called the Method Page selection. We passed all the different parameters that are already set up for our collection. Except for the page index, we add one to the page index. So we want to find out what's on our next page, and we also check if there is nothing there. We don't want to let our players do that and switch to that empty page. So we're checking if the count off cards on that page is equal to zero. We just returned from this method, so if you reach last page, you see some cards and you want to press to that next page. It will not allow you to do that so we don't want the players to escape that last page that has a least some cards. And then, if we have at least some cards to show, we call the method show cards with the page index plus one as one of the arguments. And if we are pressing another button, the one that will let us show the previous page, we just have to check if our current page index is equal to zero. So we don't want to allow our players to go into negative page indexes. So the page index it cannot be minus one or minus two or something like that. If this is not the case, then we will just show the cards, whatever cards that are there for our players and finally, our method that is Cold Bay aged selection, the last method that we have to understand from this script. It takes a very similar set off arguments because we are accessing it from our show cards, so it takes all those values that are represented in our properties and these same values. They're also represented in our card collection as filters for our cars, and that seamlessly translates into this coal. So we're obtaining the cards from our collection that satisfy all the selected criteria we call card collection. Instance Get cards, which is our most general method in card collection for getting some cards. And we pass all those arguments into this method. And in this line we get all the cards that satisfy the criteria so we don't get the cards that are fit onto this page yet. So, for example, you can only fit 10 cards onto one page, and this guards to choose from it might return you 100 cards if they all satisfy the conditions that you pass into this method. So then, to get the page selection, we have to get into this next statement if cards to choose from. So if we got, for example, 100 guards and we want to show Onley 10 of them and all these next values, they have been selected just with some trial and error. So appropriate way of doing this is to check if we have enough cards to show on this page with this page index. So if we have enough guards to feel this baby, for example, it might be 1/3 page, so this check will let us know if we have something to show on the third page, then we'll select our cards in this manner will enter this four loop, and we have several conditions in this four loop. So it's not just one condition I will start from. I was an index off zero. And the conditions that will check will be if I is less than cards to shoes from count minus page index multiplied by slots length. And the second condition will be that I is less than slots length. So we don't want to return more cards that we can show on one page. And at the same time, we don't want to return more cards than we have in our cards to choose from a list and then we see return list. Add. We are adding the card with this index page index multiplied by slots length plus I. So, anyway, these are some values that have been selected by trial and error. I have included some explanation of them here in the comments, and right now we have reached the end off our collection, browse or script and, you know, in general how that works in the next lecture will sort out more visual stuff that we need to show our card collection to our players, like those card pre fabs, the prefab off a spell card and off a creature card that will use in the menus. And we still haven't made those buttons the left and right buttons that will let us switch between the pages in our collection. I would like to thank you for watching this course, and I will see you in the next lecture.
25. 409 – Pagination Buttons and Collection Card Prefabs: Hello, everyone, welcome back to the course in this lecture will do two things. First, we want to establish those left and right buttons that will let us switch pages in our collection. And the second thing will take a look at these guards the spell card menu and the Creature Card menu. You can find them in the assets Brief ABS Menu pre Fabs folder. I've just dragged them from there into our scene, but first, let's make those left and right buttons. In order to do that, I think we can just grab one off our tab buttons because essentially, they're not any different. So I can just I guess I can copy and I can paste it on top off our background. So until for the background, I'll right click and hit based for some reason, it doesn't want to baste it as a child off our background. So I had to manually re establish that, and then I should stretch this button, make it fit to this side off our background. I'll apply the anchoring percent to this button. I don't think that it looks too pretty, but you know we need a practical solution and later, we can make some adjustments to it. So this button will sit here on the side. We can turn off the frame. I guess we don't need it. And we can make the image on the button a bit darker to let us know that we can switch pages where we can just make it transparent. That's what I did in the other scene, So I have just made this image transparent. It'll still react to clicks, but it will not be visible for our players and the text. We can just sable that I guess that's OK for our button, except we have the character filter tab script here that we don't need. So I should just remove that. And we should establish the connection with our collection browsing script that is attached to this grid four cards component. So I'll drag that onto this on click event, and here I'll select collection browser previous which sense for switching to the previous page. Then I can just control D and copy this button. I can drag it onto here to the other side off our background, and I can anchor it to an appropriate spot where it currently is, and then for this button, we should just re select a different method to be called from collection browser here. We'd like to call the method next, and I have Olson named these tabs appropriately. The 1st 1 is called the previous button, and the 2nd 1 is called the Next Button. Now let's take a quick look at the cards to some extent thes cards there even simpler than the ones that we were dealing with before in the PAC opening. We only care about one side of these cards, so we'll never show the card back. We'll never rotate them so we don't need that better card rotation component, and therefore they're very simple. They only have the books collider. They have the one card manager component that lets us re skin the card and show different text images. It century on the card, and the only new component that these cards have is this ad card to deck script. And another difference between these cards from our collection and the cards that we get from PACs is this little compartment in the lower area of this card that shows the quantity of this card that our player has in the collection. It is quite simple. It is very similar to our buttons. It is not clickable, though, so it doesn't have the button script. And we have a reference to this text quantity taxed in our ad card to deck script. So let's open at card to deck and take a look at it in Mona Develop. So now that ad card to deck is open, we have just one public field, the quantity text. Then we have several private feuds float initial scale, scale factor. And we need those because we want to make it so that when the player enters with the cursor and hovers on top of the card, it gets enlarged by 1.1. In this case, we have private field card asset card asset in awake. We just memorize our initial scale, and we said it equal to transform local scale X because we'll use do between to change the scale. We don't need to save all three values of scale. We'll scale. It's uniformly. That's why we're saving just one coordinated in this case, the X coordinate. We have the public method sat guard asset. That's very simple. Just a one line method that sets the value off our private guard SS variable if we scroll a bit lower, There are several methods that handle this zooming behavior. So on most enter and on most exit, we do something with our scale. We say transform do scale. And we change scale in this case back to initial scale in 0.5 seconds. And in this case, we're enlarging our card, making it larger by this scale factor. Also in 0.5 seconds. When the press on this card, this method on mows down is cold and we're getting the card asset from our one card manager . I've included this check. If acid equals to know, then return. I am not sure if we need this because this situation, when the guard asset that we are trying to add into our collection is no, it just shouldn't happen so. But it just for the sake of having some extra precautions, will take this extra step and check. If it's not know, then we can access our collection and check if the quantity off this card in our collection essentially is less than number off this card index. So If we can add more cards into our deck, then we can say deck building screen instance Buder script ad card. And then we can update the quantity off this card on the page else. It's an appropriate place to display some sort of a message for your player that you don't have enough guards or you have reached the card limit. You can only have two off this card in a deck or is just something similar. If we scroll a bit lower, there's this update and in update, we're checking for right clicks. So if we have clicked anywhere with the right button, it's not necessarily checking. If we have clicked on this card, then we're calling the Method on right click that Will Ray cast figure out if we have hit this guard, and if we have right clicked over this card, we want to show the crafting screen. So far, we haven't done the crafting screen. I think that it will be covered in our next section, so we want to allow our players to right click on cards and craft them or disenchanted them . And that is also included into this package that we are exploring in the scores. And next we have this method update quantity. In general, the quantity should be equal to the quantity off this card in our deck. So that's what we're getting here. And then we are performing several checks like a sad we can display either just the quantity off this card that we have in our collection, or depending on the amount of guards that we have already added into our deck, we can display a reduced quantity like this card has traveled from the collection and into our deck. So here we are, checking if we are in deck building mode first. And then there's also this Boolean show, reduced quantities in deck building. It's in our deck building screen. And if you set this check mark to true in the Inspector than your quantity will be reduced by the number of cards that you have already added into your deck. And then you said the quantity taxed on this card to X. That's just a symbol that we used to represent quantity and quantity dot to string. So in this lecture we have added those two extra buttons that will help us switch the pages in the pagination in our collection, and we have also covered the card. Pre fabs that will use during collection, browsing and deck building in the next couple of lectures will push the words, getting an actual result entering our collection and getting to use the pagination, getting to switch pages in our collection, seeing some cards and finally getting some visual results. So thanks a lot for watching and looking forward to seeing you in the next lectures.
26. 410 – Deck Building Screen: Hello, everyone, and welcome back to the course. So in this lecture and in the next couple of lectures were going to push to finally get some visual result in our deck building slash collection browsing screen, our deck building screen. It shoud also have a script that is a singleton, and it controls this screen content object. So it either shows the screen to our players or it had hide it from our players so that they don't see and these scripts that manage our screens. They also take care off some other tasks, like storing some references for us and taking care that when we open the screen, everything shows correctly. So this deck building screen, I'll select the object. It doesn't have any scripts, and we'll have to attach the deck building screen script to it. It has a lot off different references. There are some of these references that point to the objects that we do not have yet, but some of these references we can already established here. So the 1st 1 is this screen content. Then these two next references ready decks list and cards in deck list. I've planned to include this into our next section and talk more in depth about how we select the deck that we want to edit. Create in you deck how we add the cards into our deck list or remove them. So these two next references they will point us to these objects that will be located on the right side, relative to our collection Builder script is something that will be attached to our cards in deck. List the script that will be responsible for adding or removing cards into our deck from our deck. We have a reference to a script list off ready made decks. We don't have it yet. We have a reference to our collection browser script, and we have that. So our collection browser script is located on our grid four cards. Object. Let's establish this connection and we have a reference to our tabs script. The tab script is located on our tabs. Parents object. This next 1,000,000,000 show reduced quantities in collection, so it's just a matter off personal preference. It'll work either way, and it will show the quantities a bit differently when you're editing a deck. So first I think Let's take a look at the script deck building screen to figure out how it works and why does it need all those references If we open it in Monte develop, we have all the public feels that we have just seen. We have a public static field deck building screen instance that makes the script s singleton in awake we set instance, equals this and we say Hide screen, just like we do for all the other screen manager scripts. And then in this script, just like for our collection browser. We have two methods because this screen can be shown into different situations. The 1st 1 is collection browsing. So if you want to display the screen for collection browsing, we want to set the screen content to be active, to be visible. Then we want to make sure that will show the correct game object on the right, and we have to either show the ready decks list if we are selecting the deck or we have to show cards in deck list if we are building a deck. So when we are collection browsing, we want to show the list off our ready made decks. So we said this active true and we hide the list off cards in deck because we're currently not building a deck, we excess our builder script, and we are telling it that we're not in deck building mode. So if you press on cards in our collection during this mode, they will not be added to our deck. We access the script list off ready made decks script, and we want to update the list to display the correct list in our Ready decks list. Object both of these objects ready decks list and cards in deck list there quite similar, and they're made with unities built in, scroll wrecked or a scroll list. We'll definitely take a closer look at them in our next lectures. Next, we want to make sure that we are showing the correct tabs. So in this situation who want to show the old character tabs and we don't want to show the one character tabs, so we want to be able to switch between the cards that belong to anyone off our characters . Then we say canvas for sub date canvases. I don't remember the exact reason for doing this, but sometimes it is required to update your canvases to display the most recent information . So we do that and finally we excess our collection, browse or script that has similar methods and we say show collection for browsing. And in this next method shows screen for deck building. We do the opposite, so we want to still show the screen content. We want to show the other game object that it's gold cards in deck list here on the right side off our screen, and we want to show a different set off tabs. We also say Cannabis Force Update canvases. Our deck building screen also contains a method that is called Build a Deck four who cover this process off, creating a deck in one off our next sections. But just to describe this in general, when your players will decide to build a new deck, they will be presented with a screen that contains a layout off all the character assets off all the characters that exists in your game. When they select one of the characters and they, then they breasts a certain button. It will call this method build a deck four. It will pass that character asset into our deck builder, so it'll let our collection browser script. Know that we want to show collection for deck building for this particular character, and we want to show the cards on Lee for this particular character and hiding the screen. That's pretty simple. We just say Screen content said Active. We pass in false, so we hide the screen content. And it's also convenient to clear the list off created cards in our collection browser script. So we just destroy all the instant she ated pre fabs and created cards that we were showing to our player. So now that we know how this script works, we can already guess that it will not work without setting up all these objects, like ready decks, list cards in deck list and so on and so forth. Even though we are not discussing how those scripts and those objects work in this section there still required for this script to work even just for the basic stuff like showing us the collection off cards, I promise that will review these objects in great detail in our next lectures. Right now, we just need them for this script toe work. So my offer is let's go to the pre mate seen and just copy them from there as a temporary solution. So let's go to our project assets. The pre made seen is just called menu scene. We can save the current scene that we're working in, and we have to copy those two objects under deck building screen content. Maybe we'll have to copy even Mawr different objects from the scene? I don't know for sure yet, but we definitely have to grab this one existing decks canvas and this one the car at least canvas. I don't know if that works. If we grab two objects so I can just select copy here, go to our many seen course, the one that we're working in. And I will go under a deck building screen screen content. I will, right click and based those two objects. I think I should parent them to screen content, and now we can't establish some more references, even though we don't know in detail how these objects are made. Yet we have to fill in these references, so the 1st 1 is ready decks least this is our existing deck canvas, and we just need a reference to a game object here, then we need a reference to our cards in deck lists, and that's our cards list canvas. Then we need a reference to our builder script, and that should be somewhere on our cards. Least canvas. You see here there's our script that is called the deck Builder that will be responsible for putting cards from our collection into our deck. So let's go to reject building screen established that reference. Here's our deck builder and the last one is list off ready made decks. And I think that that script is located on our existing decks canvas object. So in a similar manner, I will just establish this reference. And now that we have configured our deck building screen, I am not 100% sure if this will work. But let's try this so we can already go and deactivate our screen content than the only thing that we want to see in the game is our canvas. And I think that we have not connected the collection button to our deck building screen yet. So let us select this collection button and let's press on this little plus sign, I will drag our deck building screen onto this collection button, and we want to call the Method Deck building screen shows screen for collection browsing. So when we just pressed on this collection button, we know for sure that we will not instantly build some Deck will have to make some extra steps for that. So we just want to show the collection that weaken, browse and see all those cards that are present in our project. So I will select show screen for collection browsing to be cold when we press this button. And another thing that we don't have to forget about regarding this collection bottom. So when we press on this button, another thing that we want to achieve is we want to hide our menu. I don't remember how we did that for our shop button. Let's check that out. So we have also deactivated the game object that is called Panel. That is apparent off our menu background, so we'll do the same thing for our collection button. I will go and drag this panel onto our own click button handler and we'll call a method game object set active and will deactivate this object. So now that this is set up. Let's just try and run the game. Let's see how that works. If we have to make some more fixes, well, that's fine. But it's most likely that we'll get a least some results from it. So if I launched the game, I will go in press on this collection button. And even though we have made all the correct steps for deactivating this men, you can see that we have some sort of an error in our council here, even a set off errors. And so we'll have to spend some extra time in our next lecture to figure out all these errors and to finally make our collection of guards usable. In this scene. I'd like to thank you for watching the scores, and I'm looking forward to seeing you in the next lecture.
27. 411 – Fixes for Deck Building Screen: Hello, everyone. And welcome back to the course. In the previous lecture, we stopped. Exactly. At this point we have configured our deck building screen, and we have established all the references. We were able to do this faster because we had a fully configured menu seen that already works. So we have copied these objects that are on the right. One of them is the least off decks that you have. Another one is the least of cards that you have in your deck. We just copied them from that pre configured seen into our current seem to establish thes references. We launched the game and we still get some errors, even though this main menu should be hidden when we press on our collection button. I guess because we have all these errors, it just hangs. So we'll have to re sold all these errors one by one. And we can notice that all these errors that we have here they all happen in our ad card to deck script in the method that is code on mouse enter. So let's double click on this error, go to our ed car to deck script and try to figure out what's wrong here. So here it tries to reference a script that it's called the crafting screen, and this screen will just be a part off our deck building screen. It is also a singleton, so it will have this instance and in awake it'll say instance equals to this. But right now, because we haven't introduced this object into our seen yet, sir, when we say if crafting screen dot instance, it just streets this as no so it cannot find the crafting screen in the scene and saying no , that visible doesn't make any sense. So it gives us this error, and it turns out that one of the errors is fixed if we go into our pre configures scene and bring the crafting screen from there and will take a much closer look at the crafting screen and our deck list objects in our next section. So no need to worry about that and let's go and check out the second error that we get the second error. We get it from this other script list off decks in collection dot update list Line 24. So let's go into this script and here we also have another script, another Singleton, that we have not added into our seen yet. The script is called Dex Storage, and it is an interesting script that will let us save the breaking figure decks that are made by our players into player preps. And I actually think that this script is worth e for us to take a look at it in this lecture. But first, let's go into our pre configured seen and try to copy all those objects from there. The 1st 1 is Dex Storage, and the 2nd 1 is that crafting screen. So let's exit Mona develop. I will close this error window and exit the game. I'll go into our many seen Let's save this scene. I can instantly spot this object that it's cold decks storage, and it has just this next storage script that doesn't have any visible public fields. So I can just press copy here, go back into our many seen course and just based it right into our scene. We want this decks storage object to be located in the root off our hierarchy, and let's go back into the man you seen save this one, and under our deck building screen. Our job is to spot the object that is called crafting screen. So actually, there it is, and we want to copy this whole object and bring it into our other seen. So let's right click Press copy here, go into our menu. Seen course. Find our deck building screen screen content, Select one of the objects and hit based. Now that this is done, at least those errors that we were getting in the end off our next lecture should be resolved. So let's launch the game again and try how that goes right now. Now, if you press collection, it is a minor success. We get through to our collection browsing screen, but we also have one error. Let's check out if our pagination buttons work. So if we press on these pagination buttons, they actually switch the pages. We can press this show X zero cards, and it turns out that it doesn't add that much because they opened a lot of backs and they're all recorded in player preps, and I have a lot of these cards in my collection. We can switch this to old tab, and it'll include the cards that belong to all the different characters that I have in my project, and I have just two. So we have these green cards, the blue cards and thes beige cards. They're just neutral cards. I think the other filters should also work. Like we can filter the cards by Mana, select only the three man accost cards, or we can search our collection by some keyword. I don't want to spend much time fiddling with our guard collection Right now. I want to figure out what that error waas so it points us to that new script that we have just copied into our scene. That is, Cold Decks storage. And we wanted to check out how that deck storage script works in this lecture anyway, so I'll just double click on the error, and we'll try to figure out why that gives us an error. So in this script, the line that causes an error is this line line number 86. It says decks found, add new deck info and so on and so forth. But it also tries to access this character assets by name. That is also Singleton, and it is a very simple script. It just contains the character assets that we have in our project, and we can access them by passing their name like the name of the file that we see in the Assets Folder. Actually, let's just take a quick look at this character essence by name. I'll go control C based it into here. So character assets by name. It looks like this. We have a public static field character essence by name. Instance. It is also Singleton. We have a private array character, asset array, old character assets. We have a dictionary that stores all the character assets by their names. So we have string keys and character asset values, and this script is very similar to our card collection. In awake, we're saying instance equals to this. We get all the character assets in our project by saying Resource is load old, off type, character asset, and we pass an empty string into these parentheses, so this line will populate our old character assets array with all the character assets that it confined in our project. Inside the resource is folders all over the project. Then we its rate through the story, and we say for each character assets. See a in old character assets if our dictionary doesn't contain the key with the name off this asset, we add this asset into our dictionary by saying Add the first argument is the name that is the key in the dictionary. And the second argument is the character asset that is the value in our dictionary. And we have this public method that we tried to use in our decks storage script. It is cold. Get character by name and this method tries to excess our dictionary. We're checking. If our dictionary contains the key that is equal to name, then we return the value that is stored in the dictionary under this key else were just returning and no. So our dictionary doesn't have this character asset. We can just return. No. And then the reason why we got this error in our decks storage script is quite similar to our previous errors. We just don't have an object that holds this script character assets by name in our new seen. So to save us some time, I can just copy this name. I can go back to unity, exit the game, I can create a new object so I can just go and create an empty object in hierarchy based this name, character essence by name. And I can manually add this script to our newly created object so I can search for character SS by name and attached. This stripped. It doesn't have any public fields, so we won't have to set anything up here and just having it in our hair key in our seen is enough for everything to work and for other scripts to be able to find this script because it's a singleton. Now that we have done all these fixes, the next lecture will be dedicated to understanding our decks, storage script and how it functions. So thank you for watching and I will see you in the next lecture.
28. 412 – DecksStorage Script: Hello, everyone. And thanks for watching the scores were finally getting to some truly interesting stuff in this lecture will take a look at the script that it's Codex storage and on top in the same file we have. This helper class that is called deck info and deck info is exactly what it says. It's all the information that we need to describe one deck in our project and some helper methods that will help us figure out if this deck is complete and how many cards off a certain type we have in this deck. So the deck will be described by these three like pieces off information. First, we have our deck name, so we want to let people name their decks in our project. The second thing that we need to know about our deck is the character asset that we have built this deck four because it'll affect the hero power and the cards that players can use in this deck. So we have to store that somehow. And, of course, the deck should also have the least off card assets that are featured in this deck. So the constructor for this class deck info is meant to initialize all these fields and you can see here that this list off guards is initialized in this interesting manner. We seen you list guard Asset, and we pass cards as an argument into our least constructor. So this will actually create a copy off the list. So if we make any changes to this cards with capital Letter C, this old list cards with the lower letter C that was passed into this constructor, it will remain unaffected. Our method that checks if our deck is complete, it looks like this. We're just checking if the amount off cards in our deck is equal to and the max amount off cards that is allowed for our decks is stored in our builder script. Amount off cards in deck. So we check if this is the case. And if it's true, it means that our deck is complete. And we also have this short method for figuring out how many cards off this card acid do we have in our deck. And it'll help us show the quantities in our collection and in our deck list, as you will see later. So first we initialize the integer value count, with the value of zero very iterated through all the cards in our cards list. So all the cards in our deck, and whenever we find that this card asset that we are it rating through is equal to the card asset that we pass as an argument into this method, we just add 12 hour counter variable. And then when we passed through all the cards in the deck, we just returned the count so it might be zero, or it might be something greater, like one or two, and then let's scroll a bit lower and take a look at our decks storage script. Like a lot of other scripts in our project, it's a singleton. It has this line, and it has instance, equals to this. In awake, we have a public list off deck info, old decks that we can get and set. And mostly we will get this list So this list will be set on Lee. Once when we launched the game, the decks will be loaded, and then they will be valuable for editing and for playing with these decks, and they will be saved again when we exit the game, and we make sure that we load the decks from player preps Onley once when we launched the game by having this Boolean already loaded decks. So in this method void start. We check if we haven't loaded our decks already. Then we call the method lewd decks from player preps, and we also see already loaded Dex equals true. So even if we deactivate this game object and reactivated, if we enter the start method again, if this already loaded decks is set to true, we will not load the decks again, which is convenient. And next we have two methods. One of them will load all the decks from player crafts, and our loading method works like this on top of the method we make in you list. That is Go Dex found, and it is a list off deck info. And then we iterated from 0 to 8 that returns us nine decks in total because we have made a convention that in this project will let our players save only nine decks, and we also have a naming convention related to the keys that we use in player preps. So the key that who use for the whole deck list. It's cold deck lyski, and it looks like this. It might be deck zero, deck one and all the way to deck eight. So we're saying Deck Plus I, which is an integer from 0 to 8 adult to string our character keys. They will look similar, but they will say Deck Hero from 0 to 8 and our deck name Key will say deck name from 0 to 8 and then this next line is interesting here. We don't use the default unities player preps, but we use a package that I found in Unity sort of Vicky PDO. You can find it on the Internet. It is free to use, and it's cold. Player preps X. So, essentially, someone wrote a library that allows you to write a raise off in its rays off strings into player preps and get these rays back from player preps. So he was a string array deck as card names, and we get the array from player preface X. The syntax is similar to working with. Unit is built in player preps. We say get string array and we pass in our deck list key. Then we have some debug Lok statements just to let us know what's happening in the background. And what kind of information are we getting from player preps? And then we perform this check if we have found some cards in this deck. So if we have found some cards in the deck that has the deck lyski deck plus this I So, for example, Deck zero if we have found some cards here and our player crafts, and these are the simple player preps, the ones that are built into unity If these Blair preps have key character key, if they have a key deck name key, which means that we have found a complete deck Surrey say string character name and we get this value from player crafts, we get the deck name from player, perhaps by passing in the respective keys, and then we make at least off card assets that is called deck List. It is a new list off guard asset. We iterated through our deck as card names array that we got from player preps X and player . Preps X is just a script that sits somewhere in your project so you can search for player breaths X, or just find it on the Internet and figure out how that works in the background. It still uses the ordinary unities player preps, but it is automated so that you don't have to think about it, and you can just write and Ray into this player Preps player Preface X and get the array back. So we're iterating over this array and for each name that we find in this array, we say deck list, and we are adding the card from our card collection that has this name. So by the end of this, for each loop, our deck list should be filled with guard assets in this case and we can see Dex phoned. So we're referring to this list that we have created on top of this method, and we are adding in you deck info, which is this new type of objects that we can create that is also included into this script . So we're essentially creating a new deck with this deck list, a deck name that we've got from player preps and the character acid by name that we get from this script that we have seen in our previous lecture and then, in the very end off this method after the loop, we say Old X equals two decks phoned and a similar method that is gold save decks into player preps. It looks like this, we reiterate from 0 to 8, because I is less than nine, and we just want to make sure that we clear the player breaths from all the existing decks so we can just see if Player Braff's has key character key. We just delete the character key. And by doing this, we also make sure that we will not find any of these old decks in our method Low Dex from player preps. Because here we check if Blair breaths has key character key, and it has the deck name key. So we Onley treated as a complete deck if it has all those keys. So if we remove just one of them, like either the character key or the deck name Key will no longer find it and loaded from player preps, and then we its rate over all the decks that are defined in our old decks list and this method, it'll always be called when we quit the app so you can see here void on application. Quit that is, apart off money behavior. And here we say, save decks into player breath. So this is definitely getting cold when we are quitting the game and when the old decks are pretty well defined. So we have already edited something, added some new decks, and we want to store them and save them. So we make the keys by the same rule. We just say Deck plus I, which is our index. Then we convert the list off our card assets back into the least off our card names. We can also make it into an array from a list by saying card names Ray equals card names list dot to Ray and then setting all these values into player preps is just mother off these three lines, we say Player preps, X set string array by our deck list. Kiwi past this card names Ray and in a similar manner. We passed the name off this deck and the character that this stack belongs to now in Blair breaths. We cannot store any complicated types so we can only store like integers. Float variables, weaken store strings like we do here, but we are not allowed to store card assets or character assets. That's why we have to go through this process off, converting everything to strengths and obtaining everything back from strings. And now if we go back to unity and launch the game again, everything should work as expected. So we should enter our collection. Now you can see that we no longer get any errors in our council. The council is completely free of these red error logs that we might have gotten if we had any errors and we can navigate our collection, began apply some custom filters to our collection. And because we have made copies off some objects that we grabbed from the other scene, we can do much more. For example, we can right click and enter this crafting screen, but we'll figure out how all these other elements work in detail in our next section. I would like to thank you for watching, and I will see you in the next section of this course
29. 501 – Introduction to Section 5: Hello, everyone, and welcome back to the course. So in this section we will talk about all the remaining elements that we need to assemble in order to make our many seen for re functional. And compared to this scene, the one that is called the menu seen that I have prepared beforehand, let's launch the game and check out which menu items have recovered already and which ones off the menu items that are present in this scene we're yet to make in our other scene. So launching the game, our previous section was mostly dedicated to this menu item that it's cold collection. If we enter our collection just like in this scene in our other scene, we are also able to browse the collection and use the filters so we can consider that done this little trick with arrows, you can check out how it's done in this scene. I don't want to spend too much time on this. So the first thing that we haven't covered yet, but we have copied it into our course seen already is this. If I right click on one of the guards, it'll show us this crafting screen and the crafting screen lets us disenchanted cards or craft them for dust that is displayed on this hot. And the next thing is, we have two different lists here on the right side first list, the one that we see right now is the decks list, and this list will hold the Aikens that represent the decks that our players have pre built . So now it contains this new deck button that is a unique element that will be displayed on Lee if we don't have enough decks. So, for example, if we already had nine decks, which we have just selected as a Mex amount of decks for our game, then we wouldn't be able to see this new deck button. Then if we go further and we want to actually create a deck when we press this new deck button, we get to this new screen that we haven't seen yet, and we haven't discussed it yet. That says, choose your hero. Since I have created just to heroes for this game, we can select just one of these, and these two are actually similar, so we select one of the heroes and repress on this build a deck button. Let's do that. So now we're building a deck for this Elf class so we can only use either elf or neutral cards. Let's add a couple of cards into our deck and talk about this other list that we'll have to discuss and figure out how it's made. And it's actually pretty similar to that Dex list. So all the principles and everything, it's 100% similar. Let's add a couple of cards. So it's at this one, this one and this one. Let's go and add a couple of unusual cards and let's go back and add a couple of elf cards right now. The limit for the max amount of cards in deck. It's set to a pretty low amount. It's only 10 cards, so this deck is already full and this frame around our cards in deck list. It shows that the deck is already done, and we can already play the game with this deck. So now let's press done here and now, as we go back into our collection, you can see that now We also have this item in our decks list, which is our deck. If we press on this item we can enter back into our deck editing mode we can give a random name to our deck has done again. Now this deck will have that random name that we have just given. Another thing that is very important. And it actually appears the first in the list off our many items is our play menu items. So if we go back once we have built ADAC and we press play, we see a very similar screen to that character selection screen that we So when we were just trying to build a deck and this screen, it contains only the decks that we currently have, so we can select one of them, and currently we have only this one, and now we can hit play. So our program for this section consists off tourists that are pretty similar. One of them holds the decks and other one colds. The cards in our deck. We have two screens. There are also pretty similar. One of them holds the ready decks, and I'm talking about this list, and another one holds the poor traits off our characters that we can select before building a deck. And another thing that we have to cover is our crafting screen. So once we click on one of the cards with our right mouse button, we get to this screen that allows us to craft or disenchanted cards. And actually, there's another interesting thing that we have to cover. If we go back to our play menu items, select one of the decks that we have. We can press on this play button, and it should take us to that other scene where the card game battle happens. So we will also discuss this transition and how we can transmit the info about the deck that we have selected into that other scene. So thanks for watching and looking forward to seeing you in the next lectures of this course.
30. 502 – Crafting Screen: Hello, everyone, and welcome back to the course. Our objective for this lecture is to figure out how the crafting screen works, the screen that allows us to craft cards and add them to our collection or disenchanted cards and get this secondary currency that is gold dust or spare parts. I have opened our menu seen course, because in the previous section we have copied our crafting screen from the scene that was ready into the scene that we're working in. I have deactivated the canvas game object, the one that was holding our main menu so that it doesn't obscure the view and went into our deck building screen under screen content. We have this object that it's cold crafting screen, and it's structured very similarly to our other screens. So it has this object you can call it screen content, or I just called it everything. So under crafting screen, we have a reference to all the content of the screen that we can activate or deactivate, depending on our current situation in the game. So under everything, we have several objects. The 1st 1 is the background, and I try to make the background with a striped render, and that would be perfectly fine. But then I discovered that we can still click through the sprites render and remember that when we are in our crafting mode here in the background will most likely have agreed off other cards. So if I click here, for example, and clicked a couple of times, it would be a car there or could right click and do something to this guard. So to avoid making clicks through the background, I've added another canvas that's actually huge. I could have gone much smaller in size for this cannabis, and this canvas has one single You I object that is called the Panel, and I've converted this panel into the bottom. So when we press in this huge bottom, there is just behind everything that we show on our crafting screen. We will hide the crafting screen. Sued calls, the method crafting screens, so it refers to this object and calls the method hide crafting screen that who look at in a couple of seconds. Next child off our screen content object is cold cards, parent. So because we have two different cards in the game that look differently, our creature cards and spell cards. They have differently shaped frames for the main picture on the card. So we have our creature guards and our spell cards, and they are located in the same spot. When we opened, the crafting screen will figure out whether it is a creature or a spell card. And then we'll show the card template that we need and these spell cards and creature cards . Here they are very simple. We don't need to do anything with them. There's no need to rotate them. So we don't have our component that it's go better card rotation. And the only thing that we want to do with them is re skin them and show the information about the current card that we're trying to craft or dis enchant. So we have this one card manager component on both our spell card and creature card descend chant, and the last component is called Canvas Craft isn't chant, and it is this canvas in the lower part off our crafting screen. It has the text you have, like several instances of this cards several copies, and it will let you know the actual amount that you have in your collection. And then we have this object. Botanists parent. We have two buttons to organize them easier. I use the horizontal layout group, and the two buttons that we have are disenchanted button and craft button. And they both refer to the methods in our crafty street. The craft, Bolton says. Crafting screen dot craft, car and card and the disenchanted button says crafting screen Decent Chand Current card. So crafty screen It doesn't have that many dependencies on other scripts, and all the functionality is enclosed in this script crafting screen. So let's open it in Wana. Develop and check out how it works. So now that they're crafting, screen script is open right on top of the script. We have this help or class public class rarity trading cost, and the reason for having this glass is to establish sort of a currency exchange rates so you should be able to craft cards for a much higher value than you are able to disenchanted the same card. And to input all this information into our crafting screen, we have this ray public rarity. Trading costs, trading costs, Ray, let's jump back to unity and take a quick look at how this is organized in unity. So here's our trading costs array. We can expand it, and here you can see that basic cards we cannot craft. Um, we cannot isn't Chantome and it's prohibited by other code in this application, So the costs are zero and zero. Our common cards, the ones that have common rarity, were able to cross them for 100 we are able to decent chant them for 50 dust, and it goes on and for legendary is we have the crafting cause off 1600 we can do isn't on them for 800. You can play with these values and big something that is appropriate for your game. So back to our main script crafting screen. On top of the script, we have a variable public study crafting screen instance, and we have it here because this script is also Singleton. Just like a lot of other scripts that you have seen in the course, we have a reference to its content, so it's similar to all the other screen managers that can activate or deactivate all the visual content off the screen. We have references to those game objects creature card and spell card. And these are not pre fabs this time. These objects, they just sit there permanently. So we just figure out if we need the creature card. We activate that, and we hide the spell card. If we need this spell card, we do the opposite. We hide the creature card and show the spell card with the appropriate information. We have these references to text components, and I think these craft text and disenchanted text their texts on our craft and disenchanted buttons that show the actual amounts off dust that you will spend or that you will get from crafting or dis enchanting cards. And this next text component is quantity. Text is that one that tells you you own certain quantity off this card. You have already seen this rarity. Trading costs, array in unity, and it holds that currency exchange rate. How much can you get or how much do you have to spend to craft one card? We have a property that is called public buoy invisible, and it only has a get access er. Essentially, our screen is visible if the content is active in hierarchy, so we can actually see the content off this street, then we can consider it visible. We have a private reference current card, So whenever we open our screen, we save the card that we're currently viewing as current card. So when we say disenchanted current guard or craft current card, we have access to this variable, and we know which one of the cards do we have to add to our collection or subtract from our collection and give an equivalent amount of dust and, for our convenience, restore the trading costs off our cars. In this dictionary, the dictionary has keys off type rarity options, which is our Inam that defines rarity so basic, legendary, common and so on. And verity trading costs is that type that we have defined on top of this class. I think it is convenient because we cannot edit dictionaries in the Unity editor in the Inspector. That's why I use the streak very often. So first I define helper class. I create an array off variables off this type, and then I organize them in a dictionary. So here, in awake, you say instance equals to this because this glass is a singleton. But we also see for each rarity. Trading costs cost in trading costs array. So we loop through the array and we add the data in this beret into our dictionary. So we excess our costs dot rarity, and we write the variable off costs into the dictionary with this rarity key. Next, we have this method show crafting screen, and it takes in an argument of type card asset. It makes sense because we always show this screen to display a certain card so we can adjust. Show it like abstractly with any of the cards. We only mean to show it if we want to show a certain card to our players. So first we initialize our private variable current card with the card to show that is an argument off this method. And then we'd like to store a reference to that card object that we use on the screen. So if our current card don't type of card is a creature, then we want to show the creature cart and we want to activate it. We want to deactivate the spell card, so it's exactly what I told you about before and then else if it is a spell card. We only have creatures and spell cards. So if you introduce Mawr card types into your project, this if else statement, will be longer. But in our case, it's just if it is a creature, we do this. If it is a spell card than we do something else, we activate the spell card and we hide the creature card. Next, we have to take care off the way our card looks. So we have to get the components of Type one card manager on the card. We're setting the card asset to our card to show what you divorce, said current card. Because we have copied our value off card to show into this variable current card. And then we say manager redcard from acid. So after these three lines, our card, it might be a creature guard or a spell card. It already looks exactly like the car that we have picked in our collection. Next, we want to change the texts on our buttons. So we say craft taxed the text and then you can combine strings in one text. So here is a craft discard four and we excess our trading coasts Dictionary, so it is convenient because we can just pass this cards rarity and get the actual crafting cost that we need So we can craft this card for this amount of dust from our dictionary or weaken, disenchanted for this other amount off dust that we also get from our dictionary. We have covered this a while ago, but we also access our shop manager. Instance dust hard and we said it actives you True. So when you are making these operations with grafting or dissent chanting cards, you want to see the amount of dust that you have whether you have enough off dust to craft this card or not. And then we can also call this method update quantity off current cart. That is the next method in our crafting screen script and finally on Lee. After all, these manipulations are done, so the screen shows all the actual data. For this card. We activate the content off the screen, so we show it visually to our players. The method update, quantity off car and card tries to access our card collection, so we access card collection instance quantity of each card and we pass our current card as an index into this quantity of each card dictionary. And then we say quantity text equals. You have this amount that we got from our card collection and finally, the last thing that we want to do in this method. If we are dis enchanting cards and we have an instance off the same card in the background behind our crafting screen, we also want to update the quantities on the page. So if you're in the crafting screen and you're hitting about either, it isn't chant. The quantity of this guard on the page should be updated. That's why we're calling this method deck building stream. Instance. Collection browser script update page. Our method hide crafting screen is much shorter, so we have to deactivate the screen content, and we have to deactivate our dust hard. We have a reference to it under our shop manager object, and then we have two methods that are used as button handlers on our screen. So the 1st 1 is gold craft garland card and were only allowed to craft guards that are not basic. So the basic cards it doesn't make any sense to craft them because you have a certain set quantity, the max amount that you can use in the deck. And you don't want to let people do this, either craft them or disenchanted them to get certain advantage in the game. So you say, if shop manager instance dust. So we check if we have sufficient amount of dust to craft this guard and we get the costs off this card from our trading costs dictionary. Then we subtract the cost of this card from our dictionary and we add one to the quantity off this guard in our card collection. And of course, we update quantity off current card both on the crafting screen and in the background. If we are able to see this guard behind the crafting screen else, I have not filled anything into here. But you can show some sort of a message like you don't have enough dust to craft this guard or something similar, and the method disenchanted current card. It looks a bit more complex. We are only allowed to dissent. Chant the card. If this card isn't basic, then we enter this if statement here, we also have to check if the quantity of this card in our collection is greater than zero, so we don't want to let our players isn't chant cards that they don't have, so only if they haven't least one instance of this card. Then we allow to descend chant this card, and we instantly subtract one from the quantity off this guard in our players collection, we give our players a certain amount of dust. So we say shop manager instance, dust plus equals, and we get the necessary amount from our trading costs. We update quantity off current card on the page and the reason why this method is more complex. Because when we disenchanted cards, we also want to check if this card is present in one of the pre configured decks. And it matters because if the deck was full and it contained this card, we could have entered the play mode with this deck. If you didn't chant this card, and the quantity of this card is not enough for this deck to be full again, then, of course, we have to notify our players about this, and we shouldn't allow them to enter play mode. So we say for each deck info, info in decks, storage instance, old decks and we have taken Look at this class in our previous section and for each deck, we say, while info number of this card in deck is greater than number of discard in collection. So if we don't have enough guards in collection to put this many cards into this deck, then we say info cards remove, and we remove this card that we have found that we no longer have from our deck. And if we are currently in deck building mode, we also want to visually remove this card from our deck by removing its ribbon from the deck list. So we say, If deg building screen instance, if we are in deck building mode and if number of this card in deck that is also present in our builder script is greater than number of this card that we have in our collection, then we want to remove this card from our deck visually. So just remove the ribbon from our deck lis that is here on the right, so we'll say Deck building screen instance. Builder script dot remove card, Corrine card and else if you want to provide more feedback to your players when they try to disenchanted basic card. You can say that it is not allowed to disenchanted basic cards, so this else case here is just for that. So in this lecture, we have covered how the crafting screen is made in our application and our topics for next lectures are those screens for character and deck selection and also our lists for ready made decks and our released off guards that we are able to see in our collection. I would like to thank you for watching the course, and I'll see you in the next lecture.
31. 503 – Character Selection Screen: Hello, everyone, and welcome back to the course. So in the previous lecture, we have discussed our crafting screen and in this lecture will address our next biggest setback in our current set up. So currently I'm in the menu, seen course, and the game is running. Let's go to collection. And once we are in the collection, we could create a deck in our other. Seen the one that is cold. Just the menu seen the one that was pre built. But in this scene, if we go and press, new deck will get a Knoll reference exception, and the reason for that is we don't have an object that is cold character selection screen . So if I double click on this error and if I show you this script that causes the error, this script that is called the New Deck script is very simple, and it is attached to that new deck bottom object in the scene. So when we press the button, it just calls this method making you deck, and first it has to hide our deck building screen that we are showing to our players. And then it's you transition to this character selection screen. We have not introduced this screen into our seen yet, and we haven't seen the character selection screen script. So let's discuss this part off our application. In this lecture, let's go back to Unity. I'll exit Play mode and AL transition back to our pre made menu scene. Here's our character selection screen object. It has a component that is called character selection screen, very similar to all the other scripts that control our screens in the application. It has a reference to screen content. It has a reference to something new that we haven't seen before. That it's cold hero info panel that is a part of this screen. And it also has references to all the poor traits that are located on this screen and portray its are objects that have a script player portrait menu. I think let's enable this screen content so that we can see the screen in the background. We still have our deck booting screen enabled, so let's hide that. And now if we go to the scene, we can already see how this screen is laid out and how it looks because the camera is three D, even though this sign, Choose your hero appears behind our portrait's inorth, a graphic view in scene mode in the game mode, it is displayed correctly to make sure about that. Began deactivates our canvas over everything, so choose your hero is displayed above the portray its If we go back to the scene, each of thes bore traits is pretty similar, so all the portrait's are organized under this game. Object that is called portray its and they're just placed on equal distances in each direction, and the distance is equal to five. So, for example, for this one, the coordinates our A minus five in X Direction and five in Why Direction? And for the last one, it's vice versa. In X, it's five and and why It's minus five and the central one is located at 000 relative to this portrait scheme. Object. So these objects, they're not instant shaded from the prefab. They just sit there. They are pre made, and we can just click on them. And the character that we select will be selected on this side off the screen, and this side is called hero Info panel. So this hero info panel it has the script that it's cold. The same way. Hero Info panel. It has references to several buttons on this screen. We don't have a play button, so we cannot jump directly into the game from the screen. And it also has a reference to the portrait to this bigger one that reflects the character that we have currently selected. And two other elements on this screen are these build and deck button. So if we press the build button, it will call several methods. First, it will hide the character selection screen, and then it'll access our hero info panel and cola method. Go to deck building. That'll prompt us to build a deck for the character that we have currently selected. And our back button will just return us back to our deck building screen into the collection browsing mode. So now let's go back to Mona, develop and try to figure out how old these scripts that control our character selection screen work. So here is Mona Develop, and it contains only the scripts that we are interested in for this lecture. Let's start with character selection screen, very similar structure to all the other screens. It is a Singleton contains reference to our hero Info panel, which is this last script that will take a look at in this lecture. And it has an array off objects of type portrait menu, which is this second strip that will take a look right after this one. So in awake, we set up the instance. We hide the screen. It has only two methods. Hide the screen is super simple. We just hide the screen content, and if we show the screen, we want to make sure that none of the portrait's is selected. So we looped through all the portray. It's in our old portray its beret, and each portrayed menu has a method that is go de select. So on each of the portrait, it's we call the method portrayed Don't de Select, and we also access our Hero Info panel. Since this script also has something to do with our characters selection, we say hero panel dot select character, and we passed Snow as an argument into this method, meaning that currently none of the characters is selected. Let's go to our portrait menu script. So the portrait manuscript has only one public field, which is character asset s it, and in this case, we just have to set it up manually. So in unity, you go grab a character asset from your assets folder and drag it onto this public field for each off your portrait menu items, we have a private reference to player portrait visual, essentially player Portrait Visual is a similar component to one creature manager or one card manager that loads the data from character asset, and it re skins our portrait and makes it Luca visually, as if it was that character that we have selected. So, of course we want to do that on the screen, so we should have a reference to this component. We have references to initial scale and target scale off our portrait. It's and we need these variables Onley for this little visual effect that when we press on one off our port treats, it gets a bit enlarged and this character gets selected on the hero info panel. And finally, we have a private bullion that is gold selected. It's currently set to false. When we'll select the sport rate, it will be set to true. In awake, we get the component player portrait visual, and we instantly make it look the way that we wanted to look. So we pass our character asset from this stripped from the public field into our player portrait visual. And we say portrayed dot apply look from asset. So after these several lines are executed, our portrait will look like the character from this asset. It will grab the avatar and the background and older self that rule put in there, and we also save the initial scale bay, saving just one value of scale transformed up local scale X to select and de select the sport rate. We use the method on mouse down when we are clicking on this portrait with our mouths. If this portrait is not selected, then we say selected equals two. True between the scale towards our target scale in zero board five Seconds and we also excess our hero info panel because it is linked through our character selection screen. We say character selection, screen instance, Hero info panel and this method select character, as you will see later. It takes arguments not off type, character asset, but of type poor traits menu. So because we have to pass portrait menu into here. We can just say this, which means that we're passing this instance off the portrait menu script where we are currently executing this code. And then if we have selected one off our port traits, we need to de select all the other player portray its. We could have done this by getting this information from our character selection screen because we have all the references to our portrait Manu scripts there. But we can do this in a different way. We can say Portrait menu array, and we can get all the portrait menu scripts in our seen by saying Game object, find objects of type and will pass this type off portrait menu. Then we'll say for each. So we'll loop through our array all portrayed buttons and will de select all the portrait's except for this one. So this line, if M is not equal to this. It does exactly that. So for this portrait, we will not execute I m the de Select Onley four. The other poor treats and else. So if this portrait was selected, then we want to de select this portrait and we'll call the Method de Select and also will call the method select character in our hero Info panel and we who pass no as an argument. So we let our hero Info panel know that now none of the characters is selected, and this Method de select is quite simple. We set selected to fools, and we transition to our initials scale for the sport rate in 0.5 seconds. I think that the script Hero Info panel will be a topic off our next lecture, and we use Hero Info panel for several purposes. The first purpose is selecting characters, and the second purpose is selecting Deck Aikens. So we have a similar object with the same script, both on our character selection screen and ready made deck selection screen. And it's responsible for tracking down, which portrayed is currently selected, or which Deck is currently selected, who discuss it in detail in our next lecture. I'd like to thank you for watching the course, and I'll see you in the next lecture
32. 504 – HeroInfoPanel and Transmitting Data to the Next Scene: Hello, everyone, and welcome back to the course. So the topic off this lecture is our hero Info panel script, and this script will take care off, showing the selected character that we select on our character selection screen or on our ready made deck selection screen if we are selecting a deck that we want to use in play mode. So it has two different purposes in our application. And the first public feud is a field of type player portrait visual that is called Portrait . So our hero Info panel has its own portrait that it has to be skin. The portrayed on our Hero Info panel is larger than the other poor treats, and it makes it more important, sort of so that our players get an idea which one of the characters is currently selected. It has references to these buttons, and they're actually buttons from different screens if we are selecting a ready made deck, so one of the saved decks than the important button for us is the play button. So when the deck is selected, then we should be able to press the play button and go into our play mode and then we should set our play button to be interact herbal. Otherwise, if none of the decks is selected, the play button won't be interact Herbal so well will not be able to click on the button. And the same thing is true for our bill deck button. If we are using this hero Info panel script on our character selection screen on Lee, if we have selected one of the characters, we can press on this build deck button. If none of the characters is selected, it doesn't make sense to press on this bill deck button because we cannot build an abstract deck for any of the characters or for none of the characters. We have these two properties. I've made them into properties so that we can not see this field in the Inspector, and we will not try to set anything to these public fields. So the 1st 1 is portrayed menu that will be used on our character selection screen, and the 2nd 1 is Deck Aiken that will be used in a similar ready made deck selection screen . In our method awake that is, apart off money behavior will call the method on open in the method on Open will make sure that we have no characters or no Dex selected. So we'll say, select character and personal as an argument and will select and no deck. And then we have these two methods select character and select deck. So when we are selecting characters on our character selection screen, if the portrait menu that we pass into this method is no or if the portrait menu object that we pass into this method is equal to our current selected portrayed. So we have this portrait already selected, but we click on it again. Then we probably want to de select. Then we call a method portrayed game Object said Active False. So we stop showing the portrayed on our hero info panel. We sat our selected portrait to know, and we make our build deck button not interact herbal. So if we have a reference to Arbil deck button, we said it interact herbal to false, which means that we will not be able to click on the button and else so this is the ordinary case off selecting a portrait. Our menu portrait is not know and it is not equal to our current selected portrait. Then we'll say portrayed dot character Asset will set it equal to men you portrayed. That asset will apply the look from asset to our portrayed on our hero Info panel, and we'll set the portrayed active. So these three lines who ensure that our players see the portrait of the character that they have just selected. We'll store the selected portrait menu item in our selected portrait's property. Several say Selected portrait equals two men. You portray the argument that we pass into this method and we will make our build deck, button, interact, herbal. So now that we know for sure that we have selected one of the characters, we can build a deck for this character. If our players decide to press on the bill deck button and in a similar manner, we have another method select deck that does virtually the same thing. But the argument of this method is our deck Aiken, and you will find out what attack I can is in one off our next lectures. Deck. Aiken is pretty similar to our portrait menu, so it is represented with another portrait, but it also contains a ribbon with a deck name that we store in our list off ready made decks. In this method, if we want to set our selected, decked and null and not show anything on our hero info panel, we also check for this. If not deck information dot is complete, and deck information is off type deck info that you've over the scene in our previous lectures. It has a method is complete that shows if this stack has the max amount off cards index. So if we are allowed to enter play mode in this case, and if we are not allowed to enter play mode in this case, we shouldn't be allowed to select this deck on our ready made deck selection screen. So in this case, we set selected deck to be equal to know hide the portrait, and we set play button interruptible to false so we cannot press the play button. If we have tried to select this deck and this else case the case when we actually select a valley deck that we can use to start a match, we will re skin our portrait and show it to our players will set selected deck to be equal to deck, which is an argument off this method. This next line is interesting. Will instantly store the selected deck in the class battles. Start info. And I wanted to discuss this in our next lectures, but I think that now it might be an appropriate moment to discuss this concept with you. So in order to start the game, we have to somehow passed the information from one scene, which is our menu seen or many seen course that were working in right now to our battles scene. And in order to do this, we use this interesting trick. Restore all the information in the static class. So if we open battle start info, let me search for it in the search bar off Monta develop. The class is static and it contains only one public static member that is off type deck info and its gold selected deck. So whatever information you'd like to pass from one scene to the other, this is one of the ways that you can use to achieve this. Everything that is static doesn't get wiped when you load another scene. So if you have a static class and you write certain information into this glass. When the next scene is loaded, you can still access this information. So we want to store this selected deck through the scene loading process so that when the new scene is loaded, we can grab this selected deck and loaded for our player. And this aesthetic glass battle start info helps us achieve this goal. Now if we go back to our hero info panel. Finally, after storing this selected deck in battle start info, we can set our play button to interact herbal, which means that we can start the game with the deck that we have currently selected and this last method go to deck building. It is used as a button handler for one of the buttons in this class, which is this build deck button. So when the Bill DEG button is pressed, this method will be called Go to Deck Building. If our selected portrait is equal to know, of course, there is no point in building a deck for a character that is no than we just returned from the method. And if it isn't no than our code execution advances to this line and we say deck building, screen instance, cola method build a deck for and we passed the asset off the character that we have selected. So now that you know how old the scripts on our character selection screen work, I think there's no point in recreating it step by step in unity. It is quite a simple screen, and there's just a lot off mechanical work with objects that we already have. So what I'm offering is let's go to our many seen. I'm currently in this many seen that it's pre built. I can grab the character selection screen and copied from this scene. I would just copy. Then I will go to our many seen course, and I will just based it into the scene. Now, remember, we had a template for our character selection screen that only had an empty object that is called screen content. Now we can use this more advanced, pre assembled character selection screen, and you know how that works and what all the scripts do. So I will just delete this object from the scene right now, and I will based in you one So I'll hit based and it'll based in you character selection screen with all the pre assembled references. Let's check our hero info panel to make sure that the references to build deck button are assembled. There's no play button on this screen, so that's also fine. And now let's just just this. Let's run the game and make sure that we can try and build a deck for one off our characters. So now when the game is launched, if we go to collection, we can press on this new deck button, and it should take us to our character selection screen. We can choose one off the heroes. Let's speak another character, for example, this major character or a monk character, I guess, and we can press build the deck. You can notice that when a de select the character, it doesn't allow me to build a deck. It is allowed to build a deck for a character only if the character is selected, sir. When I press build a deck, it takes me straight into the deck building mode with only month cards or in neutral cards available, and we can name this deck, start adding cards to it and some neutral cards impress done. And now we have two decks available for us to edit. Or maybe play if these decks were complete and in the next lecture will address another a similar issue and will cover another screen that is similar to this one. If we go back in this scene, it just crossed my mind that I don't have the back button handler connected correctly in this scene. So when I pressed the back, but nothing actually happens, so the only way off going back is to just exit play mode and re enter it again. If we go to our first menu item that is called play right now, if you press on this. But nothing will happen because we don't have the ready made deck selection scheme that should show up when we press on this button and to make sure that we haven't left any off the buttons not connected. Let's go through the buttons that we have added into our scene while copy pasting our new screens. For example, this back button it'll de activate our character selection stream so it does cold character selection screen don't hide screen, but the other reference is missing, and the reference that is missing here. I think it should enable our menu panel. So it should say many panel game object set active and it should show this game objects so it should activate our menu panel if we press back. And the same thing should be true for the buttons on our deck building screens. So if we go and activate our screen content and deactivate the screen content on our character selection screen, so let's do that. The bottom that is not connected to anything is located on our existing decks canvas. It is called the back button, and now you see that both button handlers are actually not connected. So the first thing that should do it should de activate our deck building screen so we'll call a method hide screen on our deck building screen. And the second thing that will execute will also grab our panel, the one that represents our main menu. And we'll call a method on game object, said Active and will pass true into this method. So now let's perform a quick check. If we run the game, go to our collection and press back here now we should be able to return to our menu so that works as expected, I would like to thank you for watching, looking forward to seeing you in the next lecture where we'll discuss this play menu item.
33. 505 – Deck Selection Screen: Hello, everyone, and welcome back to the course. So in this lecture will talk about our ready made deck selection screen, the screen that will reflect the decks that we have rebuilt. And it'll let our players select one of the decks and enter play mode. So we have access to the screen if we press on this play item in the menu. If I press play and I am currently in our men, you seen the one that was pre built for the course. The screen will look like this. The structure is pretty similar to our character selection screen, except for decks. We also display their name, and we also display their state off being complete or incomplete. So this stack is incomplete. That's why it shows this cross mark that symbolizes that we cannot select it and we cannot play with his deck yet. And the deck that is complete, we can select it, and we can theoretically press on this play button and it should take us into play mode. The difference between this screen and our character selection screen is this. If we have only two decks on Lee, two items will be displayed on the screen, even though there are these other items. So the deck Aikens there also displayed in this three by three grid. But all the other elements they are just deactivated. For now. If we exit play mode and check out how it's set up in the scene, our screen is gold ready duck selection screen. It has a component deck selection screen that is one off our screen managers has reference to the screen. Content has references to Deck Aiken's, and it is very similar to our character selection screen that we have seen in the previous lecture. And it also has a reference to hero panel deck selection, which is the script hero info panel that you have already seen or go for. This lecture is to review all the code that makes this screen function correctly, and the only two classes that we haven't seen is the deck selection screen, this one and the one that is used for our deck Aikens. So let's take a look at them. If I open Mona, develop our deck selection screen looks like this. It has all the public fields that we have seen in the Inspector static instance off the same type as this glass to use it as a singleton in awake. We also call a method height screen, just like on all our other screens. And it has several methods. The ones that we have on almost all the streams are cold show, screen and hide. Screen hide screen is the simplest one. It just hides the screen content, the show screen method. It activates the screen content calls the method show decks. And it calls the method on open on the hero info panel that is present on this screen that will make sure that none of the decks none of the characters is selected. And all the interesting stuff happens in this method. Show decks. If we find out that our decks storage instance, old Dex doesn't contain any pre made decks. Then just opening this screen should take us to character selection screen that who prompt us to build a deck for one of the classes that we have in our game. So if we have no decks, it wouldn't make sense to show an empty screen. That's why we check if the count off decks in our deck storage is zero. We hide this screen. We go to our character selection screen, and we return from this method. There's not much more to do in this case, the next interesting step. Before showing any deck Aikens on our screen, we want to deactivate or disable all the deck Aikens. That's what's different between this screen and our character selection screen on the character selection screen. Old Aikens are active at all times. On this screen, it's different. We just loop through all the deck Aikens in our array deck Aikens first, and for each of them we say, I can dot game object dot set active. We deactivate the Eiken, and we also say I condone Instant de select Instant de Select is a method in our deck Aiken script. I don't know if it's 100% necessary. If we have set this Aiken active to false, we could have just used ordinary de select method. The purpose of this method is to de select the Eiken so that we don't even show that between off the scale of this Aiken. So there is no great year old transition effect. The Aiken is just instantly de selected and set to its initial scale, and then we loop through all the decks that we find in our decks storage. And when we find the deck, we make our deck. I can look like that deck. So we say Deck Aikins J, which is one off the deck, likens in our array cola method. Apply. Look to Aiken and in the deck storage in our old decks. Arabi store objects off type deck info. Our helper class that represents one deck and this same helper class will be passed through our battle start info into the game to start one battle. So we passed that to apply Luke to one of the deck Aikens, and we activate Onley, those Aikins that actually represent decks in our game. So we Sadek Aikens, J game objects, said active troops. And to understand how our deck Aikens function, let's go to our deck. I can class. It is pretty similar to our portrait menu class. The character portray. It's that we have seen on the previous screen, except this one also has a reference to our text component deck name, text. It also has a reference to that cross mark deck, not complete object. It is cold so if the deck is not complete, this object should be set active. If it is complete, this object should be hidden just like our character portrait's. It also has a reference to play a portrait visual because it looks like a portrait, so we're using the same component. It also saves the values off initial and target scale to show that little Tween animation when we select one of the Aiken's. And it has a private bullion that is called selected, and it's currently set to false public deck info. Deck information is used to store the car and deck info that is selected so the deck that we are about to use to enter play mode in this class. We don't set up the reference to play a portrait visual manually. So we just get the portrait by saying, Get component and we store the value off initial scale, just like in our portrait menu class in our deck selection screen class, we have called a method apply. Look to ICANN for all the deck Aikens on that screen that actually represent one of the decks. So in this method apply look, too. I can it'll take deck info from our decks storage as an argument who instantly saved this deck. Info. As this deck information next line is interesting. We'll grab our deck note complete object and we said it active, too. This not info is complete. So if our deck is complete than it'll say fools so will hide our deck. Note complete object and if info is complete, will be false. So the deck is not complete. Opposite to false will be true. So deck not complete object will end up being active and will be able to see that cross mark. These next two lines will risk in our portrait and make it look like that character that we're building this deck four and last but not least, we'll update the text to represent the name off our deck. The method on miles down is very similar to the one that we used in our portrait Manu class . It's virtually the same. So if this deck wasn't selected, we are selecting this deck. One tiny difference is that we're resuming on this deck on Lee. If this deck is complete and we are allowed to enter play mode with this deck, then we passed this deck into the hero info panel on this deck selection screen, we call the Method Select Deck that takes a deck Aiken as an argument so we can pass this and the rest of the method is pretty similar to the code that we used in our portrait menu class. So we de select all the Aikens, except for this one and else. If this Aiken was selected, then we d selected and make sure that none of the deck Aikins is selected on our hero panel deck selection. So we passed no as an argument into this select deck method de select Tweens. The scale two initial scale in 0.5 seconds and sets selected to fools and Method Instant de Select just instantly sets the scale to the initial scale, so it doesn't take any time to transition to the scale. It's just changed instantly, and selected is also set to false. And now that you know how this screen functions, I think let's go back to unity, just like with our character selection screen, I don't see a huge point in recreating this screen from scratch. I think we'll just copy this screen from this scene into the scene that we're working in and assembling in this course, so I'll just copy Go to our many seen course. We already had a template for our deck selection screen that contains just this screen content, so I will delete this one and I will right click and based the ready deck selection screen from our other scene into this scene. The only thing that we have to take care off is our back button. I think that it is not connected to our main menu that is currently located in this scene. It should say Panel, which is the panel that represents our menu, and if we're going back, it should set it active to true. And now that we have made all the necessary preparations, let's lunch the game and try if our play button in the menu works. If we hit play. Of course, we have not connected anything to this play button, and it should open our ready deck selection screen. So let's do that. If we expand our panel, find our buttons double click on the play button, it should execute several things when it's breast First, it should de activate the main menu. So it should say panel game object set active and passed false as an argument into this method. And secondly, it's you'd reference our ready deck selection screen and it should call a method show screen. I know that you are not able to see, but I'm selecting show screen and it reflects here. Now. If we launch the game, everything should be fixed. So if we launched the game breasts plea, we had two decks. We can select this one, and if we press play here, it should take us to our battle scene. But that doesn't happen. So now we have to check out what's happening with our play button here. And I think our play button was connected to a very simple object that is left in our pre assembled, many seen Let's save our progress in this scene, the one that was called seen real odor. So just to be 100% sure, let's expend our ready deck selection screen in this scene. Let's select our plea button. So in this scene, our play button it coz method scenery, loader loads scene and it passes the name of the scene, which is battle scene. So our scene re loader object is very simple. It only contains this script seen real odor if we open it in mono develop, there are several methods. The 1st 1 s code reload seen that resets everything that's necessary for our game to function clears the commands. A d factory i d Holder. All those things are related to our battle scene that we're not covering in this course, but it's included into this application that you get with the course and the method that we want to coal. Is this one load seen string seen Name it says Seen manager dot load seen, seen name and seen manager is, I think, aesthetic glass that you have access to if you include this unity engines seen management using statement on top of your class. So in order to fix that, let's go back to unity. I will copy this scene re loader object because it's very simple. We'll go to our many seen course based or a scene re loader object into the scene, dragged down our plea button, and this play button should reference seen real odor and call the method load scene, and it already remembers that it should pass battle scene as an argument. So now if we launch the game, kid play, select the deck that is rebuilt, and if you press plea, then the game will start. The cards will be dealt to our players, and we'll actually be able to play against AI or against our human opponent in this scene. So I can play the card here and turn play a couple of cards here so we can confirm that overall, this works. Now I can exit play mode. So in the current state off our project, our many seen chorus is also pretty much assembled. Everything is covered. We can hit, play and start the game. We can go to our collection and assemble our deck, but I remember that we haven't covered one thing. For example, in this scene, we have copied these two lists. One of them is the list off cards that we are heading into the deck. Another list is the list off pre made decks, and I want to talk about them in our next lectures because these two things, they're the only things that we have left uncovered in this course. I would like to thank you for watching this course, and I will see you in the next lecture
34. 506 – Scrollable Lists of Decks and Cards in Collection: Hello, everyone, and welcome back to the course in this lecture. I wanted to talk about these two lists that we have here on the right side off our screen. One of them is called card list canvas. It's the list that we are able to see right now, and the second list is gold existing decks canvas. And there is no situation in our many seen when we're able to see both of these lists. So they occupy the same area on the screen and just for the sake off demonstration and showing them to you. I wanted to rearrange our seen a bit and show them to you side by side so that you see all their similarities and differences. First, we can de activate our background. Canvas will not be that our great for cards object we can also temporarily deactivate. It will not need the main canvas that holds our menu for this lecture so I can deactivate it as well and our existing decks, least existing decks. Canvas is currently not active in the scene, so I'll make it active. And then I will change its exposition so that we have these two ists side by side like this , and you can instantly notice some similarities. I think that these lists they were actually made from the same object. So I made one of them first. And then I did the 2nd 1 as a derivative off the 1st 1 Both of these objects, they have their own canvas that is set to world space. So we're currently looking get our existing decks canvas, and if we switch to card list canvas, it'll be separate canvas in world space. The second similarity is both of these lists or these objects. They have a script that will manage their behavior that will add certain objects to the lists that are contained in these. Cannabis is, for example, our card list canvas. It has a script that is called Deck Builder and our existing decks canvas. It has a simpler script that is called list off decks in collection, both of them. They have a reference to this content, which is erect, transform, and to the pre fabs that will instance she ate and make them the items off our list. So for our decks list will instance she ate this deck name prefab, and we'll also instance, she ate the new deck buttons so it will contain two different kinds off pre fabs and for our cards list canvas. We can notice the similarity that it also contains the prefab that it will spawn into this list. And it contains the content reference. So all the pre fabs that we instance she ate they will become child objects off this content transformed. Now if we check out how the prefab looks that will instance she ate into one of these lists , for example, our card named Prefab and selected here in our S. It's folder. You'll see that this prefab is also made off unity. You I So it has you I components. It has direct transform, so it will not even be visible outside off the canvas. If we just drag it into our scene, it'll not be represented correctly. And the only way to see this game object displayed correctly is to make it a child off canvas. One of our campuses, for example, let's drag this one onto our cards least canvas. I think the issue here is that our guard, for some reason, it got enlarged to this extremely high scale off 50 50 if we return it back to the scale off 11 And this probably happened when we dragged is into the scene this representation of a card in our list. It will obtain the necessary scale, and it will be represented properly in our list. I can create duplicates off this card ribbon. Let's go back to our lists and check out other similarities. And let's probably start from the simple stuff. Both of them have a button here in the lower part off the canvas. In this list, the button says back and in our cards list the button, says Don, which means that we're done editing a deck. Essentially, this is also a sort of a back bottom that brings us back to the previous screen on top. Off our lists, we have two other objects in one of the West's is just attacks that says your decks. And in our second list, the one that holds cards that are featured in your players deck. There is this object deck name, input field, and this is just a ordinary input field that you can just create by right clicking, going to you I and finding an input field in this drop down menu. The purpose off this input feud is to let our players name their deck, and when they press done, this information gets saved first into our decks storage. And then when they exit the game, it also gets saved into our player preps, and the list itself is built using the unities built in scroll view and scroll view is a component that you can create by right clicking, going to you I and selecting a scroll view. And it has a scroll wrecked component. And it's like a pre built scroll herbal list that you can customize and use in your game if you need this. But I've made several adjustments to the scroll lists by default. Stroll ists also have a horizontal scroll. Bar in this case will not scroll it horizontally, so we won't need this. There is some bug connected to this horizontal scrolling check mark. So even though we will not scroll these lists horizontally, I still keep this horizontal check Mark checked in both off our lists. Even visually, we can recognize that both of these lists they have a very similar structure. So if we expanded this row view has a child object, a school Vieux port, just like here. And then the View port has a child object that is called content. The View port object in both cases contains an image and a you. I'm ask component so that if we ADM or, for example, decks into this least off pre made decks and we have so many of them that they start overflowing the size off our content, then this Pew port object will mask them, and it will display on Lee that portion that's inside the view port and another thing that we use. If we check out the content objects, we use several components to organize the list elements inside the content. The first component is Vertical Layout Group that controls the size, placing and spacing off all the child objects that we add into this list. So, for example, if I had to create a couple more off these deck name pre fabs, I could press control D on my keyboard, and it'll just add several more of them if it changed the order in the list than we get more of these deck name pre fabs and then this new deck button in the lower part of for a list. If I create a couple copies off this new deck button, we can see the illustration off our view. Port mask working. So without the View Port Mask, it would probably look awkward if I uncheck this mask component, then this list doesn't look right. If we check it back, then it looks like an ordinary scalable list, just like we intended. So I'll delete the extra elements that have added into this list. So both content objects. They contain the Vertical Layout group to organize the elements and another useful component that we use on these content objects. It's gold content, size fitter horizontal pit is set to men. Size and vertical fit is set to preferred size. And this allows this content object to constantly adapt to the number off elements that we add into our list. For example, right now, this content object is selected in the scene, and if presume in you can see that it just surrounds all the elements that are added in the list. It has a bit of padding on the sides because the batting ISS set in our vertical layout group. So let's actually intended. And if we start adding new elements to our list, so I'll create a couple more copies off this button and we switch back to our content will be able to see that now this content is larger and its fans even lower than our back button , so the content constantly tries to adapt. And it has the same size as all the elements that we add into our list. If we do eat some of the buttons that are unnecessary and these deck names as well and select the content again, the content will be fit to these two buttons. If we go and check out the pre fabs that we use in our lists, who discover that they are all actually buttons, not just this new deck button that is obviously button, but also this deck name prefab. It also has the bottom script and a helper class deck in school lists that allows us to control its behavior. And also, if we check the card name prefab, you can even see that when I switch them. They're very, very similar ends their structure. They have an image of buttons, so this is just an ordinary U Y button and this card named Prefab. It also has a component card named Ribbon that is used to display the correct text on the button, like the card name correct quantity off this guard in our deck. And also, if we click on one of these ribbons, it means that we want to return the card from our deck back to our collection, and we'll discuss that in our next lecture. If we check the structure off the pre fabs that we use in our list, there is nothing that will be that you to us. We've done that a lot in the course, so this guard named Prefab is just an ordinary button that has several texts. One of them is the name text that is anchored to one side off our button, and the 2nd 1 is quantity text. Because the ribbons are of these interesting shape. I also use creative anchoring, so I dont anchor the text to the borders off this bottom graphic. I anchor them so that they look appropriate with this ribbon, and if we check our deck name prefab, it has only one text, but it has several images. For example, it has thes character avatar image, the name tax that is displayed on the side off our deck name prefab. And it has the frame just for decoration purposes. And another cool thing that I forgot to tell you about for this cards in deck list that displays the cards. We have this another interesting object that is called the deck Complete frame, and it's actually a child object off our view port so the content object it expands or contracts when the add elements to it, or remove elements from it and the view port object. It always remains stationary, and it has the same shape. So by adding this frame to our view port object, the frame will also be stationary and will use this frame to symbolized that. Okay, our deck is now full, and we can enter play mode with this deck. So I think now we have covered how these lists work. Visually, they're both pretty similar, and they use the same methods or ways off managing the list items, and in the next lecture will take a look at the scripts that make these lists work in general and make these least items work like the script deck in scroll list for our deck name, prefab and the script card named Ribbon for our card name Pre Febreze. Thanks for watching and see you in the next lecture.
35. 507 – Scripts that Control the List of Pre Made Decks: Hello, everyone and welcome back to the course in this lecture will talk about the list off decks that your players have pre built for themselves to use in the game. We have already seen how it's done visually, and all the action in this list is controlled by two scripts. One of them is attached to the pre fabs that we instance she ate into this list and the script is called Deck in Scroll list, and the second script that serves as a manager for this object is gold list off decks in collection. So in this lecture will take a look at these two scripts, and I'll do my best to explain how they work. Let's jump right into modern develop this list off decks in collection script is not that long and not very complicated. It has only one method update list. So essentially the only thing that we can do with this list is show the actual information that is contained in our decks storage, a glass or Dex storage object and all the different actions. For example, your player has built in you'd AC, or your player has deleted his old deck. They only require us to run an update operation on this list so that it displays the latest state off our decks storage. The script has three public fields. One of them is the transform content that will serve as apparent for our pre fabs that we instant sheet and two references to pre fabs. One of them is the deck, button or deck Aiken and the other one is the new deck, but the one that appears in the very end and lets us built in you deck in the Method Update list. First we have to clear the list. So whatever information, whatever pre inst enshi ated objects we have in this list, we have to destroy all of them. And we can do this by saying for each transform T in content. This for each loop will loop through all the child objects off our content transform, and I am not sure if content itself is included. So here I am also checking if T is not equal to content. We don't want to destroy our content game object, and if we find any objects that are parented to our content, we simply destroy them. Then, when we are 100% sure that our content is clear. We approach this next statement. We check out our decks storage so we say for each deck info, info in decks, storage instance dot old decks and for each neck that we find, we instance she ate and you deck in list brief up. This variation off calling instant she ate will make our deck in list prefab a child off our content game object. We also make sure that this newly in satiated object has a local scale off one. Then, on this new game object, we know that it's a prefab and it should have our deck in scroll ist script so we can say G get component and get this component on the object that we have just instance she hated. And the only method that we have to call here to make that component look like our deck and represent the information about the deck. We have to say Deck in strollers component dot apply info and we're passing info, which in this case is deck info straight from our decks storage. So when we exit this for each loop, all the decks that you have in your deck storage there already reflected in our scroll herbal list. If there is more room in our deck storage and if we can create more decks Onley in this case, we'll show the new deck bottom to our players. And the only thing that we have to do with the new deck button is instance she ated and ensure that it has the correct scale. So the syntax is pretty much the same that we use when we create the new deck in List B fab except here. We don't have to get any other component. We just have to instance she ate it and all the functionality is already packed into this new deck bottom. And now let's check out how our deck in scroll ist script looks the one that is attached to each deck in list prefab. So if we go to this script, you can see that it inherits not only Mona behaviour but also implements these interfaces. I point her. Enter handler and I points are exit handler, and they're used in this script to activate or deactivate the little cross mark button in the corner off each deck. Item in the scroll list that will let us delete this deck. That item in the corner is also bottom, sir. With this code, we ensure that once we hover over this item in the scroll ist this cross mark button will appear in the corner off our deck list. Item weaken. Hover over that button, press on the button and this deck will be deleted from our list and from our decks storage to use this functionality off I pointer handlers. We have to also use these new name spaces, unity engine events and unity engine event systems. The public fields are references to a graphical components that our list item has. So you remember that it has the avatar image, the name text that shows the name off our deck. And it also has a reference to this delete deck button, but as a game object. So we only need a reference to it as a game object so that we can activate or deactivate it . And in a week, we make sure that we are not showing this delete deck button. So we said it active to false. There are several methods in this glass. Most of them are used as button handlers, for example. This method added, this deck is used when we just pressed on this item in the list. And when we click on this item, you want to instantly take action and edit this deck. So we have to bring our deck building screen into a different mode. Previously, we were just collection browsing, and now we want to build a deck. So in order to wipe all the information that is currently shown on our deck building screen , first we hide the screen. We say Deck building, screen instance. Hide screen. Then we are preparing this screen for building a deck for a character that we have selected . So we access this field, save deck info and save Dick Info actually should have bean a property so we'll never edit it in the Inspector. It will be just set in code, and there's no need to make it a public variable. It could have been a public property, so we're saying deck building screen instance Builder script. And it's something that you will see in our next lecture. That's the script that manages those little card name ribbons in our other scalable list. So we go to that script and we say Build a deck four and essentially when we want to edit the deck that was pre built. We want to open that deck building screen, but there's nothing in that list off card ribbons, so we want to feel it manually with the cards that are saved in our decks storage. So we call a method, build it at four. We set the name of this deck on that input feud on top off our cards list. Then we populate the least off guards by seeing for each card asset acid in save deck info . So this is the deck that this item represents, and we know which guards does this deck have. So we can pass this information on to our builder script and add all those cards as those ribbon items into our deck list. And this next step is interesting. Be excess our decks, storage instance old decks and we remove the deck that we have just selected for editing. So we know for sure that this will be in you deck. The person will edit the deck, or even if they will press done, this deck will be saved as a new one into our decks storage and another thing that we're doing in this method. We are building this deck for a certain class that is defined in our project, So we have to pass this information and show the appropriate class names on our tabs. One of the tabs should be preset for that class that we're building this deck for, and the other tab should just say neutral. So we are accessing our tap script, and we are setting the class on that class stamp to the class that was pre selected for this deck. And we also excess our collection, browser, script and cola method show collection for deck building that will ensure that our screen looks in a way that is appropriate for deck billing. And after all these operations are performed, we also call the Method Deck building screen instance show screen for deck building, so there might be some duplicate code here in this method showed screen for deck building and in this other method show collection for deck building. But the important part here is that both of these scripts, they ensure that when players see our collection, everything is set up for building a deck for a certain character. And if we scroll a bit lower, there are also these several methods This method apply. Info is cold from our list off decks in collection. So we pass in our deck info and then from our deck in for we Can Draw This Information about the Avatar image were getting it from our character asset. It has a reference to a sprite that's called Avatar Image. We have information about our name, text weaken. Just set it to deck info dot deck name, and we are storing this deck info that we pass into this method as saved deck info. The variable that we were operating in this edit this deck method. Then this method delete. This deck is used as a bottom handler for our delete button. And like I say here in the comment, we can also display the Are you sure window, which will be an extra U Y elements. So it didn't want to bother and overcomplicate this tutorial. I think it's complicated enough already, So when we press that little cross mark button in the corner off our deck, Aiken, this method delete This deck is cold and it does two things. First, it removes this deck from our deck storage. And second, it also destroys this game objects. So it destroys itself. And this deck is removed from our scroll herbal list. And these last methods on Pointer, enter and on pointer exit their required in order to implement those interfaces that we have inherited on top of our class I pointer, enter Handler and I Pointer. Exit handler. You can read about them in unity documentation. It is required for these methods to take this pointer event data argument even though we don't use it here. So when we enter this object with our pointer will activate our delete tech button. And when we exit this object with our pointers so we're no longer hovering over it. Well, say delete that buttons set active falls. And that's it for these two scripts. Now you know how they work. And in the next lecture will make a similar overview off the code that we use for that list with card name ribbons, the list that contains the cards that your players include into their deck. I would like to thank you for watching and I will see you in the next lecture
36. 508 – Scripts that Control the List of Cards in Deck: Hello, everyone, and welcome back to the course in this lecture will take a look at this list that will hold cards that your players add into their decks, and the list will contain these objects. They're called card name prefab, and these card named pre fabs are actually ordinary unity buttons that also have this component card named Ribbon. They will display the name of the card that you have added into your deck and the quantity of this card that has been added into the deck. So we'll take a look at this card name ribbon script and will also take a look at another script that is on our cards least cannabis objects. And it's called the deck Builder and deck Builder. This script has several public fields that are very important for the general few off the game. For example, it has the feud same card limit that defines how many instances of the same card can you put into one deck. And it also has this other public field that's called amount off cards in deck. And by changing this setting in deck builder, you can extend the decks in your game from 10 cards like we have it set right now to 20 or 30 cards or whatever other number that you find appropriate for your gain. Other than that, it's pretty similar to the script that we have seen that manages the other scroll of a list in our game. So it has a reference to the prefab card name Prefab. It has a reference to this content transform to define the parent transform when we instance, she ate our pre fabs, and it also has a reference to this deck complete frame, which is just an object that we can turn on or off, depending on the state off our deck, whether it is complete or not. So let's open, model developed and let's start from this first simpler script that is called card named Ribbon. So our entries in the list they will have to texts. They have to display the name of the cart who have a text for that, and we have to display the quantity of the card so we'll have the second text. For that, we'll have a reference to the image of a background image of the button that looks like a ribbon. In our case, and will use the image in this script to change its color and to make it represent cards off certain character class. So here we have a public property card asset asset, and we've made it appropriate e just so that we don't mess with it in the Inspector so well on Lee said it in code, we have another property for quantity. So whenever we set asset, it makes sense to change the name off this card. And also we can change the image cholera, depending on the character asset that this card belongs to, and whenever we change quantity, it makes sense to update our quantity text. This method apply Acid is more like a general method that we re skin this bottom that will make it look like that card first in terms of color. So we check here. If the character acid of this card is not able to know, which means that this card is not neutral and this card belongs to certain character class . Then we'll set the ribbon image to BC adult character asset. So we'll access the character that this card belongs to, and we will select the color off class card tint, which is set up in our character assets. Then we'll set this estate property to be equal to see a and we'll change the name text on our card to be equal to the name off our card asset. So names off those files that you have in your Assets folder. They also serve as names off your cards and then we call this next method set quantity and we passed in this value off integer quantity. If we move into this method, we check if quantity is equal to zero, then we just returned from the method. We don't have to do anything. And if the quantity is something other than zero, it makes sense to update our quantity texts. And we display the text in this format axe and then the number of cards that we have added into our deck. And we also save this integer quantity into our quantity property and this next method reduced quantity. It will serve as a button handler. So if we press on one of the items in our cards list, it means that we want to return this card from the cards least back into our collection. So we'll do just that, say, deck booting screen instance. We'll refer to our builder script, which is the next script that will take a look at in this lecture deck builder and Will Cola method remove card that will make sure that the deck that we're building no longer has this card or has a smaller quantity off the same card in deck. Now that we have covered this glass, let's go and take a look at the deck builder class. You have seen all the public fields of this class in unity. We also have several private fields. The 1st 1 is the least off guard acid that is called deck list, and it makes sense to have a list like that because it easily translates into our deck info . If you remember the class deck info that represents one deck in our game, it also has the least off card assets. And since the card assets that we add into our deck, they correspond to these least entries the items that we add into our least for our convenience. We create this dictionary that will have keys off type card asset and will have values of type card name ribbons. There will no which one of the inst enshi ated objects that we add into our list for each object will know to which card asset does it correspond to with this dictionary? Next, we have this important property public Boolean Index building mode so we'll be able to add cards into our deck on Lee if we are in deck building mode when we are just collection browsing. So we're looking at all the cards and on the right side, we don't have the least off cards in our deck. But we have the least off pre made decks than this index building mode. Property will be set to false, which means that will not be able to add cards if we click on them in the collection into our deck list. We also have this private variable building for this character, and this value will be set in one of the public methods, just so that the script is wear off for which character are rebuilding a Deck four and in awake. We have just one line. We refer to that complete frame, which is a game object. We get component of type image on our deck complete frame because we know it is an image. And we said this interesting property ray cast targets equals fools. So I've made this mistake a couple of times when I was building this application. If we go back to unity, let me show this to. So currently I have this object selected deck complete frame. It has an image component. And if this image wasn't set to rake a stargate false than this deck complete frame, it doesn't matter that much that in the center of this image, it is 100% transparent. So unity is not aware off these things. And because it is located lower in hierarchy than our card name pre fabs This that complete frame object, it will intercept clicks on our card name pre fabs, and we want to prevent this from happening. So an easy way of doing this is to make this image not a recast target. So this is just a visual element that we show for decoration purposes, not something that we want to be able to click on in the game. So was go back to mono, develop this line in awake. It ensures that this image is never array. Cast target. Next, we have a method ad card that will be cold when we pressed on one of the cards in our collection, and we are also in deck building mode. So, like I said, if we were just collection browsing and not building a deck, if we press on any of the cards in our collection, this at card method would be cold. But it wouldn't let the code execution approach any further. Next check ensures that we still have some cards to add into our deck. So if the deck is already full than none of the operations below, this line will be executed and will also return from this method. Then we want to establish a couple of integers that will let us decide whether we can or we cannot at this card into our deck. The 1st 1 is integer count and will call a method that is also in this class number of this card index who pass in the asset. That is an argument of this method and in our application because we have the max limit off the same card set to it might only be 01 or two then we'll try to figure out the limits off this card in deck and a universal limit off. Having the same cards in our deck is set in this class, and it's equal to same card limit. But I've also included another way off letting you decide how much off this same card can you include into the deck, for example, In some games, you can include Onley one instance off legendary cards. Or you might have some other conditions of defining how many instances of the same card you want your players to be able to include into the deck. So I've included this field into our card asset class. That's called override limits off this card in deck so we can decide for each guard individually, whether we want to impose some limits. Or we want to make the limit for this card a bit higher so you can have different limits for each and every card in your collection. And if this limit is greater than zero, so by default this limit is set to minus one or something like that, and if we said it to be greater than zero, then we update this variable limit of this card index with the value from our card s it and then we can only add this guard into our deck if the count. So the number of the cards that we already have in the deck is less than the limits off this card in deck. In this case, we approach into this. If statement, we add this guard into our deck list, that is just the least off guard assets we call the method Check deck complete frame that activate or deactivate our frame. And it's just a one line method that you see here. We say that complete frame dot set active and we said it active to this value that is actually a boolean. So we check if our deck least count is equal to amount of cards in deck. So if we have reached the max amount, this value will be set to true and the deck complete free will be activated else the deck complete frame will be deactivated. Then we incremental value off count to display the most recent value on our card ribbon. And then if we already have the key off type asset in our ribbons dictionary that we have defined here until before Class Dictionary That is gold ribbons. If we already have this asset in our dictionary, which means that we already have a certain quantity of this card in our deck. We already have a pre incense she ated object that represents this card in the deck. Then we should just update the quantity. So we call ribbons with an index or with the key off asset, and we call the method set quantity. And it's a method from our card named Ribbon Class that we have just seen in this lecture and else this is the case when we actually have two instance she ate and you card, name, object. So we say game object card name Winston. She ate our card name prefab, and instantly make it a child off our content transform by saying card named Transform set as last sibling, we make sure that this guard name that we have just instance she ated with will appear in the very end of the list. We ensure that this card named Transform has the scale off Vector 31 To avoid any scale distortion, we have to get the component of type card named ribbon on our cards. To be able to call this method, apply acid to make sure that this ribbon represents our card in terms, off color, name and quantity. And finally, if it's a new ribbon, we have to add an entry into our dictionary. So we add the ribbon component from the game object that we have just created with a key off assets so that we know which ass it doesn't represent in our list. And then if we scroll a bit lower, we have already seen the method check that complete our number of this guard in deck who looped through all the card assets that we have in our deck least. And if we find that the C s o the asset that we are iterating through in our list, one of the elements in this list is equal to the asset that we passed in as an argument of this method who increments this value off count and by the end of this method will return the value off count. So this method will truly return the number off instances of this card that we have in the deck and this next method remove card. It will be called from our card named Ribbon Class. When we press on one of the card name ribbons, then we find this card name ribbon component in our ribbons dictionary. We can say ribbons to remove set quantity, and we can make it equal to the quantity off this card minus one. And then it might actually said the quantity to zero. So we should also check if the number of this card in deck off This asset was equal to one . Then we should remove this ribbon from our list and we should also destroy this game object . So we only remove the ribbon from our list. If we don't have any instances of this card in our deck with our deck lease, the situation is a bit different. It can contain several instances off the same asset. So by saying deck least remove and passing asset into the remove method, we're removing only one of them. So if we are removing this card from the deck list, we don't have to perform any extra checks. And when we have removed the card, we should call the method check that complete frame. Of course, if we have removed the card from our list. This check that complete frame can only lead to one event, which is de activating the frame. And in the very end of this method will coal deck booting screen instance collection browser script update Quantities on page. If we're using the mode that will affect quantities off cards on one page when we are adding them into our deck, then we should also update quantities when we remove cards from the deck. And there's also this method. Build a deck four that is cold when we initiate building a deck for a certain character. If we called build a deck four. It means that we are in deck booting mode. So this Boolean is set to true. We're saving the asset of the character that we are intending to build this deck for into our building for character variable that we have in this class. We have to clear our deck list and we can do this in this wild loop. It is not enough to just say deck list dot clear. We have to ensure that these cards are also removed from our least physically, so their visual representations have to be removed from the list as well. That's why we have to call the method remove card each time. Then we update their character class on our tabs that we have here on top off our collection. And we do that by saying Deck booting street instance, stab script. And we said the class on class stab to be equal to this character s it. That is an argument of this method. And we also Cole a method in collection browser script show collection for deck building. And we also pass in this asset again. This method check that complete frame can only lead to one result, which is the deck complete frame will be de activated. And if we're building in you deck, we also have to reset that input field that we have on top off our deck list. And we do that by saying Deck named the Tax and we said it to an empty string so players will be able to select their own name for their deck. We have a few other methods. This method done button handler will be used as a handler for the done button in the lower part of the list. So when we press on the done button, it means that we should save the work that our players have done. Save the deck that they have built into our decks. Storage. At this moment, we have to generate in you deck info object. We see deck info deck to save that takes the following arguments. Our decks list that is list off guard assets. Our deck name, though. Text the text that players have updated themselves and the name that they have selected for their deck and we will surpass in the character asset building for character. And whenever we press done, we also passed this deck info to our decks storage. So we add this to the least old decks and we say decks, storage instance. Save decks into player preps. So whenever your player presses done, we also make sure that this deck is saved into player breaths, not just saved into the decks storage. And another important thing is when we are done building and act, we want to go back to our deck booting screen for collection browsing. So we do that. We're calling a method show screen for collection, browsing on our deck, booting screen Singleton object and finally, on application quit. We can call the same method done button handler. Let's say our player was building a deck, and for some reason he decides to quits the application right from that deck building stream. We should allow that to happen, but we have to make sure that his progress isn't lost. And we want to save his progress both into our decks, storage into player preps and so on and so forth. So by calling this method done button handler, we make sure that none of the progress off our players is lost if they exit the game right from the deck building screen. And I think by reaching the end of this script, we have completed the educational part of the scores. So now I have told you everything that I personally know about this menus application and how it functions. The next lecture will contain some conclusions that we can draw from this course, and I'll try to show you some other interesting quirks and features off this project. I would like to thank you for watching the course, and I'll see you in the next lecture
37. 509 – Conclusions: Hello, everyone and congratulations. You have completed this scores. Thanks for keeping up with me for such a long time. I hope you like the course. And I hope it helps you in making off your own trading guard game and specifically the menus for your own trading card game. Now, if you have any questions remaining, or if you want to ask me any trading card game related question, please ask them in the Q and a section for this course. I take you in a very seriously, and we had another course about trading card games that covered trading card game battle system. And in that course, we have reached over 150 answered questions in the Q and A. I usually try to answer all the questions within 24 hours, sometimes even within a couple of hours after the question has been asked. So if you ask your question, you will definitely get an answer from me. And in this last lecture, I wanted to show you something different that you can do with this project. Previously, when we were pressing this play button on our ready deck selection screen, it took us to the scene that was called Battle Scene. And that scene is configured in a way that you're playing for both players, both the top player that in most card games is your opponent and for the lower one that is mostly identified as your own player. But this project also contains a very simple A I script that can play a game against you. So I wanted to demonstrate that in this lecture, and to achieve this, I have changed the argument that it's passed into our method scenery loader loads seen from our play button. And right now it's making a transition into this. A. I seen for us. I had to make several adjustments to this project. Among these adjustments, I had to bring this object that it's called rarity colors into our scene, because right now that we have these rarity stones on our cards, when we create each card, it tries to access this rarity. Collars object to figure out the correct color to show on the rarity stone. So I have added this object to this a. I seen previously it wasn't there, and another fix that I had to apply was this line in my card logic script. I don't know why for some reason the card logic constructor, it takes the player owner argument, and we have to write the player owner as the owner off this card. I know that this material wasn't covered in this course. These are the classes that we used to make our battle system in the trading card game functional. But my point is this. If you want to have your scenes, if you want to have your project prepared for this game vs AI and you want the latest state of your project, always download the project that is called Final in the Downloads. So I would always suggest if you watch my courses, go straight for the final project and then figure everything out from there because mistakes, you know, their inevitable sometimes. And even though I am trying to fix all the mistakes, sometimes they just happen. And most of them, at least, all the mistakes that I know off their fixed in the final project. So now if I closed Monta develop and if we launched the game, if we hit play, select our deck and transition into play mode, as th