Code (CSharp): public class MyEvent: EventBase<MyEvent> {} // In MyElement somewhere using(var evt = MyEvent.GetPooled()) { this.SendEvent(evt); } some thing like above code. but in the root element register the custom event, not get the event callback!
...any officials.. debug unity internal code using Rider. i found the key is EventBase.propagation. But it is a internal property of EventBase! so user cannt using a custom event now! Code (CSharp): public class CustomEvent : EventBase<CustomEvent> { protected override void Init() { base.Init(); // propagation is internal! // this.propagation = EventPropagation.Bubbles; } }
using reflection... Code (CSharp): public class CustomEvent : EventBase<CustomEvent> { protected override void Init() { base.Init(); /* internal enum EventPropagation { None = 0, Bubbles = 1, TricklesDown = 2, Cancellable = 4, } 1 is Bubbles... */ var prop = typeof(CustomEvent).GetProperty("propagation"); prop?.SetValue(this, 1); } } now the custom Event works..