Why you should clean your code with Extension Methods!

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ต.ค. 2024

ความคิดเห็น • 54

  • @KirbyGC00
    @KirbyGC00 6 ปีที่แล้ว +50

    +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 =).

  • @thinkofwhy
    @thinkofwhy 6 ปีที่แล้ว +52

    Nullable & assignable parameters? Cool, thanks. Had no idea.

    • @beardordie5308
      @beardordie5308 6 ปีที่แล้ว +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 ปีที่แล้ว +4

      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 ปีที่แล้ว +1

    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 ปีที่แล้ว +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 ปีที่แล้ว +3

      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 ปีที่แล้ว +1

    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!

  • @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.

  • @ludovicmahieu8278
    @ludovicmahieu8278 3 ปีที่แล้ว +1

    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

  • @baroquedub
    @baroquedub 6 ปีที่แล้ว +11

    I always learn so much watching your videos! Thank you

  • @brandobin
    @brandobin 6 ปีที่แล้ว +1

    Thank you so much! I've been coding for like a decade and never learned about nullable parameters. Extension methods are pretty cool too.

  • @youcancallmedoggie
    @youcancallmedoggie 3 ปีที่แล้ว

    Been looking for something like this since I started my game development journey.. Thank you so much!!

  • @stefano4993
    @stefano4993 6 ปีที่แล้ว +1

    A lot of useful little tools in one video. Thank you!

  • @kuraikage15
    @kuraikage15 5 ปีที่แล้ว +2

    Learned a lot of new things here. Thanks!!

  • @Defectoms
    @Defectoms 4 ปีที่แล้ว

    Wow, this is quite a few things I did not know about C# Thanks a lot!

  • @andread4721
    @andread4721 3 ปีที่แล้ว

    Fantastic! Thank you so much, Jason!

  • @victorlee98
    @victorlee98 6 ปีที่แล้ว +4

    Thank you very much. I hope u release more video like this. It's very helpful

  • @deepshipalpha3861
    @deepshipalpha3861 3 ปีที่แล้ว

    This is so cool! Now I shudder at all the refactoring I probably should be doing..

  • @piyushmayekar1192
    @piyushmayekar1192 5 ปีที่แล้ว

    You deserve a lot more subs & views than you already have!!!

  • @TsetTsyung
    @TsetTsyung 6 ปีที่แล้ว +1

    Once again, an awesome vid on a subject that's on my 'To Study' list. Thank you so much! XD

  • @andrieskruger9826
    @andrieskruger9826 6 ปีที่แล้ว +1

    This was great! Thanks Jason.

  • @zekiozdemir420
    @zekiozdemir420 2 ปีที่แล้ว

    I didn't know this. Thank you!

  • @jandd661
    @jandd661 6 ปีที่แล้ว +3

    Great video! thank you! I really like the idea of a resource repository. Though I'm afraid it would make me lazy ;)

  • @TChrisBaker
    @TChrisBaker 6 ปีที่แล้ว +4

    thanks this was totally new to me. Very cool

  • @GerOB1988
    @GerOB1988 3 ปีที่แล้ว

    Thank you for this!

  • @SaiPrashanthNS
    @SaiPrashanthNS 6 ปีที่แล้ว +3

    Awesome feeling power :)
    Nullable and assignable parameters awesome
    Do more programming standard videos wrt to gaming..
    Thanks cheers

  • @MecegguemMohamed
    @MecegguemMohamed 6 ปีที่แล้ว +1

    Can you make a video on event using Action Delegate of the namespace system; Event ,EventHandler, EventArgs

  • @NemesisTWarlock
    @NemesisTWarlock 4 ปีที่แล้ว

    Mind. Blown.

  • @beardordie5308
    @beardordie5308 6 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

      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?

  • @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);
    }
    }

  • @SpLineFx
    @SpLineFx 6 ปีที่แล้ว +2

    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 ปีที่แล้ว +5

      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 :)

  • @sebasuchiha2483
    @sebasuchiha2483 5 ปีที่แล้ว

    you are a genius !!!

  • @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.

  • @jaydstein
    @jaydstein 11 หลายเดือนก่อน

    How do I unit test these extension methods?

  • @greenworld5918
    @greenworld5918 6 ปีที่แล้ว +3

    i use Extension Method , and its cool.. hehe :-)

  • @Songfugel
    @Songfugel 4 ปีที่แล้ว +1

    The real question of this video is, why doesn't color class have to hex baked in! xD

  • @billmolloy2264
    @billmolloy2264 5 ปีที่แล้ว

    thank fupp for unity3dcollege

  • @albarnie1168
    @albarnie1168 6 ปีที่แล้ว +1

    Nice video, mic has too much gain. turn down the gain and turn up the bass

  • @vib3rationalOwOs
    @vib3rationalOwOs 6 ปีที่แล้ว +2

    return BillionThanks * Mathf.Infinity;