added yarn spinner package

This commit is contained in:
2026-08-14 13:27:17 +02:00
parent c140236bf7
commit c483bda3ea
573 changed files with 81459 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: ad1e0218baeab43be922ae40dbfb3ade
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/Action.cs
uploadId: 968678
@@ -0,0 +1,98 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System.Linq;
using UnityEditor;
using UnityEngine;
using Yarn.Unity;
namespace Yarn.Unity.Editor
{
public static class ActionSourceCodeGenerator
{
/// <summary>
/// Get a path in the current project that can be used for storing
/// manually-generated Yarn Action registration code.
/// </summary>
/// <remarks>
/// This property checks to see if a file exists in the Assets folder
/// that is both named "YarnActionRegistration.cs", and contains a
/// marker indicating that it was generated by Yarn Spinner's code
/// generation systems. If this is found, the path to the file is
/// returned. Otherwise, the path
/// <c>Assets/YarnActionRegistration.cs</c> is returned.
/// </remarks>
public static string GeneratedSourcePath
{
get
{
const string YarnRegistrationFileName = "YarnActionRegistration.cs";
const string DefaultOutputFilePath = "Assets/" + YarnRegistrationFileName;
// Note the lack of a closing parenthesis in this string - we
// only want to check to see if it was generated by
// "YarnActionAnalyzer", not any specific version of that
// analyzer
const string YarnGeneratedCodeSignature = "GeneratedCode(\"YarnActionAnalyzer\"";
var existingFile = System.IO.Directory.EnumerateFiles(System.Environment.CurrentDirectory, YarnRegistrationFileName, System.IO.SearchOption.AllDirectories).FirstOrDefault();
if (existingFile == null)
{
return DefaultOutputFilePath;
}
else
{
try
{
var text = System.IO.File.ReadAllText(existingFile);
return text.Contains(YarnGeneratedCodeSignature)
? existingFile
: DefaultOutputFilePath;
}
catch (System.Exception e)
{
// Something happened while checking the file. Return
// our default, and log that we encountered a problem.
Debug.LogWarning($"Can't check to see if {existingFile} is a valid action registration script, using {DefaultOutputFilePath} instead: {e}");
return DefaultOutputFilePath;
}
}
}
}
/// <summary>
/// Generates and imports a C# source code file in the project
/// containing Yarn Action registration code at the path indicated by
/// <see cref="GeneratedSourcePath"/>.
/// </summary>
/// <remarks>
/// This method should not be called in projects where Unity has support
/// for source generators (i.e. Unity 2021.2 and later).
/// </remarks>
public static void GenerateYarnActionSourceCode()
{
var analysis = new Yarn.Unity.ActionAnalyser.Analyser("Assets");
try
{
var actions = analysis.GetActions();
var source = Yarn.Unity.ActionAnalyser.Analyser.GenerateRegistrationFileSource(actions);
var path = GeneratedSourcePath;
System.IO.File.WriteAllText(path, source);
UnityEditor.AssetDatabase.ImportAsset(path);
Debug.Log($"Generated Yarn command and function registration code at {path}");
}
catch (Yarn.Unity.ActionAnalyser.AnalyserException e)
{
Debug.LogError($"Error generating source code: " + e.InnerException.ToString());
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: dabf0558de47a486199baa9e568783ce
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/ActionSourceCodeGenerator.cs
uploadId: 968678
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: ee966ea0c2700450080c5d533c3c5afc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/Analyser.cs
uploadId: 968678
@@ -0,0 +1,25 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System.Collections.Generic;
namespace Yarn.Unity.ActionAnalyser
{
[System.Serializable]
public class AnalyserException : System.Exception
{
public AnalyserException() { }
public AnalyserException(string message) : base(message) { }
public AnalyserException(string message, System.Exception inner) : base(message, inner) { }
public AnalyserException(string message, System.Exception inner, IEnumerable<Microsoft.CodeAnalysis.Diagnostic> diagnostics) : base(message, inner)
{
this.Diagnostics = diagnostics;
}
protected AnalyserException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
public IEnumerable<Microsoft.CodeAnalysis.Diagnostic> Diagnostics { get; } = new List<Microsoft.CodeAnalysis.Diagnostic>();
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 4318b63e7e2584e3895f7b9c8782154b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/AnalyserException.cs
uploadId: 968678
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7606c7073739c4bb380207502d25cf6b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,40 @@
fileFormatVersion: 2
guid: 4e596e8d36f4949e49a276da7dcf74d0
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/DLLs/Microsoft.CodeAnalysis.CSharp.dll
uploadId: 968678
@@ -0,0 +1,40 @@
fileFormatVersion: 2
guid: d0d5eb061e5a94e61918a4bcc8343d0f
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/DLLs/Microsoft.CodeAnalysis.dll
uploadId: 968678
@@ -0,0 +1,40 @@
fileFormatVersion: 2
guid: 05b4f6ee4402b4befa8b93e0b0f30072
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/DLLs/System.Buffers.dll
uploadId: 968678
@@ -0,0 +1,40 @@
fileFormatVersion: 2
guid: d36ed78c475f14eada798a8881d84f4a
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/DLLs/System.Collections.Immutable.dll
uploadId: 968678
@@ -0,0 +1,40 @@
fileFormatVersion: 2
guid: f124754956f07408dafc0d384a437712
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/DLLs/System.Memory.dll
uploadId: 968678
@@ -0,0 +1,40 @@
fileFormatVersion: 2
guid: 33c2c99bdbd9f48f1bfe7333e3c7f401
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/DLLs/System.Reflection.Metadata.dll
uploadId: 968678
@@ -0,0 +1,40 @@
fileFormatVersion: 2
guid: 8807786a5b21e4484ae712f0f92620db
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/DLLs/System.Runtime.CompilerServices.Unsafe.dll
uploadId: 968678
@@ -0,0 +1,40 @@
fileFormatVersion: 2
guid: 6b1c9dc69df6f47a38bd1ad37d4319bd
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/DLLs/System.Threading.Tasks.Extensions.dll
uploadId: 968678
@@ -0,0 +1,111 @@
using Microsoft.CodeAnalysis;
public static class Diagnostics
{
public static readonly DiagnosticDescriptor YS1000UnknownError = new DiagnosticDescriptor(
"YS0000",
title: $"Internal unknown error",
messageFormat: "An internal error was encountered while processing this action: {0}",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);
public static readonly DiagnosticDescriptor YS1001ActionMethodsMustBePublic = new DiagnosticDescriptor(
"YS1001",
title: $"Yarn action methods must be public",
messageFormat: "YarnCommand and YarnFunction methods must be public. \"{0}\" is {1}.",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "[YarnCommand] and [YarnFunction] attributed methods must be public so that the codegen can reference them.",
helpLinkUri: "https://docs.yarnspinner.dev/using-yarnspinner-with-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1002ActionMethodsMustHaveAValidName = new DiagnosticDescriptor(
"YS1002",
title: $"Yarn action methods must have a valid name",
messageFormat: "YarnCommand and YarnFunction methods must follow existing ID rules for Yarn. \"{0}\" is invalid.",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: "[YarnCommand] and [YarnFunction] attributed methods must follow Yarn ID rules so that Yarn scripts can reference them.",
helpLinkUri: "https://docs.yarnspinner.dev/using-yarnspinner-with-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1003CommandMethodsMustHaveAValidReturnType = new DiagnosticDescriptor(
"YS1003",
title: $"YarnCommand methods must return a valid type",
messageFormat: $"YarnCommand methods must return a valid type (either void, a coroutine, or a task). \"{{0}}\"'s return type is {{1}}.",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
helpLinkUri: "https://docs.yarnspinner.dev/using-yarnspinner-with-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1004FunctionMethodsMustHaveAValidReturnType = new DiagnosticDescriptor(
"YS1004",
title: $"YarnFunction methods must return a valid type",
messageFormat: $"YarnFunction methods must return a valid type (either bool, string, or a numeric type). \"{{0}}\"'s return type is {{1}}.",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
helpLinkUri: "https://docs.yarnspinner.dev/using-yarnspinner-with-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1005ActionMethodsMustHaveOneActionAttribute = new DiagnosticDescriptor(
"YS1005",
title: $"Yarn action methods must have a single YarnCommand or YarnAction attribute",
messageFormat: $"YarnCommand and YarnFunction methods must have a single attribute. \"{{0}}\" has {{1}}.",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: "https://docs.yarnspinner.dev/using-yarnspinner-with-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1006YarnFunctionsMustBeStatic = new DiagnosticDescriptor(
"YS1006",
title: $"YarnFunction methods be static",
messageFormat: $"YarnFunction methods are required to be static.",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
helpLinkUri: "https://docs.yarnspinner.dev/using-yarnspinner-with-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1008ActionsParamsArraysMustBeOfYarnTypes = new DiagnosticDescriptor(
"YS1008",
title: "Params arrays must be of a Yarn compatible type",
messageFormat: "Params arrays must be of a Yarn compatible type, but {0} is of type \"{1}\"",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: "https://docs.yarnspinner.dev/yarn-spinner-for-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1009ActionsEnumAttributedParameterIsOfIncompatibleType = new DiagnosticDescriptor(
"YS1009",
title: "Yarn Enum attributed parameters must be of a Yarn compatible type",
messageFormat: "Yarn Enum attributed parameters must be of a Yarn compatible type, but {0} is of type \"{1}\"",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: "https://docs.yarnspinner.dev/yarn-spinner-for-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1010ActionsNodeAttributedParameterIsOfIncompatibleType = new DiagnosticDescriptor(
"YS1010",
title: "Yarn Node attributed parameters must be a string",
messageFormat: "Yarn Node attributed parameters must be a string, but {0} is of type \"{1}\"",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: "https://docs.yarnspinner.dev/yarn-spinner-for-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1011ActionsParameterIsAnIncompatibleType = new DiagnosticDescriptor(
"YS1011",
title: "Yarn action parameters must be of a Yarn compatible type",
messageFormat: "Yarn action parameters must be of a Yarn compatible type, but {0} is of type \"{1}\"",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: "https://docs.yarnspinner.dev/yarn-spinner-for-unity/creating-commands-functions");
public static readonly DiagnosticDescriptor YS1012ActionIsALambda = new DiagnosticDescriptor(
"YS1012",
title: "Yarn actions can be lambdas but this generally isn't recommended",
messageFormat: "Yarn actions can be lambdas but this generally isn't recommended. Lambda based actions cannot be unregistered and are more difficult to debug",
category: "Yarn Spinner",
defaultSeverity: DiagnosticSeverity.Info,
isEnabledByDefault: true,
helpLinkUri: "https://docs.yarnspinner.dev/yarn-spinner-for-unity/creating-commands-functions");
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8ef837099f8664a9ab951ed2c6ba6e72
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/Diagnostics.cs
uploadId: 968678
@@ -0,0 +1,29 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections.Generic;
#nullable enable
static class EnumerableExtensions
{
public static IEnumerable<T> NonNull<T>(this IEnumerable<T?> collection, bool throwIfAnyNull = false) where T : class
{
foreach (var item in collection)
{
if (item != null)
{
yield return item;
}
else
{
if (throwIfAnyNull)
{
throw new NullReferenceException("Collection contains a null item");
}
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 1a3d39b6f28ae4a31989cb67e5aa3d98
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/EnumerableExtensions.cs
uploadId: 968678
@@ -0,0 +1,132 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
#endif
namespace Yarn.Unity
{
#nullable enable
public interface ILogger : IDisposable
{
void Write(object obj);
void WriteLine(object obj);
void WriteException(System.Exception ex, string? message = null);
void Inc();
void Dec();
void SetDepth(int depth);
}
public class FileLogger : ILogger
{
System.IO.TextWriter writer;
private int depth = 0;
public FileLogger(System.IO.TextWriter writer)
{
this.writer = writer;
}
public void Dispose()
{
writer.Flush();
writer.Dispose();
}
public void Write(object text)
{
var tabs = new String('\t', depth);
writer.Write(tabs + text);
}
public void WriteLine(object text)
{
var tabs = new String('\t', depth);
writer.WriteLine(tabs + text);
}
public void WriteException(System.Exception ex, string? message)
{
var tabs = new String('\t', depth);
if (message == null)
{
writer.WriteLine($"{tabs}Exception: {ex.Message}");
}
else
{
writer.WriteLine($"{tabs}{message}: {ex.Message}");
}
}
public void Inc()
{
depth +=1 ;
}
public void Dec()
{
depth = Math.Max(depth - 1, 0);
}
public void SetDepth(int depth)
{
this.depth = Math.Max(depth, 0);
}
}
public class UnityLogger : ILogger
{
public void Dispose() { }
public void Write(object text)
{
WriteLine(text);
}
public void WriteLine(object text)
{
var tabs = new String('\t', depth);
#if UNITY_EDITOR
Debug.LogWarning(tabs + text.ToString());
#endif
}
public void WriteException(System.Exception ex, string? message = null)
{
#if UNITY_EDITOR
Debug.LogException(ex);
#endif
}
private int depth = 0;
public void Inc()
{
depth +=1 ;
}
public void Dec()
{
depth = Math.Max(depth - 1, 0);
}
public void SetDepth(int depth)
{
this.depth = Math.Max(depth, 0);
}
}
public class NullLogger : ILogger
{
public void Dispose() { }
public void Write(object text) { }
public void WriteLine(object text) { }
public void WriteException(System.Exception ex, string? message = null) { }
public void Inc(){}
public void Dec(){}
public void SetDepth(int depth) {}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 45e3ce698d3364e5790443887a66daff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/ILogger.cs
uploadId: 968678
@@ -0,0 +1,79 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using Microsoft.CodeAnalysis;
using System.Linq;
#nullable enable
static class SymbolExtensions
{
/// <summary>
/// If the <paramref name="symbol"/> is a method symbol, returns <see langword="true"/> if the method's return type is "awaitable", but not if it's <see langword="dynamic"/>.
/// If the <paramref name="symbol"/> is a type symbol, returns <see langword="true"/> if that type is "awaitable".
/// An "awaitable" is any type that exposes a GetAwaiter method which returns a valid "awaiter". This GetAwaiter method may be an instance method or an extension method.
/// </summary>
public static bool IsAwaitableNonDynamic(this ISymbol symbol, SemanticModel semanticModel, int position)
{
IMethodSymbol? methodSymbol = symbol as IMethodSymbol;
ITypeSymbol? typeSymbol = null;
if (methodSymbol == null)
{
typeSymbol = symbol as ITypeSymbol;
if (typeSymbol == null)
{
return false;
}
}
else
{
if (methodSymbol.ReturnType == null)
{
return false;
}
}
// otherwise: needs valid GetAwaiter
var potentialGetAwaiters = semanticModel.LookupSymbols(position,
container: typeSymbol ?? methodSymbol?.ReturnType.OriginalDefinition,
name: WellKnownMemberNames.GetAwaiter,
includeReducedExtensionMethods: true);
var getAwaiters = potentialGetAwaiters.OfType<IMethodSymbol>().Where(x => !x.Parameters.Any());
return getAwaiters.Any(VerifyGetAwaiter);
}
private static bool VerifyGetAwaiter(IMethodSymbol getAwaiter)
{
var returnType = getAwaiter.ReturnType;
if (returnType == null)
{
return false;
}
// bool IsCompleted { get }
if (!returnType.GetMembers().OfType<IPropertySymbol>().Any(p => p.Name == WellKnownMemberNames.IsCompleted && p.Type.SpecialType == SpecialType.System_Boolean && p.GetMethod != null))
{
return false;
}
var methods = returnType.GetMembers().OfType<IMethodSymbol>();
// NOTE: (vladres) The current version of C# Spec, §7.7.7.3 'Runtime evaluation of await expressions', requires that
// NOTE: the interface method INotifyCompletion.OnCompleted or ICriticalNotifyCompletion.UnsafeOnCompleted is invoked
// NOTE: (rather than any OnCompleted method conforming to a certain pattern).
// NOTE: Should this code be updated to match the spec?
// void OnCompleted(Action)
// Actions are delegates, so we'll just check for delegates.
if (!methods.Any(x => x.Name == WellKnownMemberNames.OnCompleted && x.ReturnsVoid && x.Parameters.Length == 1 && x.Parameters.First().Type.TypeKind == TypeKind.Delegate))
{
return false;
}
// void GetResult() || T GetResult()
return methods.Any(m => m.Name == WellKnownMemberNames.GetResult && !m.Parameters.Any());
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 245397f2263474149856dba1cfc50f19
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 267061
packageName: Yarn Spinner+ for Unity, the friendly dialogue and narrative tool
packageVersion: 3.2.8
assetPath: Packages/dev.yarnspinner.unity/Editor/Analysis/SymbolExtensions.cs
uploadId: 968678