Skip to content

CallProvider

Chillersanim edited this page Feb 9, 2020 · 4 revisions

CallProvider

Namespace: Unity_Tools.Components

Provides global callbacks for various situations, such as update, fixed update, on gui and others. Allows for dynamic subscription of calls on demand in-game and in-editor.

[ExecuteInEditMode]
public sealed class CallProvider : 
    SingletonBehaviour<CallProvider>

Remarks

Performance

Callbacks are optimized for performance and little overhead.
No reflection is being used, which makes the calls in general faster than default Unity update or fixed update methods.

Singleton Behavior

CallProvider inherits from SingletonBehavior.
Duo to Unitys handling of object destruction in the editor, it cannot be guaranteed that the Instance is accessible when the in-editor game is shutting down.

Before calling Instance methods, you need to make sure that the Instance is accessible, by checking CallProvider.CanAccessInstance.
Otherwise calls might lead to null reference exceptions.

Static methods are guaranteed to work, however their calls won't have any effect when the Instance is no longer available.

Periodic Update

The periodic update subscription is for components that don't rely on constant call frequency.
When subscribing to the periodic update callback, the subscribed listener will be called irregularly.
Subscribed listeners will be called one after another, until the allocated time frame is used up.
In the next frame, the calls will continue where they left of.
It is guaranteed that a listener won't be called multiple times per frame, even if the allocated time frame is long enough.

Editor

Callbacks work in the editor as well.
The update and fixed update callback will use the Application.Tick callback, leading to a frequent callback behavoir.

Properties

  • MaxPeriodicUpdateDuration : float
    Gets or sets a value defining how much time is allocated per periodic update segment for invocations, in seconds.

Methods

  • AddEditorOnlyUpdateListener(Action) : void
    Adds a listener to the on editor only update callback list.
  • AddFixedUpdateListener(Action) : void
    Adds a listener to the on fixed update callback list.
  • AddOnGizmosListener(Action) : void
    Adds a listener to the on draw gizmos callback list.
  • AddOnGuiListener(Action) : void
    Adds a listener to the on draw gui callback list.
  • AddPeriodicUpdateListener(Action) : void
    Adds a listener to the periodic update callback list.
  • AddUpdateListener(Action) : void
    Adds a listener to the on update callback list.
  • RemoveEditorOnlyUpdateListener(Action) : void
    Removes a listener from the on editor only update callback list.
  • RemoveFixedUpdateListener(Action) : void
    Removes a listener from the on fixed update callback list.
  • RemoveOnGizmosListener(Action) : void
    Removes a listener from the on draw gizmos callback list.
  • RemoveOnGuiListener(Action) : void
    Removes a listener from the on draw gui callback list.
  • RemovePeriodicUpdateListener(Action) : void
    Removes a listener from the periodic update callback list.
  • RemoveUpdateListener(Action) : void
    Removes a listener from the on update callback list.

Thread safety

The CallProvider is not thread safe and is intended to only be used from the main thread.

Clone this wiki locally