https://github.com/sator-imaging/unity-fundamentals
Unity Scripting Fundamentals
https://github.com/sator-imaging/unity-fundamentals
csharp csharp-library unity unity-scripts unity3d
Last synced: 3 months ago
JSON representation
Unity Scripting Fundamentals
- Host: GitHub
- URL: https://github.com/sator-imaging/unity-fundamentals
- Owner: sator-imaging
- License: mit
- Created: 2024-03-18T00:32:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-10T03:58:05.000Z (12 months ago)
- Last Synced: 2025-08-23T01:37:40.437Z (10 months ago)
- Topics: csharp, csharp-library, unity, unity-scripts, unity3d
- Language: C#
- Homepage: https://sator-imaging.github.io/Unity-Fundamentals/
- Size: 324 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://deepwiki.com/sator-imaging/Unity-Fundamentals)
[](https://sator-imaging.github.io/Unity-Fundamentals/api/index.html)
ย
[](https://qiita.com/sator_imaging/items/235c8447f4171ba5a522)
Unity Scripting Fundamentals is designed to be minimal, efficient & dependency-free as possible.
Most of scripts are .NET / Plain C# compliant. See `using` statements in `.cs` files for details.
- ๐งฑ [Plain C# APIs](#-plain-c-apis)
- ๐ฎ [Unity Runtime APIs](#-unity-runtime-apis)
- ๐ฑ๏ธ [Unity Editor Extensions](#๏ธ-unity-editor-scripts)
> [!TIP]
> Licensed under the MIT License unless otherwise described.
> Supported Unity version: Unity 2021.3+
# ๐ฆ Installation
Add the following `git URL` in Unity Package Manager (UPM).

## ๐ท๏ธ Release version
Use latest stable release.
```
https://github.com/sator-imaging/Unity-Fundamentals.git#latest
```
or use specific version (append desired version at the end: `#vX.Y.Z`).
```
https://github.com/sator-imaging/Unity-Fundamentals.git#v1.7.2
```
## ๐ฆ Canary/Nightly Build
> [!IMPORTANT]
> It's very experimental and may have breaking changes, bug or errors without notice.
```
https://github.com/sator-imaging/Unity-Fundamentals.git
```
ย
# ๐งฑ Plain C# APIs
- `Fibers`
Microthreading Library for .NET / Unity.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Threading/Fibers.cs.html)
or
[ๆฅๆฌ่ช็](https://zenn.dev/sator_imaging/articles/0236e98fbbbc98)
- `FiberScheduler`
Task scheduler with concurrency level control.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/api/SatorImaging.UnityFundamentals.FiberScheduler.html)
- **Non-Alloc String Splitter**
Split string without allocation.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Text/NonAllocStringSplitter.cs.html)
or
[ๆฅๆฌ่ช็](https://qiita.com/sator_imaging/items/1393aa0efa3b064d77ec)
- **Rx (Reactive Extensions) / Observable**
Transform `event Action` to `IObservable`.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Reactive/ObservableEvent.cs.html)
- **Easing Functions**: `EasingFloat` and `EasingDouble`
High performance easing functions (Unity Burst Compiler ready).
[๐](https://x.com/sator_imaging/status/2035921437433966891)
- `NetworkClock`
Believe-worthy, device-independent time provider based on `HTTPS` connection.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/System/NetworkClock.cs.html)
or
[่งฃ่ชฌ](https://zenn.dev/sator_imaging/articles/6e1bd822a82d31)
- `HalfUlid`
https://github.com/sator-imaging/Half-Ulid
ย
[ๅฎ่ฃ
ใฎ่ฉณ็ดฐ](https://qiita.com/sator_imaging/items/576781d95367d5856624)
- `Atom`
Thread safe primitive.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Threading/Atom.cs.html)
or
[่งฃ่ชฌ](https://zenn.dev/sator_imaging/articles/ed6dac717f5038)
- `MiniXXHash`
Minimal xxHash32 / xxHash64 implementation.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Hashing/MiniXXHash.cs.html)
or
[ๆฅๆฌ่ช็](https://qiita.com/sator_imaging/items/36c390c0536a6750b788)
License: BSD 2-Clause
xxHash Clean C Reference Implementation
```
xxHash Library
Copyright (c) 2012-2020 Yann Collet
Copyright (c) 2019-2020 Devin Hussey (easyaspi314)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```
- `SpanList`
List implementation of `Span` especially designed to work with `Span`.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/System/SpanList.cs.html)
- *TODO*: Add `(int, int) GetMinMaxLength()`
- To prevent enumerating repeatedly to get same result.
- Add `bool _isFrozen` to determine recalculate is required. `Write` turns it off when changed.
- Add `bool IsFormattable` with more strict token check: `{one}{two}` (currently accepted but must be rejected).
- One pass replacement for `FormatNonAlloc`: search for `{` then perform `.Slice(foundIndex, fromTokenMaxLength)`, check which one is match.
- `RustSharp`
Move semantics for .NET / Unity.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/FancyStuff/RustSharp.cs.html)
or
[่งฃ่ชฌ](https://zenn.dev/sator_imaging/articles/e6428d4f1c8158)
- `UString`
Lightning-fast non-alloc string builder faster than `DefaultInterpolatedStringHandler`.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Text/UString.cs.html)
or
[ๆ่ก็ใช่งฃ่ชฌ](https://qiita.com/sator_imaging/items/edc5be1a55dd867e1c73)
*NOTE*: Depending on `StrictEnum`
*TODO*: Benchmark
- `Poolable`
Self-contained singly linked list based object pool.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/System/Poolable.cs.html)
or
[ๆฅๆฌ่ช็](https://qiita.com/sator_imaging/items/2a387a54a01e91e5d71d)
*TODO*: Write tests
- `Sentinel`
Fast & efficient exclusive or concurrent thread/event manager.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Threading/Sentinel.cs.html)
- `WhenEachEnumerator`
`Task.WhenEach` for Unity / .NET Standard 2.1.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Threading/WhenEachEnumerator.cs.html)
or
[ๆฅๆฌ่ช็](https://qiita.com/sator_imaging/items/0facece38f6e1c03bd19)
- `Defer`
Providing function for `early-finally` pattern.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/System/Defer.cs.html)
- *TODO*: Implement `IAsyncDisposable` overloads.
- ex: `await using var _ = Defer.New(async () => await ...);`
- `StrictEnum`
Unlike other enum utility, this class reuses system cache and also support parsing `Flags` value.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/System/StrictEnum.cs.html)
See also:
[FinalEnumGenerator](https://github.com/sator-imaging/FGenerator/tree/main/FinalEnumGenerator)
- `ThreadSafeSingleton`
Thread! safe!! singleton!!!
[ๆฅๆฌ่ช็](https://qiita.com/sator_imaging/items/6c60e462417a5235778a)
- NUnit-compatible Framework for Unity Editor
Crazy stuff.
No need to use this anymore as unity asset store now accepts `package.json`.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/FancyStuff/NUnit.Framework.UnityStubs.cs.html)
ย
# ๐ฎ Unity Runtime APIs
- **Observable `UnityEvent`**
Transform `UnityEvent` to `IObservable`.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Reactive/ObservableUnityEvent.cs.html)
- **Nullable support for `UnityEngine.Object`**
Reliable nullable (`??` `?.` ~~`??=`~~) support for `UnityEngine.Object`.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/UnityObject/NullableUnityObject.cs.html)
- `ManagedShell`
Provides functions that avoid creating leaked managed shell.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/UnityObject/ManagedShell.cs.html)
or
[่งฃ่ชฌใใฎ๏ผ](https://qiita.com/sator_imaging/items/6bca6c642b6347bd68d8)
[ใใฎ๏ผ](https://qiita.com/sator_imaging/items/1251fa3a0b51db87a82f)
- `PoolableBehaviour`
Self-contained singly linked list based `MonoBehaviour` pool.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/UnityObject/PoolableBehaviour.cs.html)
or
[ๆฅๆฌ่ช็](https://qiita.com/sator_imaging/items/80c712ee4fcabfce9163)
- **UI Toolkit Core Extensions**
- `ExecuteAfter` extension method
- unlike builtin `ExecuteLater` method, this method runs action right after specified number of *repaint* events.
- `DisableStyleTransitionScope` extension method
- this method temporarily turns off all transitions and turns them back on when leaving the `IDisposable` scope. useful for immediate style update without transition animation.
- UI Toolkit Event Subscription
Use extension method `RegisterCallbackAsSubscription` to register event as `IDisposable` interface.
It allows easily unregister event later.
- UI Toolkit Dropdown Helper
Extension method `RegisterCallbackAsEnum` allows implement typed callback.
And also there is option to delay event to correctly handle dropdown event.
(if no delay, dropdown in Unity editor behaves like 'stop-the-world' and some actions are not work as expected)
*NOTE*: Depending on `StrictEnum`
- `ReusableCoroutine`
Non-alloc Unity coroutine implementation.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/api/SatorImaging.UnityFundamentals.ReusableCoroutine.html)
or
[ๆฅๆฌ่ช็](https://zenn.dev/sator_imaging/articles/b0ab667808d563#ใunityใๅๅฉ็จๅฏ่ฝใชใณใซใผใใณ)
ย
# ๐ฑ๏ธ Unity Editor Scripts
- **UPM Package Test Kit**
Generate clean environment and build script for selected UPM package.
[๐](Editor/UpmPackage)
or
[ๆฅๆฌ่ชใใใฅใขใซ](https://zenn.dev/sator_imaging/articles/feadbd5b1281d8)
*TODO*: Unit test automation.
- **C# API Documentation for IDE**
Download C# API Documentation from Nuget.org.
[๐](Editor/Nuget)
License: Apache License version 2.0
- `UnityEditorMainToolbar`
Provide access to `VisualElement` in Unity main toolbar.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Editor/Uncategorized/UnityEditorMainToolbar.cs.html)
or
[ๆฅๆฌ่ช็](https://qiita.com/sator_imaging/items/f1bdf82016117cd6c7bd)
- **Leaked Managed Shell Detector**
Not perfect.
Just for reference.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Editor/Uncategorized/LeakedManagedShellDetector.cs.html)
- **Assembly Definitions Manager** for Project Settings Panel
*TODO*: Documentation
- *WIP*: `sealed`-able Type Finder
As IL2CPP bloats resulting C++ code if C# class is not marked with `sealed` modifier.
ย
# ๐๏ธ *Obsolete*
Files are found in [Obsolete/](./Obsolete/) folder with `.txt` extension.
- **CancellationToken based Lifecycle Manager**
Obsolete features still exist as `.txt` files.
[๐](https://sator-imaging.github.io/Unity-Fundamentals/Obsolete/LifecycleBehaviour/README.html)
or
[ๆฅๆฌ่ช็](https://qiita.com/sator_imaging/items/48296a686e4bbff8676c)
- `Run`
Job runner for Unity providing reliable un-async-ing functions and more.
> [!NOTE]
> `InitializeMainThreadContext` may be required to being called on Unity startup. (it called automatically by default)
*TODO*: documentation for `OnMainThread`, `InThreadPool`, `SetExceptionHandler`, `GetTimerToken`, `GetElapsedTime`, `Shutdown`, `CreateNewScheduler`, `SetConcurrentThreadCount`
- `ObservableAction`
[๐](https://sator-imaging.github.io/Unity-Fundamentals/HeaderDocs/Runtime/Reactive/ObservableAction.cs.html)
ย
# ๐ Devnote
## โ๏ธ `DefineConstants`
How to set `DefineConstants` in *.csproj* file from `dotnet` command, see [Directory.Build.Props](../CStrBenchmark/Directory.Build.props) and [Program.cs](../CStrBenchmark/Program.cs#L37) for details.
Source: https://github.com/dotnet/sdk/issues/9562#issuecomment-1386955134