Just a tip for anyone watching this as its a very simple guide to Events in C#, he actually missed a CRUCIAL point in this tutorial. you should always always check the EventHandler (ClickEvent in this case) for null with the Invoke. if you do not and nothing has subscribed to the event, it will crash the program. you can either do if (ClickEvent !- null) ClickEvent.Invoke() or shorthand it with ClickEvent?.Invoke() (the ? at the end is a shorthand version of only do this if its not null)
I have a "button" class that I'm creating dynamically. Each button will report a different string to a handler when it has been hovered over. What I've been doing is giving my button class a reference to the parent, and then will call "ReportUp(str)", but I don't think this is a good design. Does this solution help with this or not really? I'm also using Unity but I don't think that matters
Thank you so much, I have read through documentation and watched several videos, but this explanation and demonstration finally made me understand how to actually use them!
Question: why is there a need to use the custom EventArgs when you can simply utilize the class where the EventHandler belongs? To be specific in this example: why create a new MyCustomArguments class when you can instead add the Name property in Button and then on the anonymous function just call
Just a tip for anyone watching this as its a very simple guide to Events in C#, he actually missed a CRUCIAL point in this tutorial. you should always always check the EventHandler (ClickEvent in this case) for null with the Invoke. if you do not and nothing has subscribed to the event, it will crash the program. you can either do if (ClickEvent !- null) ClickEvent.Invoke() or shorthand it with ClickEvent?.Invoke() (the ? at the end is a shorthand version of only do this if its not null)
You can't learn from this. This will only make sense once you already fully know about Events.
Where I am confused is... why was there no event here? only a delegate?
You forgot to explain how event handlers work.....
set speed 1.25, at least
But how do you create the button itself as an object?
I don't quite see the difference between events and event handlers and boring old callbacks with custom delegate functions?
That's cutosom!
I have a "button" class that I'm creating dynamically. Each button will report a different string to a handler when it has been hovered over. What I've been doing is giving my button class a reference to the parent, and then will call "ReportUp(str)", but I don't think this is a good design. Does this solution help with this or not really? I'm also using Unity but I don't think that matters
Clear as mud
Thank you so much, I have read through documentation and watched several videos, but this explanation and demonstration finally made me understand how to actually use them!
You are my hero man i could finally understand this, really thank you
Awesome! Short and sweet! Very helpful!
Thanks. This was really enlightening.
Thanks for posting this. I'm not sure why you don't have more subs.
Question: why is there a need to use the custom EventArgs when you can simply utilize the class where the EventHandler belongs? To be specific in this example: why create a new MyCustomArguments class when you can instead add the Name property in Button and then on the anonymous function just call
Thank you for this clear explanation!
It's a hard topic. Best expression imo
This example is more relevant and understandable even more than the ones in the official content
Bro think for the video I finally learnt what I need !