Generic Arithmetic - C# Template Extension
Juste Tools
$5.49
$10.99
50%OFF
(no ratings)
Jump AssetStore
Arithmetic and comparison operations in generic C# classes. Works with any value type, no setup required; supports source generation for AOT-safe custom types.[Website] [Documentation] [Public API]Arithmetic and comparison operations in generic C# classes. Works with any numeric or operator-enabled type, with no additional setup required.Built-in computators cover all Unity numeric and vector types; a Roslyn source generator adds AOT-safe support for custom types.FeaturesFull operator coverage: all C# arithmetic (+, -, *, /, %), bitwise (&, |, ^), unary, shift, and comparison operators, plus boolean evaluation (operator true / operator false)Any numeric or operator-enabled type: built-in computators cover int, float, double, long, Vector2, Vector3, and all other Unity numeric and vector types; custom types are supported via source generator or manual computatorsTwo usage styles: wrap values in Computable to use standard C# operator syntax inline, or call Calculate and Evaluate static methods directly for explicit result-type control and cross-type operationsSource generator: the [GenerateComputators] assembly-level attribute generates AOT-safe computators at compile time; the recommended approach for IL2CPP buildsManual computators: extend BinaryCalculator, UnaryCalculator, BinaryEvaluator, or UnaryEvaluator for full control over how each operation is implemented; discovered automatically at startup, no registration requiredTry methods: non-throwing variants of every Calculate and Evaluate method return false instead of throwing when an operation is not supported for the given typesConfigurable fallback: choose Throw, Dynamic, or Expression behavior for types without a registered computator, set per-project in the Configuration inspectorEditor tooling: bulk tests window to run all registered computators against a predefined value set and review color-coded results; creator tool to generate manual computator scripts from a windowContentComputable struct: lightweight value wrapper exposing all operators directly; implicit conversions to/from T and cross-type From / To castingCalculate and Evaluate static classes: method-call API for binary and unary operations with explicit result types; each has a nested Try class for non-throwing accessComputator system: built-in computators for all Unity numeric and vector types; [GenerateComputators] Roslyn source generator; four abstract base classes (BinaryCalculator, UnaryCalculator, BinaryEvaluator, UnaryEvaluator) for manual implementationConfiguration inspector: per-project fallback strategy and view of all registered built-in and user computatorsTests: NUnit test suite and a bulk tests window covering all computator type combinationsDemo: a benchmark scene comparing non-generic, naive generic, Computable, and Calculate approachesRequirementsUnity 6.0 or laterClaude code reviews and documentation generation.

