Shorter Cleaner Code with Extension Functions - C# and Unity

Поділитися
Вставка
  • Опубліковано 4 жов 2024

КОМЕНТАРІ • 21

  • @geri4367
    @geri4367 3 роки тому +10

    I've never seen this being explained so clearly, so concisely and with such good reasoning behind all the points made throughout the video. Good job and keep it up!

  • @mcgeufer
    @mcgeufer Рік тому

    I make games with Unity for a long time, this thing, I missed so far.
    So this procrastination session was time well spent.

  • @1DrowsyBoi
    @1DrowsyBoi 3 роки тому +4

    One super useful one that I use all the time is a "GetRandom()" method, made for ILists. This way, I can avoid the constant - and tedious- other way of:
    int roll = Random.Range(0, longListName.Count);
    var item = longListName[roll];
    I also made overloads for this, that gives me a list of random elements, being able to set a stale queue (only returns an element once per X minumum other elements have been added), etc.

    • @OneWheelStudio
      @OneWheelStudio  3 роки тому

      I love that idea! Getting random elements get verbose in a hurry!

    • @NowKnownMAWO
      @NowKnownMAWO 2 роки тому +1

      public static T GetRandom(this List list)
      {
      return list[Random.Range(0, list.Count)];
      }

  • @xmetax
    @xmetax 2 роки тому +1

    This is pretty nifty. Thanks 👍

  • @erz3030
    @erz3030 3 роки тому +3

    Very cool stuff! I had no idea this was even possible, and so easily! Cheers

  • @OneWheelStudio
    @OneWheelStudio  3 роки тому +2

    Prefer written tutorials? Here's the blog post for the video: onewheelstudio.com/blog/2021/7/14/c-extension-methods
    Project File: github.com/onewheelstudio/Adventures-in-C-Sharp/tree/main/ExtensionMethods

  • @jugibur2117
    @jugibur2117 3 роки тому +1

    Wow, this is really useful - thanks for posting!

  • @umapessoa6051
    @umapessoa6051 3 роки тому +1

    Nice video, please keep doing more.

  • @syluxdev
    @syluxdev 3 роки тому +1

    Life saver and Useful!!! 😄

  • @asembahra6187
    @asembahra6187 3 роки тому +1

    Thanks for the nice video !

  • @andreybirchenko1767
    @andreybirchenko1767 3 роки тому

    Wow! Thank you so much. You explained it very clearly!

  • @kvskchaitanya4733
    @kvskchaitanya4733 3 роки тому

    Waiting for a video of writing proper managers without singletons.

    • @OneWheelStudio
      @OneWheelStudio  3 роки тому +3

      Events and static functions! But mostly events! :)
      I have at least a dozen managers in my personal project and not a single use of the Singleton Pattern. It's not always a bad pattern, but I think it is mostly used to communicate between managers. A lot of that communication can be done with events that doesn't cause massive coupling of different classes.
      All that said, this could be a cool idea for video! Any problems in particular you've run into? Problems you are trying to solve?

    • @kvskchaitanya4733
      @kvskchaitanya4733 3 роки тому

      @@OneWheelStudio I have used singletons to create managers but it has dependencies as project grow I just want to know if there is proper way of doing it.
      Thank you for the information.

    • @OneWheelStudio
      @OneWheelStudio  3 роки тому +1

      Yeah. That does happen. If you aren’t familiar with it check out the observer pattern - ie events, actions and delegates

  • @_Garm_
    @_Garm_ 3 роки тому +1

    @2:35 i did not get, where you got vectorFloat from: vectorInt = vectorFLoat.TOvector3Int(); could you please elaborate a bit more :)

    • @OneWheelStudio
      @OneWheelStudio  3 роки тому +1

      "vectorFloat" is just a name of a variable of the type Vector3 - just the usual type nothing special. I named it that to try and make a clear separation between the float and integer version of Vector3.

    • @_Garm_
      @_Garm_ 3 роки тому +1

      @@OneWheelStudio Thank you, now i understand :D