Why you should clean your code with Extension Methods!

  Рет қаралды 16,318

Jason Weimann (GameDev)

Jason Weimann (GameDev)

Күн бұрын

Пікірлер: 53
@KirbyGC00
@KirbyGC00 6 жыл бұрын
+Unity3d College, Your expertise in computer science and game development clearly shows in every video. I haven't seen this level of competence in any other tutorial/educational series for game development. Thanks so much for sharing years of hard work and knowledge with those of us just starting out =).
@Unity3dCollege
@Unity3dCollege 6 жыл бұрын
thx :)
@thinkofwhy
@thinkofwhy 6 жыл бұрын
Nullable & assignable parameters? Cool, thanks. Had no idea.
@beardordie5308
@beardordie5308 6 жыл бұрын
I assume those would require the newer compiler version, which is fine. They are handy for sure. I never saw ?? before. Neato.
@Unity3dCollege
@Unity3dCollege 6 жыл бұрын
Those work fine w/ the old .net profile :)
@ZOMBIEBUST3R
@ZOMBIEBUST3R 5 жыл бұрын
I had no idea either. It came in clutch 'cuz I needed something like this but didn't know it existed
@brodieeli5653
@brodieeli5653 3 жыл бұрын
You probably dont care but if you're stoned like me atm you can watch pretty much all of the latest movies and series on InstaFlixxer. I've been binge watching with my girlfriend during the lockdown :)
@pj-wille
@pj-wille 2 жыл бұрын
Though it may be a very long time before I can afford your course, I'm glad you have so much useful content on youtube for free. Really saves people like me who want to get into game dev but just don't have spare cash. Thank you a ton.
@AlbertoFdzM
@AlbertoFdzM 6 жыл бұрын
This is amazing! I've come from JS and I'm losing a lot of stuff to learn in my way to Unity3D and C#. Your videos are helping me a lot, keeping apart the basics and diving into good practices, game dev patterns and a lot of medium and senior stuff I couldn't find anywhere else. Thanks a lot for your videos.
@Unity3dCollege
@Unity3dCollege 6 жыл бұрын
thank you :) glad to hear they're helpful! :)
@Frank_G_Finster
@Frank_G_Finster 4 жыл бұрын
For a total coding beginner like me, that was really helpful. Explained very clear and presented with easy to follow examples. Thank you very much, it will be put to good use.
@woodenfences
@woodenfences 3 жыл бұрын
Very useful! It is this basic-to-intermediate stuff which I find most helpful as I am still learning C# and Unity. That transform.position.y = someFloat was the perfect example I could relate to! Big thanks!
@ludovicmahieu8278
@ludovicmahieu8278 4 жыл бұрын
Nullable & assignable parameters? I was like 'wooooo magic code' :D you're standing above the crowd of all tutorials I've ever seen in each videos
@digitalconsciousness
@digitalconsciousness 3 жыл бұрын
I have watched several of your videos now and am really liking stuff like this. Always wanted to know how to do this because using multiple classes / extension methods / state managers to split my code up has always been my biggest weak point.
@baroquedub
@baroquedub 6 жыл бұрын
I always learn so much watching your videos! Thank you
@bissash103
@bissash103 6 жыл бұрын
same
@Unity3dCollege
@Unity3dCollege 6 жыл бұрын
You're very welcome! Thanks :)
@brandobin
@brandobin 6 жыл бұрын
Thank you so much! I've been coding for like a decade and never learned about nullable parameters. Extension methods are pretty cool too.
@stefano4993
@stefano4993 6 жыл бұрын
A lot of useful little tools in one video. Thank you!
@youcancallmedoggie
@youcancallmedoggie 3 жыл бұрын
Been looking for something like this since I started my game development journey.. Thank you so much!!
@kuraikage15
@kuraikage15 6 жыл бұрын
Learned a lot of new things here. Thanks!!
@victorlee98
@victorlee98 6 жыл бұрын
Thank you very much. I hope u release more video like this. It's very helpful
@andread4721
@andread4721 3 жыл бұрын
Fantastic! Thank you so much, Jason!
@piyushmayekar1192
@piyushmayekar1192 5 жыл бұрын
You deserve a lot more subs & views than you already have!!!
@Defectoms
@Defectoms 4 жыл бұрын
Wow, this is quite a few things I did not know about C# Thanks a lot!
@TChrisBaker
@TChrisBaker 6 жыл бұрын
thanks this was totally new to me. Very cool
@andrieskruger9826
@andrieskruger9826 6 жыл бұрын
This was great! Thanks Jason.
@TsetTsyung
@TsetTsyung 6 жыл бұрын
Once again, an awesome vid on a subject that's on my 'To Study' list. Thank you so much! XD
@MecegguemMohamed
@MecegguemMohamed 6 жыл бұрын
Can you make a video on event using Action Delegate of the namespace system; Event ,EventHandler, EventArgs
@deepshipalpha3861
@deepshipalpha3861 3 жыл бұрын
This is so cool! Now I shudder at all the refactoring I probably should be doing..
@zekiozdemir420
@zekiozdemir420 2 жыл бұрын
I didn't know this. Thank you!
@jandd661
@jandd661 6 жыл бұрын
Great video! thank you! I really like the idea of a resource repository. Though I'm afraid it would make me lazy ;)
@NemesisTWarlock
@NemesisTWarlock 4 жыл бұрын
Mind. Blown.
@GerOB1988
@GerOB1988 3 жыл бұрын
Thank you for this!
@jaydstein
@jaydstein Жыл бұрын
How do I unit test these extension methods?
@SpLineFx
@SpLineFx 6 жыл бұрын
Nullable and assignable parameters are great, thanks! But why do we need these extension methods? I still can't get it. We could just write our own class called Utilities or something. With extension methods you may return to your code after some time and completely forget that you wrote something for Transform or Color class, you can search help file for these new methods, etc. As for me, it's just a trick for a trick, some sugar, nothing more.
@Unity3dCollege
@Unity3dCollege 6 жыл бұрын
You definitely could, there's nothing wrong w/ that at all. That's actually what I used to do before extension methods were introduced. The main difference I've found is just with discoverability, when the extension methods are used, it looks like part of the class/struct, and it pops up for intellisense, so other people on the team are more likely to realize it exists and use it (instead of writing duplicate code). Outside that though, there's no technical difference :)
@SaiPrashanthNS
@SaiPrashanthNS 6 жыл бұрын
Awesome feeling power :) Nullable and assignable parameters awesome Do more programming standard videos wrt to gaming.. Thanks cheers
@furkankocak3142
@furkankocak3142 3 жыл бұрын
Here is a similar extension directly for Transform class: You can basically do the same thing in the video with only writing transform.With(y:0); instead of transform.position = transform.position.With(y:0); public static class TransformExtension { public static void With(this Transform original, float? x = null, float? y = null, float? z = null) { original.position = new Vector3(x ?? original.position.x, y ?? original.position.y, z ?? original.position.z); } }
@beardordie5308
@beardordie5308 6 жыл бұрын
I'd love to see a list of the most useful and/or commonly used extension methods for Unity developers. A set I commonly use at least in 2d projects extends the transform class with methods IsLeftOf, IsRightOf, IsBelow, IsAbove, and includes an optional tolerance parameter which makes those a lot more versatile. Here those are: gist.github.com/beardordie/0d24c1e64e88f71b2167b336afd5ae78
@beardordie5308
@beardordie5308 6 жыл бұрын
Correction: those I linked to extend the GameObject class, but one could easily adapt it to extend the transform class instead. I just found it handier to make direct reference to the gameObjects themselves.
@billmolloy2264
@billmolloy2264 5 жыл бұрын
bumpty bump bump
@Nova04550
@Nova04550 3 жыл бұрын
So your extension class doesn't need to be referenced? Like for example by existing on a GameObject and then looking for that GameObject? Does this mean the method is deriving from MonoBehaviour? **EDIT** So I did some more research and understand static methods better. So when you set up a static method in Unity, can that be called any time so long as the class definition exists somewhere in your assets?
@ericbeaulieu419
@ericbeaulieu419 3 жыл бұрын
Hey guys, I'm wondering if there was a way of further cleaning this up. It works at the end of the day but I'm being nitpicky. I'd say this falls in relation to the vector3.flat that you created in the video Right now I'm trying to create a color extension method that resets the alpha. I also have one that sets the alpha and you pass it a float that works the same way. using UnityEngine; public static class ColorExtensions { public static Color ResetAlpha(this Color original) { return new Color (original.r,original.g,original.b,1); } } and then here's the code for the item implementing that method. hudBackground.color = hudBackground.color.ResetAlpha(); What im asking is there a way of further cleaning this up so instead of that extra bit it ends up looking like hudBackground.color.ResetAlpha();. So essentially taking out the return. I tried this a bit playing around with it but essentially I just want to set the alpha to 1 and that's it without a return but when I try to set it doesn't exist. Jason if you can put some insight on this id love it. Thanks in advance
@NadjibBait
@NadjibBait 3 жыл бұрын
The explanation is simple. You need to learn the difference between reference type and value type objects. Color is a value type object, and value types are immutables, which means that their value cannot be changed. To change it you need to create a new object literally. Value types examples: numbers (int, float...etc), bool, char and structs. Color is a struct, like Vector2/3.
@Songfugel
@Songfugel 4 жыл бұрын
The real question of this video is, why doesn't color class have to hex baked in! xD
@sebasuchiha2483
@sebasuchiha2483 5 жыл бұрын
you are a genius !!!
@albarnie1168
@albarnie1168 6 жыл бұрын
Nice video, mic has too much gain. turn down the gain and turn up the bass
@greenworld5918
@greenworld5918 6 жыл бұрын
i use Extension Method , and its cool.. hehe :-)
@billmolloy2264
@billmolloy2264 5 жыл бұрын
thank fupp for unity3dcollege
Unity3D Rants - Clean Code, Extension Methods, & State Machines
18:45
Jason Weimann (GameDev)
Рет қаралды 25 М.
Humble Object - Game Programming Patterns in Unity & C# (kinda :)
15:31
Jason Weimann (GameDev)
Рет қаралды 39 М.
Thank you mommy 😊💝 #shorts
0:24
5-Minute Crafts HOUSE
Рет қаралды 33 МЛН
Jaidarman TOP / Жоғары лига-2023 / Жекпе-жек 1-ТУР / 1-топ
1:30:54
БАБУШКА ШАРИТ #shorts
0:16
Паша Осадчий
Рет қаралды 4,1 МЛН
Unity3D Managers vs Controllers
12:06
Jason Weimann (GameDev)
Рет қаралды 58 М.
5 ways to Reference GameObjects in Unity3D
11:49
Jason Weimann (GameDev)
Рет қаралды 133 М.
How & why to use Static Events in Unity3D
11:30
Jason Weimann (GameDev)
Рет қаралды 41 М.
Observer Pattern -  Game Programming Patterns in Unity & C#
18:52
Jason Weimann (GameDev)
Рет қаралды 91 М.
Code Smells - 'Switches' in Unity3d / C# Architecture
25:21
Jason Weimann (GameDev)
Рет қаралды 78 М.
Tools EVERY Software Engineer Should Know
11:37
Tech With Tim
Рет қаралды 24 М.
Unity3D SOLID Principles - Dependency Inversion Principle
15:45
Jason Weimann (GameDev)
Рет қаралды 62 М.
Creating Objects in Unity3D using the Factory Pattern
17:54
Jason Weimann (GameDev)
Рет қаралды 99 М.
The 6 Design Patterns game devs need?
24:20
Jason Weimann (GameDev)
Рет қаралды 375 М.
Thank you mommy 😊💝 #shorts
0:24
5-Minute Crafts HOUSE
Рет қаралды 33 МЛН