-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please generate differently named interfaces for EventTarget.Self and EventTarget.Any #810
Comments
Why not just leave it as |
I have also run into this problem to and I think different names would be very useful |
@AVAVT This works but is not very convenient. I would also like to have different names for the event listeners. |
@AVAVT this sortof defeats the purpose of an event-driven system. The point is to only call the method when necessary. In some cases this would lead to thousands of unneccesary method calls. |
What do you guys think about removing IListener and replace it with public delegate void OnPosition(Vector3 position); var listener = contexts.game.CreateEntity();
listener.AddPositionListener(p => transform.position = p); |
The content in listener function usually has more than one line code. It is nice to have a distinct function for it. The one of advantages of IListener approach is that correct function name and parameters can be filled by IDE automatically. Another personal reason I like to keep using IListener is that I pick the Blueprint up and make it support IListener. |
I like the IListener approach for the same reasons, it's nice and convenient in the IDE and it's extremely readable, right at the top of the class you can see what it's reacting to. I just want support for both types of listener at the same time - perhaps the more cumbersome naming (Including the word Self/Any for example) could be reserved only for when the CG detects that both types are defined on one component? |
Just submitted PR #827 [Event(EventTarget.Self), Event(EventTarget.Any)]
public sealed class PositionComponent : IComponent
{
public Vector3 value;
} will generate public void OnAnyPosition(GameEntity entity, Vector3 value)
{
UnityEngine.Debug.Log(entity.creationIndex + " Position: " + value);
}
public void OnPosition(GameEntity entity, Vector3 value)
{
UnityEngine.Debug.Log(entity.creationIndex + " Position: " + value);
} |
Need to update roslyn generator and namespace support. Will be in next release. |
Delegates might be more flexible, but currently I also prefer IListener being more explicit. |
Hi,
I am coming across this more and more, and I'm really struggling to work around it. I have situations where I need both the bound event and the unbound event from a component at the same time.
Using an attack component as an example: I want to have the attack notify the entity's view that an attack has occured so i can switch its animation state, but i also want to have a blood effect controller sitting around and listening for any attacks so it can spawn in particles, and I want this to be global, not hanging off each entit's view. Can you detect when both of these attributes have been added and add the words Self and Any to the listener components and interfaces and whatnot?
The text was updated successfully, but these errors were encountered: