Generics in C# and Unity - Do More with Less Code

Generics in C# and Unity - Do More with Less Code

One Wheel Studio

3 года назад

13,217 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@m1g4s
@m1g4s - 14.01.2021 18:48

Wow. Just wow. Probably the best and simplest explanation of generic classes i've seen around. Well done, man!

Ответить
@ACatWithACrown
@ACatWithACrown - 14.01.2021 22:01

I'm more smart now.

Ответить
@djdavidj
@djdavidj - 15.01.2021 19:44

Thank you!

Ответить
@alejmc
@alejmc - 17.01.2021 03:33

I still find it very complicated when the right constraints and interfaces have to be implemented for equality/inequality compares, mathematical functions, etc to work. In my experience generics start very well as an idea but then sometimes I’m met with knowledge needed that I just don’t have yet.
Great example on generics nevertheless, I do like the Pool system and a way to get all of the types from a shape. Can be used for many things, ability systems, collectible items types, etc etc... maybe mix-able with scriptable objects of sorts, to think about.

Ответить
@watercat1248
@watercat1248 - 30.01.2021 19:03

Can i ask you i questions do you work with team or you area solo developer like myself

Ответить
@watercat1248
@watercat1248 - 30.01.2021 19:15

From what i understand the list is samthin very useful but i still don't get it how it works the only thing i understand is i add same type off faction for example cameras but i don't get how the understand which camera or what ever type off faction i want to add?

For example if have 5 camera on my sean how that list knows to which off this cameras is the correct camera

Ответить
@restushlogic5794
@restushlogic5794 - 08.02.2021 13:55

Awesome, thank you!

Ответить
@1DrowsyBoi
@1DrowsyBoi - 20.02.2021 11:22

After watching this video, I went down a rabbit hole. My couple ongoing projects have me CONSTANTLY using the same couple lines of code to pull a random element from a list/array, so after this video I realized I can just make a static class and utilize the new knowledge about generics. Talked about it with a few people in a Discord server and one person hinted that I should go one step further and make it an extension method.

Had no idea what they were, so I looked up them up, and when I figured that out, I had a glorious script that I can keep for future projects too. Even made some overloads for things like returning a list of multiple selections - with the option of also making sure each element is distinct, being able to also input a blacklist, etc. So now I can just use [List Name].SelectRandom().

Extension methods could be a neat video idea too. I'm definitely gonna be exploring them more, but either way, thanks for the video, and leading me to learning several new things!

Ответить
@unclerandy398
@unclerandy398 - 04.03.2021 00:32

Did you create odin?

Ответить
@JackFoz454
@JackFoz454 - 06.03.2021 13:23

These videos are amazing. So far I've watched exactly two, once each. Both times, I've grasped a concept that had eluded me for months of trying with a ton of other sources.

Can't overstate how good it feels to just... understand. You are a wonderful teacher. Thank you.

Ответить
@unityvictor787
@unityvictor787 - 26.03.2021 13:01

Thanks for Tutorial!!

Can you make a Tutorial of AssetBundles Build and Load please?

Ответить
@EpicGamer63637
@EpicGamer63637 - 23.10.2021 11:37

This is the most amazing video I have ever watched on this topic.....

Thanks!

Ответить
@vladisslavss
@vladisslavss - 26.11.2021 22:48

Coool

Ответить
@TheKr0ckeR
@TheKr0ckeR - 13.12.2021 13:34

That's the greatest generics explanation so far! Thank you

Ответить
@forginbits5457
@forginbits5457 - 24.04.2022 16:53

Thank you so much for making these tutorials, incredibly helpful and cristal clear explanations. I just discovered your channel and I guess I'm going to be watching a LOT of your videos. Cheers !

Ответить
@josephramos6939
@josephramos6939 - 27.12.2022 04:31

The way you explain and teach is so helpful to me. Sometimes I watch other content and it takes multiple videos for new programming concepts to sink in, but I understand what you're explaining on the first go-around. Thank you!!

Ответить
@theLegendPiyush
@theLegendPiyush - 06.09.2023 15:53

Underratedd!!!

Ответить
@Director414
@Director414 - 29.10.2023 13:18

Great video, perfect pacing and content. Awesome!! :)
In my own project, I think I might have made it too complicated for myself. I have problem reaching my script via code.

I have my base-weapon-script like this:
public abstract class WeaponBase<T> : MonoBehaviour, IWeapon where T : WeaponDataBase

then my different weapons inherit like this,
public class WeaponStanardProjectile : WeaponBase<WeaponStandardData> (WeaponStandardData being a Scriptable Object that is of different types)..

The problem I'm facing is trying to reach this weapon-script via code, turning the scrip on (when a weapon is picked up, and off then its dropped) . Seem the GetComponent() don't work for generic scripts?

Ответить
@pureatheistic
@pureatheistic - 29.08.2024 13:12

When using inheritance as a form of strongly typed "tags", would it not be better to use an empty interface so as to be able to have more than one "tag" if needed?

Ответить