Reusable Unity 6 algorithm pipeline. com.soobak.algo.core defines execution primitives, while com.soobak.algo.sorting and com.soobak.algo.search ship domain-specific showcases.
- Core Primitives:
IAlgorithm<TState, TEvent>andIAlgorithmStepSink<TState, TEvent>contracts withAlgorithmRunner<TState, TEvent>handling snapshot cloning and fan-out. - Core Pipeline:
IAlgorithmDescriptor<TState, TEvent>,IAlgorithmCatalog<TState, TEvent>, andAlgorithmPipeline<TState, TEvent>model how algorithms are registered, discovered, and executed. - Sorting Module:
SortingState/SortingItem,SortOp,IBarVisualizer,SortingAlgorithmCatalog, andSortingRunnerdemonstrate the pipeline with bubble, selection, merge, heap, shell, counting, quick, and stable insertion sort implementations. - Search Module:
SearchState/SearchResult,SearchEvent,ISearchAlgorithm, and search-specific implementations for linear search, binary search, and other search algorithms.
SortingAlgorithmCatalogexposes descriptors created viaAlgorithmDescriptor.Create.SortingRunnercomposes visualizers (IBarVisualizer) and, when supplied, the catalog to build anAlgorithmPipeline.- Consumers either pass an
ISortingAlgorithmdirectly or callExecuteAsync("quick-sort", state, token). - Each step broadcasts a cloned
SortingStateand aSortOpevent so visualizers receive immutable snapshots.
-
Install UniTask first (required dependency):
Git URL (recommended):
https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.5.10OpenUPM (alternative):
https://openupm.com/packages/com.cysharp.unitask/ -
Add individual packages using path parameters:
Core Package:
https://github.com/soo-bak/soobak-algo-core.git?path=Packages/com.soobak.algo.coreSorting Package:
https://github.com/soo-bak/soobak-algo-core.git?path=Packages/com.soobak.algo.sortingSearch Package:
https://github.com/soo-bak/soobak-algo-core.git?path=Packages/com.soobak.algo.searchOr add to manifest.json:
{ "dependencies": { "com.soobak.algo.core": "https://github.com/soo-bak/soobak-algo-core.git?path=Packages/com.soobak.algo.core", "com.soobak.algo.sorting": "https://github.com/soo-bak/soobak-algo-core.git?path=Packages/com.soobak.algo.sorting", "com.soobak.algo.search": "https://github.com/soo-bak/soobak-algo-core.git?path=Packages/com.soobak.algo.search" } }Note: Each package is independent and can be installed separately. Make sure to install UniTask first before using any algorithm packages.
-
Implement a visualizer.
public sealed class BarVisualizer : IBarVisualizer { public UniTask InitializeAsync(SortingState initialState, CancellationToken token) => UniTask.CompletedTask; public UniTask PublishAsync(AlgorithmStep<SortingState, SortOp> step, CancellationToken token) => UniTask.CompletedTask; public UniTask CompleteAsync(SortingState finalState, CancellationToken token) => UniTask.CompletedTask; }
-
Run an algorithm via descriptor.
var catalog = new SortingAlgorithmCatalog(); var runner = new SortingRunner(new BarVisualizer(), catalog); var state = SortingState.FromValues(new[] { 4, 2, 3, 1 }); var sorted = await runner.ExecuteAsync("quick-sort", state, CancellationToken.None);
- Cover pure logic with Unity EditMode tests; use
UniTaskand log cancellations/errors viaDebugin English. - Sample command:
Unity.exe -projectPath . -runTests -testPlatform editmode -logFile ./Artifacts/editmode.log
.github/workflows/unity-editmode.ymlruns EditMode suites throughgame-ci/unity-test-runner@v4..github/workflows/commit-sentinel.ymlenforces SSH-signed commits and the:gitmoji: scope: messagestyle.
- Import "Sorting Visualizer Demo" from the Package Manager samples to try the cube-based bar visualizer.
- Attach
SortingDemoControllerto an empty GameObject and press Play to run the selected algorithm.
- See
Docs/architecture.mdfor layering responsibilities and extension guidance.
- Extend the catalog with additional algorithms (e.g., counting sort, shell sort).
- Spin up new domain packages (e.g., graph search) that reuse the core pipeline.
- Validate Git UPM consumption from a demo repository with WebGL publishing.
