How neuecc/unirx works
Main components
• Core Reactive Library: This includes the base abstractions of reactive programming (IObservable, IObserver, Disposable types, various LINQ-style operators, Subjects, and ReactiveProperties). This is found under Assets/Plugins/UniRx/Scripts and also in the Dlls/UniRx projects.
• Unity Adaptor Layer: Contains platform-specific adaptations (e.g., MonoBehaviour triggers within Assets/Plugins/UniRx/Scripts/UnityEngineBridge and related trigger classes under Assets/Plugins/UniRx/Examples that show the bridge between Unity events and observables).
• Scheduling and Threading: It implements specialized schedulers like Scheduler.MainThread, ThreadPoolScheduler, and MicroCoroutine mechanisms for efficient frame-based asynchronous execution. These components (located within the Schedulers subdirectories and as parts of the UnityEngineBridge) are critical in mapping Unity’s game loop characteristics.
• Testing and Analysis: The project has a robust test suite (see Tests/UniRx.Console, Tests/UniRx.Tests) and a Visual Studio Analyzer under the Analyzer directory. This part of the system verifies correct reactive behavior and helps identify common mistakes (e.g., forgotten subscriptions).
• Build and Distribution Infrastructure: NuGet packaging files (inside the .nuget directory), continuous integration configuration (in the .circleci folder), and Visual Studio solution/project files (such as UniRx.sln, Assembly-CSharp, and .csproj files) represent the build and deployment pipeline.
• Example and Documentation: There are extensive examples (Assets/Plugins/UniRx/Examples) and sample scenes that illustrate “how to use” the library in practical Unity projects, along with the README documentation that guides usage.
Relationships and interactions
• The Core Library provides the fundamental reactive types and operators. These are consumed by both Unity Adaptor components and the high-level Reactive UI components.
• The Unity Adapters/Triggers layer converts Unity events (Update, OnCollision, UI interactions, etc.) into observable streams. For example, ObservableTrigger classes (and the extension methods on GameObject/Component) tap directly into Unity’s event lifecycle and forward these events as Rx notifications.
• The Testing/Analyzer components are decoupled from the main library but are integrated during CI build (.circleci config) and help enforce correct reactive patterns.
• Tools like MessageBroker and ReactiveCommand provide glue between the UI and the domain logic, emphasizing a Model-View-(Reactive)Presenter pattern (illustrated in the README) where view events are funneled as observables to update models and trigger UI changes.
Architectural Patterns and Design Principles
• Modular Architecture: The separation of core functionality (reactive extensions and operators) from Unity-specific adapters fosters reuse and substitution.
• Reactive Programming Fundamentals: All aspects of the library, from asynchronous operations to UI events, follow a reactive paradigm—using streams, subscriptions, and disposables to manage communication.
• Asynchronous and Multithreaded Handling: The use of schedulers, micro-coroutines, and main thread dispatchers underscores how asynchronous work is coordinated with Unity’s single-threaded nature.