Add Juice, Polish and Functionality with Unity Event Handlers

Поділитися
Вставка
  • Опубліковано 11 лип 2024
  • Double click, popup menus, dragging UI, dragging scene objects, or maybe an inventory system? All of these are SO MUCH easier to implement with the use of Unity's Event Handlers. They work with UI objects and scene game objects. Plus! They work with Unity's old or new input system. Examples used: IPointerEnter, IPointerExit, IPointerClick, IBeginDragHandler, IEndDragHandler, IDragHandler and more.
    Video Links
    ************
    DoTween: assetstore.unity.com/packages...
    Supported Events Documentation: docs.unity3d.com/Packages/com...
    Events/Actions Video: • Delegates, Events, Act...
    TaroDev DoTween: • DOTWEEN is the BEST Un...
    Support the Channel!
    *******************************
    ► Buy me a coffee: www.buymeacoffee.com/onewheel...
    ► Shop the Unity Asset Store (affiliate): assetstore.unity.com/top-asse...
    ► Become A Channel Member: / @onewheelstudio
    ► Or a Patron: / onewheelstudio
    ► My video and streaming kit: kit.co/onewheelstudio/tutoria...
    ► Buy a Game Design Book: kit.co/onewheelstudio/game-de...
    Video Gear List (Amazon Affiliate)
    ***********************************
    ► Sony A6100 Camera: amzn.to/32logXz
    ► Sigma 16mm 1.4 Camera Lens: amzn.to/3KA4Wr4
    ► GoXLR (audio interface): amzn.to/35dmr03
    ► Shure SM7B Mic: amzn.to/3fNbV1E
    ► Blue Mic Arm: amzn.to/3tHgwdQ
    Neewer Light: amzn.to/3rD8eRv
    Light Softbox: amzn.to/3GUaHgQ
    Neewer RGB Light: amzn.to/3rCTQJ9
    Other Links
    ************
    Discord: discord.onewheelstudio.com
    Twitter: / onewheelstudio
    Devlog: onewheelstudio.com/
    Twitch: / onewheelstudio
    Timestamps
    *************
    0:00 Intro
    0:51 Hover Popup Menu
    13:06 Drag and Drop from UI
    20:38 Double Click
    25:24 Move Scene Objects
    31:41 Dragging UI Objectcs
    37:11 Inventory Basics (!!)
    #GameDevelopment #Unity3D #indiedeveloper

КОМЕНТАРІ • 24

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

    Okay, not sure why I said "Event System" at the beginning... Oops.
    Either way, here's the written tutorial: onewheelstudio.com/blog/2022/4/15/input-event-handlers-or-adding-juice-the-easy-way
    And the code: github.com/onewheelstudio/Adventures-in-C-Sharp/tree/main/Event%20Handlers

  • @steveradtke1308
    @steveradtke1308 2 роки тому +10

    Thank you for putting in the time to make these videos, I know they are not "blowing up" but they are very helpful and informative to those of us who they pertain to.

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

    To have IEventHandler interfaces neatly presented with those super-relevant use case examples all in one place. Way to go, man!!!
    Great job, as usual!

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

    Great vid with some nice use case examples

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

    dude! thanks!

  • @MarekNijaki
    @MarekNijaki 2 роки тому

    Awesome video

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

    10/10

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

    Neat

  • @JawadHussain-od8ie
    @JawadHussain-od8ie Місяць тому

    Great!Can we access these methods like OnBeginDrag,OnDrag without direct clicking on object?
    Click on empty space then dragging mouse on moveable object where OnBeginDrag work

  • @sharat.achary
    @sharat.achary 2 роки тому +2

    Thank you for this wonderful tutorial. Btw one question is it necessary to add "event" before "System.Action"? Please advise.

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

      You don't need to but often it's a good practice to do so.
      The event keyword does not allow assignment statements only += and -= this prevents classes from overriding which classes are subscribed to a delegate. It also prevents other classes from calling "invoke" on the delegate.
      So not needed, but its generally a good idea.
      You can see more about it in this video: ua-cam.com/video/UWMmib1RYFE/v-deo.html

    • @sharat.achary
      @sharat.achary 2 роки тому

      @@OneWheelStudio Thanks, that was good to know. Shared these two videos they are a must.

  • @SRCoder
    @SRCoder 2 роки тому

    Any tips on where to find the documentation on these interfaces? The Unity Scripting Reference doesn't show them! In fact there isn't even any documentation for UnityEngine.EventSystem.

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

      It is a bit tricky to find. You may need to switch to an older version of the documentation at least that's what I noticed.
      I also added a link in the video description to "supported events" which should be a good starting point.
      You can find other links by following the link to the OWS blog in the pinned comment.

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

      @@OneWheelStudio excellent. Thank you.

  • @captainnoyaux
    @captainnoyaux 2 роки тому

    Do you have a way to handle double click without triggering single click ? If you need double click and single click logic on the same gameobject for instance without one interfering with the other.

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

      Hmm. It might depend on EXACTLY what you are trying to do. But I my first attempt would be to put the double click detection BEFORE the single click AND if the double click happens you return or exit the function.
      Would that work?

    • @captainnoyaux
      @captainnoyaux 2 роки тому

      @@OneWheelStudio yeah probably! I tried to do it with the new input system too but it complicated too much the code base, plus you add delay on all calls :/, I never found a correct solution to that (maybe there is none)

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

      If this is the new Input System, try adding Tap and MultiTap interactions to the click. You can then check the interaction type in your code. If the interaction type is MultiTapInteraction then you have your double click. Otherwise, single click.

    • @VEOdev
      @VEOdev Рік тому +1

      you can keep tracking last click time on update, if you click again while you are in the click duration, it triggers the double click, else if the time reached 0 > reset the double click, it will be something like that :
      first make a bool call it : clicked = false;
      then make a float call it : clickTreshhold = 0.05f;
      in update check if we click, if we do and the clicked is false, start counting down, if we clicked again and the countdown is not 0 yet, we trigger the function.. else if the time reached 0, set clicked to false again.

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

    There is also this method:
    using UnityEngine;
    public class OnMouseOverExample : MonoBehaviour
    {
    void OnMouseOver()
    {
    //If your mouse hovers over the GameObject with the script attached, output this message
    Debug.Log("Mouse is over GameObject.");
    }
    void OnMouseExit()
    {
    //The mouse is no longer hovering over the GameObject so output this message each frame
    Debug.Log("Mouse is no longer on GameObject.");
    }
    }

  • @inkofthedragon
    @inkofthedragon Рік тому +1

    I'm curious why you use interfaces in these examples? Can't you just use straight up methods? Thanks

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

      Without the interfaces the methods won’t get called. I’m not sure how Unity locates the interfaces, but I think about it as if Unity calls FindObjectsOfType() then calls the corresponding method on each instance.
      Does that help?