Great tutorial for beginners!. It misses few concepts that are important to talk about when teaching generics: - What is the difference between T and object - Why not use ArrayList? - What is a generic type T - How it's essentially different than a regular class type (Like array of objects?) This is a good point to talk about meta-programming, How a generic type looks under the hood. - covariance and contravariance in generic programming. A good place to look at will be Clr via C#, explains very well what is a type and a generic type.
Aside from the factory, the examples provided do not display re-usability as explained since re-usability is already provided by the Hero generic class inheritance or the ping interface. You can just have a HeroHelper with a non-generic Hero data type and it will do exactly the same but your code will even be clearer.. Generics really shine when you need to handle elements of various types all together or when you want to define behaviors that do not depend on the type. So if you use where T:WhateverType and define behaviors based on WhateverType, it's fine but you do not need generics. Example : You have a generic class Selection handling player's selection of an item. This Selection does require a type T since it will trigger an event with its T data upon selection (since you need to now who fired the event). Now let's say i want that behavior on an Item & on a button : Just declare UIItem : Selection & UIButton : Selection and hook up its selection event and that's it. (and this is an inheritance example but it works just the same by composition).
For so long I've been looking at generics and failing to understand how and when to use it. I always had a feeling that I needed to use (or would be useful) but never could figure it out. You've explained it so simply that it just makes perfect sense to me now. Thank you! :)
Great explanation, thank you, I've stumbled upon some videos about generic functions, and the guys keep theoreticising about generics without explaining it deeply in this manner
Great video! one point i would have added is how generics work with inheritance. So you could also make a class WarriorHelper : HeroHelper if you wanted to add a function that is specific to warriors. This is also valuable for working with generics in monobehaviours in unity, as you dont create monobehaviours by their constructor and cant add a monobehaviour with a generic type as component.
just found out about your channel from a certain video that has absolute random numbers as examples and I must say I'm really digging into your clean video format, deep explanation and occasional dad jokes. Subbed and will hope for the channel to blow up soon.
Just wow. TY I like the explanation. You have made my day! I can't explain how this makes me so happy! I was looking for an explanation of this for while. It is explained so well and I can immediately apply it.
Eggcellent video, quite informative. If you may, could you drop the bgm in future videos, or try with a less intrusive theme? It gets quite annoying after a while when using headphones, thank you.
Look at you Mr. Fancy Pants with your C# 10 & VS 2022. I can't wait until Unity catches up some. Of all the new features, I oddly think the file-scoped namespace is going to be my favorite. Tabbing an entire class for nothing more than a namespace makes my OCD tingle.
I especially like it for videos as it keeps boilerplate away and allows people to focus purely on the content. This is magnified for new devs who have only experienced unity and never created a console app, static void main could be confusing.
Hey! I recently found your channel and must say this channel is blessing. Also your art style is fooking awesome, it would be a another blessing if you do that kind of art tutorials
I'm honoured you would like me to do an art video, but I absolutely feel like an imposter in the art world. Are you talking about all the little mascots I drew?
your videos are very good, they are helping me a lot in the creation processor of my game. I spent 1 year studying to be able to make a game, now with some of your videos I managed to progress much faster. if I made a video showing my project would you see? I'm sure you'll be surprised by my idea.
I wish I could double thumbs up this. I’ve read through the definition of generics and interfaces. I’ve written them out in my own code. But I never fully understood them until seeing the examples you had here. This explained so many of the things I haven’t quite mastered in C#. I feel so much more powerful now! But seriously thank you for this!
Gamifying anything makes it fun to learn. Imagine if we earned experience ironing our clothes, or washing the dishes. You better believe I'd be a level 80 ironer. But in reality, I've ironed once in my entire life lol.
@@RealisiticEdgeMod I mean yeah... I don't think the purpose of the video was to make you an expert on generics, but a lot of people might not have know about them or how to use them properly. I'm pretty new to coding and even though I knew about generics I found the video very helpful for clarifying and expanding upon my knowledge.
Excellent tutorial about generics, we are very lucky that you share this stuff with us sir. I would love if possible that you give some hints on the best architecture for a videoadventure where objects unlock dialogues and areas, and also depending on the answers given to a certain NPC, this propagates to the branching dialogues of not only this but ther NPC in the world but currently not in the scene, affecting the main storyline and the behavours of those NPCs towards the main character. I don't know what would be the best way to handle such complexity with so many NPCs, dialogues and object triggers affected. If I think of events and listeners, won't the code end up with lots of conditionals. Is there a cleaner way to do this?
Very informative. Thanks! On the other hand, I don't see the point of the HeroHelper class: you have to create a helper for each hero, and using ForceHeroToAttack is not easier or more flexible than using Attack? In addition, we manage 2 variables: the hero and his helper. I must have missed something ... We can define the Attack method as virtual and overload it in the child classes. I also do not see the point of increasing the code with HeroFactory compared to the use of constructors : - with constructor : Mage mage = new Mage ("Gandalf", 100); - with HeroFactory : Mage mage = HeroFactory ("Gandalf", 100); Also, if we want to have a different behavior from the mage (for example a mana field used by each attack), I have not succeeded in simply modifying HeroFactory.
In that case you will need a generic class that implements IAttack, and now you can send there Archers, Mages, Warriors who need to know how to attack (for example the mage uses mana, the warrior uses fury, etc) but the implementation is inside every singular class
Okay so I finally came to convert my mod system to use generics, because right now I'm using a struct to hold my settings which includes a variable for intVal, floatVal, boolVal... so of course you can imagine a lot of wasted variables there (presumably wasted memory). I thought it would be better to just have a basic generic value to replace the previous 3 (if not more as I grow the game and invent new modifications). Problem is, I'm struggling to get these little guys in a list. List modList = new List(); doesn't work. Of course I can specify the list to be a specific type eg List
I love your stuff, just found this chance a few weeks ago, have you done any working with making UIs work with arrow keys only?? Like if it were an old fashioned computer?
Could you just put IPing everywhere instead of the generic T? like dont use generics and just use the interface? What can generics do that polymorphism cant?
C#: Let's do List.Add(1) Tarodev: Nah, let's do List.Add(69) ha 😏 Edit: Legolas sounded like "Legal Ass" 😮 😂. Not sure if it was intended or just an accent thing. I love his vid (on the educational and comical aspects) PS: excellent content.
Great video! This reminded me of one of the problems I thought could be solved using generics but I couldn't. Imagine using ScriptableObject architecture similar to the one described in Unity learn videos, where you store your variables as IntVariable, FloatVariable SOs and reference them in your classes. Now lets imagine UpgradeData class which would have to take either of thees types as a single variable - UpgradeValue. But you can't do that with generics because you have to define type at compile time. Any ideas on how to solve this? Not much info on the internet.
In this case, Isn't shorter and more clear to just write this: (below)? I get this is just an example but I'm asking because maybe I'm missing something here. void PingMap(IPing ping) { ping.PingMap(); } When I found generics and started refactoring my code to include them, I swear I removed at least 400 lines of code from the hole project limao
You're absolutely right haha. That's why in editing I added that disclaimer about it being an advertisement for interfaces and not generics. Sometimes when you wing a segment it turns out sub-par lol. Hopefully it taught some people about the power of interfaces, at least...
If the IPing instance was a struct it would be boxed when passed into the method with an interface as a parameter. The generic version would not. Not particularly to do with this example but more broadly: The generic version could also be modified to add more constraints with little issue, whereas the interface version would require creating more structures to constrain further. Generics also allows methods to return the exact type a method is constrained to.
@@vertxxyz Thanks for detailing that. I strongly debated including the performance benefits of avoiding boxing, but chose to leave it out and keep the content strictly functional based.
Hey thanks a lot for this, am a bit late to the party but i have an offtopic question, what is that "Program.cs" and how is it getting executed while being "naked" like that, there is no class declaration in it or anything, it just runs ? I was really surprised when that first Print worked lol, so can someone please point me toward the light here xD
Hey brother, haven't seen you around recently. It's the new top level statements. The goal was making it simpler for new c# devs and not blasting them with a bunch of concepts in the boilerplate. Here's a link: learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements
In .net 6 you can now remove the standard boilerplate and write directly in the top level! It also has default imports of commonly used namespaces so it doesn't crowed your scripts 😊
In this case, probably cause it was just an easy example, but it's kinda a personal preference thing. Sometimes the property makes sense, sometimes the generic makes sense. It's a way to differentiate between a "is a" relationship and a "has a" relationship to. With generics you can say: "this is a Warrior Hero Helper" instead of "this is a hero helper that has a warrior" So it helps organize things. One thing he didn't cover is that generics can be used with implementations of an interface too, as an example, if you had heros, enemies, and puzzle blocks, and you wanted to save their in-game locations, instead of making them all inherit from a "baseUnit" you can have them implement a "ISaveable" and pass them to a "SaveHelper where T is ISaveable" and the save helper could manage saving all your game data without caring about inheritance structure. There are, of course, other ways of doing this, but it's one tool in the belt and is good to know as an option.
@@restushlogic5794 Inline open-braces are not "for professionals" - they're just a preference, and they don't change anything about the code's logic. This: void Method() { //code } Is exactly the same as this: void Method() { //code } It really doesn't reduce readability. You can tell when a block scope ends by the closing curly-brace in either style.
Challenge accepted. I'm gonna make a game where you control a chair. It will be a idle, timing game where you're goal is to wait until someone is about to sit on you, then duck out at the last minute to make them fall on their heads, awarding you blood to spend on chair upgrades, Increasing your "bps" blood per second. Eventually, your chair will be so amazingly appealing that peeple will be flocking to your cushion by the thousands and tens of thousands and single chairleggedly, you can cause the mass extinction of the human race.
@@Tarodev each class should have branching upgrades that are almost virtually unobtainable without microtransactions, the stools legendary version should look like "poop in a cup" 🤣
Once I started getting sponsored by unity I thought I'd clean up the titles a bit. I'll keep my in video personality the same though 😊 Glad you appreciated my immature humour though
@@Tarodev oh, it's understandable, i think getting sponsored makes people more "decent" lol, but i'm glad you're keeping the personality, reading about putting things inside you made me laugh too, so i guess i share the same immature humor XD but those kind of silly jokes gives you more personality and makes the video a bit more didactic? i think :)
using ConsoleApp1; var warrior = new Warrior() { Name = "Warrior", Damage = 100, }; var helper = new HeroHelper(warrior); helper.Print(warrior); warrior.Attack(); namespace ConsoleApp1 { internal class HeroHelper where T : Hero { public T Data; public HeroHelper(T data) { Data = data; } public void Print(T input) { Console.WriteLine(input); } public void ForceAttack() { Data.Attack(); } } } public abstract class Hero // Base class { public int Damage; public string? Name; public void Attack() { Console.WriteLine($"{Name} did {Damage}pts of damage."); } } public class Mage : Hero { } public class Warrior : Hero { } public class Archer : Hero { }
The complete guide is not "completely" accurate... I have a problem I can not figure out. I have a class that takes an emun like this: public class CpuInfo where T: System.Enum { public T status; // T is an enum with [FLAG] attribute public void SetStatus(T stat) { // This is not possible - why? (but is possible to do instantiatedCpuInfo.status = instantiatedCpuInfo.status | stat; from outside the class) // status = status | stat; // Equal operator works // status = stat; } // .... removed ..../ } If I instantiate the class with this enum: [Flags] public enum CpuStatus { None = 0b_0000_0001, CPU1Running = 0b_0000_0010, CPU2Running = 0b_0000_0100, CPU1Paused = 0b_0000_1000, CPU2Paused = 0b_0001_0000, CPU1Halted = 0b_0010_0000, CPU2Halted = 0b_0100_0000 } Instantiated by: var cpuInfo = new CpuInfo(); Then I perform: cpuInfo.status = cpuInfo.status | CpuStatus.CPU1Halted; It works... I can not figure out what I am misunderstanding about the generic classes... Any suggestions?
It was explained very well, thank you. Also, it looks like c# attributes are poorly covered on UA-cam, please can you make a tutorial about them? 🙂
I'd been looking to do some more research into generics so this hit at the right time mate! Also, sick thumbnail
A man who appreciates the art of thumbnails ❤
I am very impressed!!!! How you teach complex topic that even a begginner would understand and a pro would finally comprehend!
Great tutorial for beginners!.
It misses few concepts that are important to talk about when teaching generics:
- What is the difference between T and object - Why not use ArrayList?
- What is a generic type T - How it's essentially different than a regular class type (Like array of objects?)
This is a good point to talk about meta-programming, How a generic type looks under the hood.
- covariance and contravariance in generic programming.
A good place to look at will be Clr via C#, explains very well what is a type and a generic type.
This is the topic where I learnt in school and forget thinking I may not need it.
However it does fit in the need of fundamentals
Aside from the factory, the examples provided do not display re-usability as explained since re-usability is already provided by the Hero generic class inheritance or the ping interface.
You can just have a HeroHelper with a non-generic Hero data type and it will do exactly the same but your code will even be clearer..
Generics really shine when you need to handle elements of various types all together or when you want to define behaviors that do not depend on the type. So if you use where T:WhateverType and define behaviors based on WhateverType, it's fine but you do not need generics.
Example : You have a generic class Selection handling player's selection of an item. This Selection does require a type T since it will trigger an event with its T data upon selection (since you need to now who fired the event).
Now let's say i want that behavior on an Item & on a button : Just declare UIItem : Selection & UIButton : Selection and hook up its selection event and that's it.
(and this is an inheritance example but it works just the same by composition).
For so long I've been looking at generics and failing to understand how and when to use it. I always had a feeling that I needed to use (or would be useful) but never could figure it out. You've explained it so simply that it just makes perfect sense to me now. Thank you! :)
Great explanation, thank you, I've stumbled upon some videos about generic functions, and the guys keep theoreticising about generics without explaining it deeply in this manner
This is the explanation I am looking for. Thank you so much.
Big thanks. Never before did I understood those as well!
Great video! one point i would have added is how generics work with inheritance. So you could also make a class WarriorHelper : HeroHelper if you wanted to add a function that is specific to warriors.
This is also valuable for working with generics in monobehaviours in unity, as you dont create monobehaviours by their constructor and cant add a monobehaviour with a generic type as component.
just found out about your channel from a certain video that has absolute random numbers as examples and I must say I'm really digging into your clean video format, deep explanation and occasional dad jokes. Subbed and will hope for the channel to blow up soon.
Pure random numbers ;)
Just wow. TY I like the explanation. You have made my day! I can't explain how this makes me so happy! I was looking for an explanation of this for while. It is explained so well and I can immediately apply it.
That's what I like to hear 😊
Eggcellent video, quite informative. If you may, could you drop the bgm in future videos, or try with a less intrusive theme? It gets quite annoying after a while when using headphones, thank you.
Look at you Mr. Fancy Pants with your C# 10 & VS 2022. I can't wait until Unity catches up some. Of all the new features, I oddly think the file-scoped namespace is going to be my favorite. Tabbing an entire class for nothing more than a namespace makes my OCD tingle.
I especially like it for videos as it keeps boilerplate away and allows people to focus purely on the content. This is magnified for new devs who have only experienced unity and never created a console app, static void main could be confusing.
i was going over few Tutorial in generic and depress a bit.. this one click me :) right explanation :)
I win!
I've smashed that like. You were extremely helpful in assisting to understand Generics and also many other topics which you've shown unknowingly. 😊
Thanks for the like buddy 🙏
Hey! I recently found your channel and must say this channel is blessing. Also your art style is fooking awesome, it would be a another blessing if you do that kind of art tutorials
I'm honoured you would like me to do an art video, but I absolutely feel like an imposter in the art world. Are you talking about all the little mascots I drew?
fantastic and straight-forward explanation. thanks man :)
your videos are very good, they are helping me a lot in the creation processor of my game.
I spent 1 year studying to be able to make a game, now with some of your videos I managed to progress much faster.
if I made a video showing my project would you see? I'm sure you'll be surprised by my idea.
These are the comments which make me feel good about what I'm doing. Yes I'd love to see your work
I wish I could double thumbs up this. I’ve read through the definition of generics and interfaces. I’ve written them out in my own code. But I never fully understood them until seeing the examples you had here. This explained so many of the things I haven’t quite mastered in C#. I feel so much more powerful now! But seriously thank you for this!
Best Tutorials on the net xD
Thank you so much for sharing this, it's clear as, I will try to implemented in a more practical way to review the concept~cheers~
Really enjoyed. Would love to jump into game programming.
We'd love to have you 😊
Thanks!
Phenomenal video, keep up the great work man!!
Can you please do a playlist focused on core C#? It'd be so helpful
Great stuff! You taught me so much in very little time! Thank you.
Dude, thank you! Well put and understandable.
Thanks Taro, for C# Generics today I learned more from you👏[Battle King
I love your videos, i know much of the stuff in it but the small details and tips you add make them very cool. thanks for sharing your knowledge :D
Glad you like them!
Put baby in me
- Anything
Why you are using
void PingMap(T inputObject) where T : IPing{}
if you can use the way w/o generics
void PingMap(IPing inputObject){}
?
Great tutorial, thanks for good explanation
Can you make a video about Quaternions and Rotation?
Everything about this is so great, really nice and relevant topics!
Gamifying anything makes it fun to learn. Imagine if we earned experience ironing our clothes, or washing the dishes. You better believe I'd be a level 80 ironer. But in reality, I've ironed once in my entire life lol.
@@Tarodev i feel you, gamification can be a strong asset
This video is probably informative if you started coding 5 minutes ago. But its too rudimentary for anyone else.
@@RealisiticEdgeMod I mean yeah... I don't think the purpose of the video was to make you an expert on generics, but a lot of people might not have know about them or how to use them properly. I'm pretty new to coding and even though I knew about generics I found the video very helpful for clarifying and expanding upon my knowledge.
You got me with "Legolas" :D Was thinking the same. What other archers are out here in movies? Hawkeye from Marvel?
It's a short roster
I love your titles! :D
Hope I'm not pushing it a bit far with this one, lol
great work keep going
May i suggest, when you are walking us through code, can you please zoom in a little for code to be more visible. Thanks.
Ps: love your tutorials.
You always make very interesting and well explained videos! You do great work! I always learn something new! Thank you!
HEY! Love your stuff! What are the smooth jams you got runnig in the background???
I've slowly compiled a bunch of royalty free tracks over time. Glad you enjoyed them 😊
If you really want I can host them for you
Excellent tutorial about generics, we are very lucky that you share this stuff with us sir.
I would love if possible that you give some hints on the best architecture for a videoadventure where objects unlock dialogues and areas, and also depending on the answers given to a certain NPC, this propagates to the branching dialogues of not only this but ther NPC in the world but currently not in the scene, affecting the main storyline and the behavours of those NPCs towards the main character. I don't know what would be the best way to handle such complexity with so many NPCs, dialogues and object triggers affected. If I think of events and listeners, won't the code end up with lots of conditionals. Is there a cleaner way to do this?
Lmao the discord plug, love it!
And did it work...? Will I see you in there? 😉
Useful stuff, and when it comes to archers, then there is the hooded man ;)
Tarodev amazing videos brah keep it up its so fun to watch also teaches a lot ^^
Thank you
This was perfect
Very informative. Thanks!
On the other hand, I don't see the point of the HeroHelper class: you have to create a helper for each hero, and using ForceHeroToAttack is not easier or more flexible than using Attack? In addition, we manage 2 variables: the hero and his helper. I must have missed something ... We can define the Attack method as virtual and overload it in the child classes.
I also do not see the point of increasing the code with HeroFactory compared to the use of constructors :
- with constructor : Mage mage = new Mage ("Gandalf", 100);
- with HeroFactory : Mage mage = HeroFactory ("Gandalf", 100);
Also, if we want to have a different behavior from the mage (for example a mana field used by each attack), I have not succeeded in simply modifying HeroFactory.
In that case you will need a generic class that implements IAttack, and now you can send there Archers, Mages, Warriors who need to know how to attack (for example the mage uses mana, the warrior uses fury, etc) but the implementation is inside every singular class
Love your dummy data :) print(420) all day long!!
Amazing thank you.
ok, very nice, but how to make a Factory which can get parameters for all kind of Heros ?
soon your channel will have many many subs! maybe 100k? 200k? 1mil and even more.... I have gone into the past and watched each video..
You're here in the early days. A true original gansta 😉
Hahaha title is pog
When should I use generics?
thanks for this tutorial, really clear, as usual !
Okay so I finally came to convert my mod system to use generics, because right now I'm using a struct to hold my settings which includes a variable for intVal, floatVal, boolVal... so of course you can imagine a lot of wasted variables there (presumably wasted memory). I thought it would be better to just have a basic generic value to replace the previous 3 (if not more as I grow the game and invent new modifications). Problem is, I'm struggling to get these little guys in a list. List modList = new List(); doesn't work. Of course I can specify the list to be a specific type eg List
You had me @ dark souls
Genetics generates a function for each type it gets used if I remember correctly right? Kinda like syntactic sugar
I love your stuff, just found this chance a few weeks ago, have you done any working with making UIs work with arrow keys only?? Like if it were an old fashioned computer?
Could you just put IPing everywhere instead of the generic T? like dont use generics and just use the interface? What can generics do that polymorphism cant?
Generics is more performant as it doesn't require boxing and unboxing. Too much to type here but google unboxing. Good question 😉
Great !
title gore, but *very* good video taro, i learned alot about generics, there were a few "AHA!" moments for me, thank you!
That's EXACTLY what I was trying to achieve!
C#: Let's do List.Add(1)
Tarodev: Nah, let's do List.Add(69) ha 😏
Edit: Legolas sounded like "Legal Ass" 😮 😂. Not sure if it was intended or just an accent thing. I love his vid (on the educational and comical aspects)
PS: excellent content.
Great video! This reminded me of one of the problems I thought could be solved using generics but I couldn't. Imagine using ScriptableObject architecture similar to the one described in Unity learn videos, where you store your variables as IntVariable, FloatVariable SOs and reference them in your classes. Now lets imagine UpgradeData class which would have to take either of thees types as a single variable - UpgradeValue. But you can't do that with generics because you have to define type at compile time. Any ideas on how to solve this? Not much info on the internet.
The wrongness in this title is just perfect 👌 🤣
Adding 69.. Man of culture.
I'm just realizing now how many adult references I packed into this video...
@@Tarodev well there is 420 too..
@@TheKr0ckeR completely random number sir
im failing to understand the herohelper? why create a herohelper of type warrior that inherits from hero? In a game, what is herohelper?
In this case, Isn't shorter and more clear to just write this: (below)? I get this is just an example but I'm asking because maybe I'm missing something here.
void PingMap(IPing ping)
{
ping.PingMap();
}
When I found generics and started refactoring my code to include them, I swear I removed at least 400 lines of code from the hole project limao
You're absolutely right haha. That's why in editing I added that disclaimer about it being an advertisement for interfaces and not generics. Sometimes when you wing a segment it turns out sub-par lol. Hopefully it taught some people about the power of interfaces, at least...
@@Tarodev Haha it's fine! Thank you for the work that you are doing!
If the IPing instance was a struct it would be boxed when passed into the method with an interface as a parameter. The generic version would not.
Not particularly to do with this example but more broadly:
The generic version could also be modified to add more constraints with little issue, whereas the interface version would require creating more structures to constrain further.
Generics also allows methods to return the exact type a method is constrained to.
@@vertxxyz Thanks for detailing that. I strongly debated including the performance benefits of avoiding boxing, but chose to leave it out and keep the content strictly functional based.
My man what is the background music :P
Hey thanks a lot for this, am a bit late to the party but i have an offtopic question, what is that "Program.cs" and how is it getting executed while being "naked" like that, there is no class declaration in it or anything, it just runs ? I was really surprised when that first Print worked lol, so can someone please point me toward the light here xD
Hey brother, haven't seen you around recently.
It's the new top level statements. The goal was making it simpler for new c# devs and not blasting them with a bunch of concepts in the boilerplate. Here's a link: learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements
I think this tutorial got recommended to me cause you used dark souls as an example
really useful! thanks!! also got a good laugh out of "nipplebutts" hahah
How did your code run without a Main method?
In .net 6 you can now remove the standard boilerplate and write directly in the top level! It also has default imports of commonly used namespaces so it doesn't crowed your scripts 😊
Why make the HeroHelper generic? Couldn't it just have a property of type Hero instead of T?
In this case, probably cause it was just an easy example, but it's kinda a personal preference thing. Sometimes the property makes sense, sometimes the generic makes sense.
It's a way to differentiate between a "is a" relationship and a "has a" relationship to. With generics you can say: "this is a Warrior Hero Helper" instead of "this is a hero helper that has a warrior"
So it helps organize things. One thing he didn't cover is that generics can be used with implementations of an interface too, as an example, if you had heros, enemies, and puzzle blocks, and you wanted to save their in-game locations, instead of making them all inherit from a "baseUnit" you can have them implement a "ISaveable" and pass them to a "SaveHelper where T is ISaveable" and the save helper could manage saving all your game data without caring about inheritance structure.
There are, of course, other ways of doing this, but it's one tool in the belt and is good to know as an option.
The title lol
Thanks kiwi Matt Walsh
Aussie* And also, that's the first time I've been compared to him 😅
why no one is taking about the 69 and 420 perfectly used?
I think everyone agrees that we need more *generic* tutorials outside of the usual game dev ones.
(HAH!! see what i did there !?)
Please use bracket like this. It would be help for a newbie dev.
{
//code
}
@Dyanosis yes, that's for professional. Many asset on Unity use the non-in line bracket. It is easy to read the code for everyone.
@@restushlogic5794 Inline open-braces are not "for professionals" - they're just a preference, and they don't change anything about the code's logic.
This:
void Method() {
//code
}
Is exactly the same as this:
void Method()
{
//code
}
It really doesn't reduce readability. You can tell when a block scope ends by the closing curly-brace in either style.
@@Dxpress_ I don't understand
Challenge accepted. I'm gonna make a game where you control a chair. It will be a idle, timing game where you're goal is to wait until someone is about to sit on you, then duck out at the last minute to make them fall on their heads, awarding you blood to spend on chair upgrades, Increasing your "bps" blood per second.
Eventually, your chair will be so amazingly appealing that peeple will be flocking to your cushion by the thousands and tens of thousands and single chairleggedly, you can cause the mass extinction of the human race.
Time to get rid of all of the chairs in my house before they rise up against me. Thanks for the warning pal
@@libberator5891 anytime. Here all day
@Dyanosis all day. Every day. 😜
You'll need starting classes... Recliner, stool, etc
@@Tarodev each class should have branching upgrades that are almost virtually unobtainable without microtransactions, the stools legendary version should look like "poop in a cup"
🤣
heyyy why did you changed the funny name?
Once I started getting sponsored by unity I thought I'd clean up the titles a bit. I'll keep my in video personality the same though 😊
Glad you appreciated my immature humour though
@@Tarodev oh, it's understandable, i think getting sponsored makes people more "decent" lol, but i'm glad you're keeping the personality, reading about putting things inside you made me laugh too, so i guess i share the same immature humor XD but those kind of silly jokes gives you more personality and makes the video a bit more didactic? i think :)
using ConsoleApp1;
var warrior = new Warrior()
{
Name = "Warrior",
Damage = 100,
};
var helper = new HeroHelper(warrior);
helper.Print(warrior);
warrior.Attack();
namespace ConsoleApp1
{
internal class HeroHelper where T : Hero
{
public T Data;
public HeroHelper(T data)
{
Data = data;
}
public void Print(T input)
{
Console.WriteLine(input);
}
public void ForceAttack()
{
Data.Attack();
}
}
}
public abstract class Hero // Base class
{
public int Damage;
public string? Name;
public void Attack()
{
Console.WriteLine($"{Name} did {Damage}pts of damage.");
}
}
public class Mage : Hero
{
}
public class Warrior : Hero
{
}
public class Archer : Hero
{
}
🤣🤣🤣🤣
and then people make fun of JavaScript because its "confusing"
thx , it war very useful
The complete guide is not "completely" accurate... I have a problem I can not figure out.
I have a class that takes an emun like this:
public class CpuInfo where T: System.Enum
{
public T status; // T is an enum with [FLAG] attribute
public void SetStatus(T stat)
{
// This is not possible - why? (but is possible to do instantiatedCpuInfo.status = instantiatedCpuInfo.status | stat; from outside the class)
// status = status | stat;
// Equal operator works
// status = stat;
}
// .... removed ..../
}
If I instantiate the class with this enum:
[Flags]
public enum CpuStatus
{
None = 0b_0000_0001,
CPU1Running = 0b_0000_0010,
CPU2Running = 0b_0000_0100,
CPU1Paused = 0b_0000_1000,
CPU2Paused = 0b_0001_0000,
CPU1Halted = 0b_0010_0000,
CPU2Halted = 0b_0100_0000
}
Instantiated by:
var cpuInfo = new CpuInfo();
Then I perform:
cpuInfo.status = cpuInfo.status | CpuStatus.CPU1Halted;
It works...
I can not figure out what I am misunderstanding about the generic classes...
Any suggestions?