If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.
Great stuff Ben! These are very advanced subject (patterns and delegates) and I feel like you illustrated them well and in the perfect scenario!
I really appreciate that feedback, it’s a difficult topic to get across.
I thought the two courses; Delegates and Events very well presented. They even more powerful when used with any xxx-manager (e.g. gamemanager, weaponmanager, environmentmanager, etc) to both receive and send events to components in the game / scene.
Thanks, Ben, that really made a lot of sense. Personally I found the use of the event keyword actually makes it much clearer what that, otherwise very weird, line of code is about.
This is a super useful conecpt. Seems very similar to interfaces in Java.
I love learning new concepts like this, it expands the toolbox of what I can do with code.
So glad you all like this so much.
Delegates are new for me and I am still struggling. Wish I had more time to for this course. Keep up the great work!
These delegates are really interesting. Sorta hard to wrap my mind around it, but it’s cool to learn more advanced coding like this. Creating one variable, then an instance of it that can communicate with other parts, etc etc etc. I think delegates fried my brain Cheers
In the case of the Observer Pattern, I name my objects more Java like to understand it better
[it’s just a rough outline that I can come back to… it’s of course not all there is to delegates, and might not even be 100% accurate, e.g. the signature doesn’t have to be exactly the same as the delegate’s signature]:
The Broadcaster creates the events (in our case: CameraRaycaster):
class Broadcaster {
// ...
// declare new delegate type (SomeEvent)
public delegate RetType SomeEvent(T paramList);
// register listeners via += and inform them via (...)
public event SomeEvent someEventListeners;
void Update() {
T arg;
// ...
if(/* "some event has happened" */) {
// broadcast it to all subscribes
someEventListeners(arg); // basically, this "method" will call every method that has subscribe to it
}
} // Update()
} // Broadcaster
A Subscriber listens to event changes (in our case: CursorAffordance):
class Subscriber {
// ...
Broadcaster broadcaster; // get the Broadcaster from somewhere
void Start() {
// ...
// subscribe to the Broadcaster
broadcaster.someEventListeners += DoThisOnSomeEvent;
} // Start()
// note: has same return type and parameter list as the delegate
RetType DoThisOnSomeEvent(T paramList) {
// when "some event" happens, this method will be called by the delegate
// @see Broadcaster.Update()
}
} // Subscriber
Hi.
I know this is an old post, but I just wanted to say I found these 2 lectures on delegates and events excellent. I tried to understand this concept in the past by watching some other tutorials but without success. Ben explained it so clearly, it clicked almost instantly for me.
Thank you so much, Ben.