import type { IEventList } from "../engine/engine_types.js"; /** * CallInfo represents a single callback method that can be invoked by the {@link EventList}. */ export declare class CallInfo { $serializedTypes: Record; /** * When the CallInfo is enabled it will be invoked when the EventList is invoked */ enabled: boolean; /** * The target object to invoke the method on OR the function to invoke */ target: Object | Function; methodName: string | null; /** * The arguments to invoke this method with */ arguments?: Array; get canClone(): boolean; constructor(target: Function); constructor(target: Object, methodName: string | null, args?: Array, enabled?: boolean); invoke(...args: any): void; } /** @deprecated No longer automatically dispatched. Use `eventList.on()` directly instead. */ export declare class EventListEvent extends Event { args?: TArgs; } /** * Plain-data form of a callback entry, accepted by {@link EventList.addCall} so callers * don't have to construct a {@link CallInfo} themselves. Field names match CallInfo. */ export type EventListCallData = { /** The object to invoke the method on OR the function to invoke. Editors may create * entries without a target and assign it afterwards. */ target?: Object | Function; methodName?: string | null; arguments?: Array; enabled?: boolean; }; /** * EventList manages a list of callbacks that can be invoked together. * Used for Unity-style events that can be configured in the editor (Unity or Blender). * * **Serialization:** * EventLists are serializable - callbacks configured in Unity/Blender will work at runtime. * Mark fields with `@serializable(EventList)` for editor support. * * **Usage patterns:** * - Button click handlers * - Animation events * - Custom component callbacks * - Scene loading events * * ![](https://cloud.needle.tools/-/media/P7bEKQvfgRUMTb2Wi1hWXg.png) * *Screenshot of a Unity component with an EventList field* * * ![](https://cloud.needle.tools/-/media/i2hi2OHfbaDyHyBL6Gt58A.png) * *Screenshot of a Blender component with an EventList field* * * @example Create and use an EventList * ```ts * // Define in your component * @serializable(EventList) * onClick: EventList = new EventList(); * * // Add listeners * this.onClick.addEventListener(() => console.log("Clicked!")); * * // Invoke all listeners * this.onClick.invoke(); * ``` * * @example Listen with arguments * ```ts * const onScore = new EventList<{ points: number }>(); * onScore.addEventListener(data => console.log("Scored:", data.points)); * onScore.invoke({ points: 100 }); * ``` * * @category Events * @group Utilities * @see {@link CallInfo} for individual callback configuration * @see {@link Button} for UI button events */ export declare class EventList implements IEventList { $serializedTypes: Record; /** checked during instantiate to create a new instance */ readonly isEventList = true; /** How many callback methods are subscribed to this event */ get listenerCount(): number; /** * The callback entries of this event. * This is tooling/editor surface: inspectors render and edit the entries (a * {@link CallInfo}'s fields are mutable), serializers read them. Use * {@link addCall} / {@link removeCall} to change the list itself. */ get calls(): readonly CallInfo[]; /** * Add a callback entry to this event. Accepts a plain function, a {@link CallInfo} * instance or a plain data object — `addCall({ target, methodName: "myMethod" })`. * @param index optional position to insert at (appends when omitted or out of range) — * entry order is invocation order * @returns a function that removes the entry again (same contract as * {@link addEventListener} / {@link on}); the entries themselves are readable and * editable through {@link calls} */ addCall(call: CallInfo | EventListCallData | Function | null | undefined, index?: number): () => boolean; /** * Remove a callback entry (or the entry at an index) from this event. * @returns true if an entry was removed */ removeCall(call: CallInfo | number): boolean; /** If the event is currently being invoked */ get isInvoking(): boolean; private _isInvoking; private readonly methods; private readonly _methodsCopy; /** * Create a new EventList with the given callback methods. You can pass either CallInfo instances or functions directly. * @returns a new EventList instance with the given callback methods * @example * ```ts * const onClick = EventList.from( * () => console.log("Clicked!"), * new CallInfo(someObject, "someMethod", [arg1, arg2]) * ); * onClick.invoke(); * ``` */ static from(...evts: Array): EventList; /** * Create a new EventList with the given callback methods. You can pass either CallInfo instances or functions directly. * @returns a new EventList instance with the given callback methods */ constructor(evts?: Array | Function); /** Invoke all the methods that are subscribed to this event * @param args optional arguments to pass to the event listeners. These will be passed before any custom arguments defined in the CallInfo instances. So if you have a CallInfo with arguments and you also pass arguments to invoke, the arguments passed to invoke will take precedence over the CallInfo arguments. * @returns true if the event was successfully invoked, false if there are no listeners or if a circular invocation was detected */ invoke(...args: Array): boolean; /** Add a new event listener to this event * @returns a function to remove the event listener * @see {@link removeEventListener} for more details and return value information * @see {@link off} for an alias with better readability when unsubscribing from events * @example * ```ts * const off = myEvent.addEventListener(args => console.log("Clicked!", args)); * // later * off(); * ``` */ addEventListener(callback: (args: TArgs) => void): Function; /** * Alias for addEventListener for better readability when subscribing to events. You can use it like this: * ```ts * myEvent.on(args => console.log("Clicked!", args)); * ``` * @returns a function to remove the event listener * @see {@link addEventListener} for more details and return value information */ on(callback: (args: TArgs) => void): Function; /** * Remove an event listener from this event. * @returns true if the event listener was found and removed, false otherwise */ removeEventListener(fn: Function | null | undefined): boolean; /** * Alias for removeEventListener for better readability when unsubscribing from events. You can use it like this: * ```ts * const off = myEvent.on(args => console.log("Clicked!", args)); * // later * off(); * ``` * * @see {@link removeEventListener} for more details and return value information */ off(callback: Function | null | undefined): boolean; /** * Remove all event listeners from this event. Use with caution! This will remove all listeners! */ removeAllEventListeners(): void; }