-
-
Notifications
You must be signed in to change notification settings - Fork 245
Extensions
Andrew Rumak edited this page Sep 15, 2023
·
7 revisions
I will fill this page someday...
In the meantime, you can enable Intellisense to display self-documentation of these methods by following these steps: In Unity Editor, open Edit > Preferences > External Tools and enable "Generate .csproj files for" Registry packages and Git packages, then click "Regenerate project files". The next time you open Visual Studio, Intellisense will show you comments for MyBox's extension methods.
Source
Some sugary extensions for functional-style code
if (!enemy.Is<BossEnemy>()) .. instead of if (!(enemy is BossEnemy))
// Works with IConvertible types
1f.Cast<int>().InRange(someRangedInt) .. instead of ((int)1f).InRange(someRangedInt)
// As is exception-safe, instead of InvalidCastException it will return null
enemy.As<BossEnemy>()?.Pipe(b => { /* continue interacting with boss */ });
// Flow-style functions call
Func1(originalArgument).Pipe(Func2).Pipe(Func3).Pipe(Func4);
//Instead of
Func4(Func3(Func2(Func1(originalArgument))));
// With null check - call InitializeCheckpoint(Checkpoint c) if Checkpoint is found
GetComponentInChildren<Checkpoint>()?.Pipe(InitializeCheckpoint);
// And with PipeKeep:
var initializedCheckpoint = GetComponentInChildren<Checkpoint>()?.Pipe(InitializeCheckpoint);