UnityCoroutinesAnalyzer 1.0.3.5
dotnet add package UnityCoroutinesAnalyzer --version 1.0.3.5
NuGet\Install-Package UnityCoroutinesAnalyzer -Version 1.0.3.5
<PackageReference Include="UnityCoroutinesAnalyzer" Version="1.0.3.5" />
paket add UnityCoroutinesAnalyzer --version 1.0.3.5
#r "nuget: UnityCoroutinesAnalyzer, 1.0.3.5"
// Install UnityCoroutinesAnalyzer as a Cake Addin #addin nuget:?package=UnityCoroutinesAnalyzer&version=1.0.3.5 // Install UnityCoroutinesAnalyzer as a Cake Tool #tool nuget:?package=UnityCoroutinesAnalyzer&version=1.0.3.5
A set of roslyn analyzers for convinient use of Unity coroutines
Git Hub repo
Analyzers
1. Coroutine invocation analyzer
As You know there is few ways to start a coroutine in unity:
Passing coroutine name:
StartCoroutine("Coroutine"); IEnumerator Coroutine() {}
Executing coroutine method:
StartCoroutine(Coroutine()); IEnumerator Coroutine() {}
Problems
Using the first one it is easy to make a mistake in coroutine name when writing string literal.
And if you would use the second one, you won't be able to stop the coroutine. Because you are creating an independent coroutine instance.
Solution
The first analyzer encourages you to start the coroutine using 'nameof' syntax:
StartCoroutine(nameof(Coroutine)); IEnumerator Coroutine() {}
So now you are able to call 'StopCoroutine' method with the expected result and avoid excessive mistakes.
2. Yield return in while(true)
block
Coroutines in Unity are often used in combinations with while(true)
block:
IEnumerator Coroutine()
{
while(true)
{
...
}
}
Problems
Although it is easy to forget to put yield return
statement inside while(true)
that leads to Unity crash,
Visual Studio doesn't have any embedded analyzers that prevents you from such problems. So the code above won't trigger any VisualStudio warnings or
recommendations.
Solution
Code analyzers in this package would warn you about possible issues and suggest to put yield return null;
on the end of while
block:
IEnumerator Coroutine()
{
while(true)
{
...
yield return null;
}
}
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Yield return in coroutines analyzer