Unity Scripting Fundamentals
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.
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.3.1
🦜 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
FiberScheduler
Task scheduler with concurrency level control. 📘Non-Alloc String Splitter
Split string without allocation. 📘 or 日本語版Rx (Reactive Extensions) / Observable
Transformevent Action<T>toIObservable<T>. 📘SpanList<T>
List implementation ofSpan<T>especially designed to work withSpan<char>. 📘- TODO: Add
(int, int) GetMinMaxLength()- To prevent enumerating repeatedly to get same result.
- Add
bool _isFrozento determine recalculate is required.Writeturns it off when changed. - Add
bool IsFormattablewith 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.
- TODO: Add
Atom<T>
Thread safe primitive. 解説RustSharp
Move semantics for .NET / Unity. 解説NetworkClock
Believe-worthy, device-independent time provider based onHTTPSconnection. 📘 or 解説MiniXXHash
Minimal xxHash32 / xxHash64 implementation. 📘 or 日本語版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.UString
Lightning-fast non-alloc string builder faster thanDefaultInterpolatedStringHandler. 📘 or 技術的な解説NOTE: Depending on
StrictEnumTODO: BenchmarkPoolable<T>
Self-contained singly linked list based object pool. 📘 or 日本語版TODO: Write tests
Sentinel
Fast & efficient exclusive or concurrent thread/event manager. 📘WhenEachEnumerator
Task.WhenEachfor Unity / .NET Standard 2.1. 📘 or 日本語版Defer
Providing function forearly-finallypattern. 📘- TODO: Implement
IAsyncDisposableoverloads.- ex:
await using var _ = Defer.New(async () => await ...);
- ex:
- TODO: Implement
StrictEnum
Unlike other enum utility, this class reuses system cache and also support parsingFlagsvalue. 📘See also: FinalEnumGenerator
ThreadSafeSingleton
Thread! safe!! singleton!!! 日本語版NUnit-compatible Framework for Unity Editor
Crazy stuff. No need to use this anymore as unity asset store now acceptspackage.json. 📘
🎮 Unity Runtime APIs
Observable
UnityEvent
TransformUnityEventtoIObservable<T>. 📘Nullable support for
UnityEngine.Object
Reliable nullable (???.) support for??=UnityEngine.Object. 📘ManagedShell
Provides functions that avoid creating leaked managed shell. 📘 or 解説その1 その2PoolableBehaviour<T>
Self-contained singly linked list basedMonoBehaviourpool. 📘 or 日本語版UI Toolkit Core Extensions
ExecuteAfterextension method- unlike builtin
ExecuteLatermethod, this method runs action right after specified number of repaint events.
- unlike builtin
DisableStyleTransitionScopeextension method- this method temporarily turns off all transitions and turns them back on when leaving the
IDisposablescope. useful for immediate style update without transition animation.
- this method temporarily turns off all transitions and turns them back on when leaving the
UI Toolkit Event Subscription
Use extension methodRegisterCallbackAsSubscriptionto register event asIDisposableinterface. It allows easily unregister event later.UI Toolkit Dropdown Helper
Extension methodRegisterCallbackAsEnumallows 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. 📘 or 日本語版
🖱️ Unity Editor Scripts
UPM Package Test Kit
Generate clean environment and build script for selected UPM package. 📘 or 日本語マニュアルTODO: Unit test automation.
C# API Documentation for IDE
Download C# API Documentation from Nuget.org. 📘License: Apache License version 2.0
UnityEditorMainToolbar
Provide access toVisualElementin Unity main toolbar. 📘 or 日本語版Leaked Managed Shell Detector
Not perfect. Just for reference. 📘Assembly Definitions Manager for Project Settings Panel
TODO: DocumentationWIP:
sealed-able Type Finder
As IL2CPP bloats resulting C++ code if C# class is not marked withsealedmodifier.
🗑️ Obsolete
Files are found in Obsolete/ folder with .txt extension.
CancellationToken based Lifecycle Manager
Obsolete features still exist as.txtfiles. 📘 or 日本語版Run
Job runner for Unity providing reliable un-async-ing functions and more.Note
InitializeMainThreadContextmay be required to being called on Unity startup. (it called automatically by default)TODO: documentation for
OnMainThread,InThreadPool,SetExceptionHandler,GetTimerToken,GetElapsedTime,Shutdown,CreateNewScheduler,SetConcurrentThreadCountObservableAction<T>📘
📝 Devnote
⚙️ DefineConstants
How to set DefineConstants in .csproj file from dotnet command, see Directory.Build.Props and Program.cs for details.
Source: https://github.com/dotnet/sdk/issues/9562#issuecomment-1386955134