Class WatchersSystem | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Class WatchersSystem

    The Watchers provides an optional high-level helper for getting callback-like functionality in an Entity Component System (ECS) environment.

    Inheritance
    System.Object
    WatchersSystem
    UIControlsWatchersSystem
    DefaultWatchersSystem
    Namespace: Unity.Tiny.Watchers
    Syntax
    public class WatchersSystem : ComponentSystem
    Remarks

    While callbacks are not a very ECS-friendly concept (Components store only data, and systems contain only code that operates on data), callback-like functionality can be useful for certain things.

    For example, you can use watchers for UI event handlers such as OnClick, or to get notifications about the state of a tween animation such as OnEnded or OnLoopPoint.

    The base DefaultWatchersSystem is auto-scheduled and watchers may be added immediately. For advanced use cases it is possible to schedule additional WatchersSystem by creating a new subclass and scheduling it where desired.

    WatchersSystems are standalone systems that group multiple watched values. A WatchersSystems must be scheduled as a system in order to trigger delegates/callbacks.

    Callbacks have the same restrictions as code running in ComponentSystem. They are called from the watching system, just like code called from any other ComponentSystem. They are executed when the watching system runs, and not immediately when a value changes.

    Methods

    OnUpdate()

    Declaration
    protected override void OnUpdate()

    RemoveAllWatchers()

    Removes all watchers in this system

    Declaration
    public void RemoveAllWatchers()

    RemoveWatcher(Int32)

    Removes a watcher with a specific id.

    Declaration
    public bool RemoveWatcher(int id)
    Parameters
    Type Name Description
    System.Int32 id
    Returns
    Type Description
    System.Boolean

    Returns true if the watcher was found and removed.

    Remarks

    Ids are returned by the various Watch* functions. Watchers can also be removed by returning false from the delegate callback.

    WatchChanged(Entity, TypeManager.FieldInfo, WatchersSystem.WatchValueDelegateBool)

    Watches an entity for changes to a bool component.

    Declaration
    public int WatchChanged(Entity e, TypeManager.FieldInfo fieldInfo, WatchersSystem.WatchValueDelegateBool callback)
    Parameters
    Type Name Description
    Entity e
    TypeManager.FieldInfo fieldInfo
    WatchersSystem.WatchValueDelegateBool callback
    Returns
    Type Description
    System.Int32

    WatchChanged(Entity, TypeManager.FieldInfo, WatchersSystem.WatchValueDelegateFloat)

    Watches an entity for changes to a float component.

    Declaration
    public int WatchChanged(Entity e, TypeManager.FieldInfo fieldInfo, WatchersSystem.WatchValueDelegateFloat callback)
    Parameters
    Type Name Description
    Entity e

    Target entity to watch.

    TypeManager.FieldInfo fieldInfo

    The field to watch; generally implicitly cast from the supplied string, for example "Translation.position.x", "TweenComponent.ended", or "SequencePlayer.playing".

    WatchersSystem.WatchValueDelegateFloat callback

    Delegate method to call when the value changes.

    Returns
    Type Description
    System.Int32

    An id that can be passed to RemoveWatcher(Int32)

    Remarks

    Note that all watching callbacks are called when the watching system runs, not when the value is changed.

    WatchChanged(Entity, TypeManager.FieldInfo, WatchersSystem.WatchValueDelegateInt)

    Watches an entity for changes to a int component.

    Declaration
    public int WatchChanged(Entity e, TypeManager.FieldInfo fieldInfo, WatchersSystem.WatchValueDelegateInt callback)
    Parameters
    Type Name Description
    Entity e
    TypeManager.FieldInfo fieldInfo
    WatchersSystem.WatchValueDelegateInt callback
    Returns
    Type Description
    System.Int32
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023