Life and Style Media - Binary Save


Create, Bind, and Unbind Delegate Events. Uses a custom delegate to attach and detach events at will. Useful for whenever you need a specific set of events to occur in one call.

DELEGATE EVENT


Current Version: 1.0.1
Price: FREE
License: MIT
Type: Custom Units








MANUAL


SETUP
When do I regenerate units?

- A units category has changed.
- A new unit or type is introduced.
- A unit or type is removed or marked obsolete.
- A unit or types namespace changed.
- A unit or types declaration has changed, including method signatures.

*If you are a C# programmer, you can alternatively use the attribute [RenamedFrom(string previousName)] and include the previous type name, including namespaces to prevent a regeneration.*

*Units, Graphs, Macros, ect, SHOULD NOT be included in the unit options window unless you need access to the internal scripts methods and variables.*


How do I regenerate units?

In the unity menu goto Tools > Bolt > Build Unit Options.



SUMMARY
Delegates work just like the name says, they delegate behavior between multiple sources. In the context of events and Bolt, this means we can attach and detach events. Imagine having an internal list of events that can be added or removed. One trigger to the Binding Delegate will call all events that have been bound.

Imagine playing some sort of game where there is a spotlight moving around. If you are caught in it at the end of the buzzer, you are shocked. You could use a collider with the light, and everytime a player enters or leaves, you bind or unbind. When the time is up, Trigger the Binding Delegate. Any players who are bound from still being in the light, get shocked due to the events logic that is on each player object.


CREATE EVENT
Delegate Events have no name, and are triggered by a reference to the binding delegate. To create an event, in the fuzzy finder, goto 'Events > Delegate' and place down a Delegate Event.




CREATE BINDING DELEGATE


A delegate, is a type that is used as a pointer to a single method. In code, it contains pointers to other methods by binding them. In C# you would see it like this:


public delegate void
MyDelegate
;

public
MyDelegate
del;

public void
BindDelegate(
MyDelegate
@delegate)
{
    
// Binds a delegate

    del += @delegate;

    
// Unbinds a delegate.

    del -= @delegate;
}



In bolt we create the delegate and get a reference to the Delegate Event like this:






BINDING
In bolt, the equivalent to binding a delegate is super easy. We already saved the references to a variable, so bind and unbind units do the trick.




TRIGGER
Now you can successfully trigger your binding delegates.