This commit is contained in:
SoulliesOfficial
2026-06-09 11:21:59 -04:00
parent 7c60c40d6b
commit 021e76efe7
493 changed files with 50500 additions and 2211 deletions

View File

@@ -0,0 +1,798 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Threading.Tasks;
using UnityEngine;
#nullable enable
namespace Yarn.Unity
{
using ActionRegistrationMethod = System.Action<IActionRegistration, RegistrationType>;
using Converter = System.Func<string, int, object?>;
public enum RegistrationType
{
/// <summary>
/// Actions are being registered during a Yarn script compilation.
/// </summary>
Compilation,
/// <summary>
/// Actions are being registered for runtime use (i.e. during gameplay.)
/// </summary>
Runtime
}
public interface ICommand
{
string Name { get; }
}
internal static class DiagnosticUtility
{
public static string EnglishPluraliseNounCount(int count, string name, bool prefixCount = false)
{
string result = count == 1 ? name : name + "s";
return prefixCount ? $"{count} {result}" : result;
}
public static string EnglishPluraliseWasVerb(int count) => count == 1 ? "was" : "were";
}
public class Actions : ICommandDispatcher
{
internal class CommandRegistration : ICommand
{
public CommandRegistration(string name, Delegate @delegate)
{
Name = name;
Method = @delegate.Method;
Target = @delegate.Target;
Converters = CreateConverters(Method);
DynamicallyFindsTarget = false;
}
public CommandRegistration(string name, MethodInfo method)
{
if (method.IsStatic)
{
DynamicallyFindsTarget = false;
}
else if (typeof(Component).IsAssignableFrom(method.DeclaringType))
{
// This method is an instance method on a Component (or one
// of its subclasses). We'll dynamically find a target to
// invoke the method on at runtime.
DynamicallyFindsTarget = true;
}
else
{
// The instance method's declaring type is not a Component,
// which means we won't be able to look up a target.
throw new ArgumentException($"Cannot register method {GetFullMethodName(method)} as a command: instance methods must declared on {nameof(Component)} classes.");
}
Name = name;
Method = method;
Target = null;
Converters = CreateConverters(method);
}
public string Name { get; set; }
public MethodInfo Method { get; set; }
private object? Target { get; set; }
public Type DeclaringType => Method.DeclaringType;
public Type ReturnType => Method.ReturnType;
public bool IsStatic => Method.IsStatic;
public readonly Converter[] Converters;
/// <summary>
/// Gets a value indicating that this command finds a target to
/// invoke its method on by name, each time it is invoked.
/// </summary>
private bool DynamicallyFindsTarget { get; }
public CommandType Type
{
get
{
Type returnType = ReturnType;
if (typeof(void).IsAssignableFrom(returnType))
{
return CommandType.IsVoid;
}
if (typeof(IEnumerator).IsAssignableFrom(returnType))
{
return CommandType.IsCoroutine;
}
if (typeof(Coroutine).IsAssignableFrom(returnType))
{
return CommandType.ReturnsCoroutine;
}
return CommandType.Invalid;
}
}
public enum CommandType
{
/// <summary>
/// The method returns <see cref="void"/>.
/// </summary>
IsVoid,
/// <summary>
/// The method returns a <see cref="Coroutine"/> object.
/// </summary>
/// <remarks>
ReturnsCoroutine,
/// <summary>
/// The method returns <see cref="IEnumerator"/> (that is, it is
/// a coroutine).
/// </summary>
/// <remarks>
/// Code that invokes this command should use <see
/// cref="MonoBehaviour.StartCoroutine(IEnumerator)"/> to begin
/// the coroutine.
/// </remarks>
IsCoroutine,
/// <summary>
/// The method is not a valid command (that is, it does not
/// return <see cref="void"/>, <see cref="Coroutine"/>, or <see
/// cref="IEnumerator"/>.)
/// </summary>
Invalid,
}
/// <summary>
/// Attempt to parse the arguments with cached converters.
/// </summary>
public CommandDispatchResult.ParameterParseStatusType TryParseArgs(string[] args, out object?[]? result, out string? message)
{
var parameters = Method.GetParameters();
var lastParameterIsArray = parameters.Length > 0 && parameters[parameters.Length - 1].ParameterType.IsArray;
var (min, max) = ParameterCount;
int argumentCount = args.Length;
if (argumentCount < min || (argumentCount > max && !lastParameterIsArray))
{
// Wrong number of arguments.
string requirementDescription;
if (min == 0)
{
requirementDescription = $"at most {max} {DiagnosticUtility.EnglishPluraliseNounCount(max, "parameter")}";
}
else if (min != max)
{
requirementDescription = $"between {min} and {max} {DiagnosticUtility.EnglishPluraliseNounCount(max, "parameter")}";
}
else
{
requirementDescription = $"{min} {DiagnosticUtility.EnglishPluraliseNounCount(max, "parameter")}";
}
message = $"{this.Name} requires {requirementDescription}, but {argumentCount} {DiagnosticUtility.EnglishPluraliseWasVerb(argumentCount)} provided.";
result = default;
return CommandDispatchResult.ParameterParseStatusType.InvalidParameterCount;
}
var finalArgs = new object?[parameters.Length];
var argsQueue = new Queue(args);
var paramsArgs = new List<object>();
for (int i = 0; i < argumentCount; i++)
{
var parameterIsArray = parameters[i].ParameterType.IsArray;
string arg = args[i];
Converter converter = Converters[i];
if (parameterIsArray)
{
if (i < parameters.Length - 1)
{
// The parameter is an array, but it isn't the last
// parameter. That's not allowed.
message = $"Parameter {i} ({parameters[i].Name}): is an array, but is not the last parameter of {parameters[i].Member.Name}.";
result = default;
return CommandDispatchResult.ParameterParseStatusType.InvalidParameterType;
}
// Consume all remaining arguments, passing them through
// the final converter, and produce an array from the
// results. This array will be the final parameter to
// the method.
var parameterArrayElementType = parameters[i].ParameterType.GetElementType();
var paramIndex = i;
// var paramsArray = new List<object?>();
var paramsArray = Array.CreateInstance(parameterArrayElementType, argumentCount - i);
while (i < argumentCount)
{
arg = args[i];
if (converter == null)
{
// Use relative index into paramsArray
paramsArray.SetValue(arg, i - paramIndex);
}
else
{
try
{
paramsArray.SetValue(converter.Invoke(arg, i), i - paramIndex);
}
catch (Exception e)
{
message = $"Can't convert parameter {i} to {parameterArrayElementType.Name}: {e.Message}";
result = default;
return CommandDispatchResult.ParameterParseStatusType.InvalidParameterType;
}
}
i += 1;
}
finalArgs[paramIndex] = paramsArray;
}
else
{
// Consume a single argument
if (converter == null)
{
finalArgs[i] = arg;
}
else
{
try
{
finalArgs[i] = converter.Invoke(arg, i);
}
catch (Exception e)
{
message = $"Can't convert parameter {i} to {parameters[i].ParameterType.Name}: {e.Message}";
result = default;
return CommandDispatchResult.ParameterParseStatusType.InvalidParameterType;
}
}
}
}
for (int i = argumentCount; i < finalArgs.Length; i++)
{
var parameter = parameters[i];
if (parameter.IsOptional)
{
// If this parameter is optional, provide the Missing
// type.
finalArgs[i] = System.Type.Missing;
}
else if (parameter.GetCustomAttribute<ParamArrayAttribute>() != null)
{
// If the parameter is a params array, provide an empty
// array of the appropriate type.
finalArgs[i] = Array.CreateInstance(parameter.ParameterType.GetElementType(), 0);
}
else
{
throw new InvalidOperationException($"Can't provide a default value for parameter {parameter.Name}");
}
}
result = finalArgs;
message = default;
return CommandDispatchResult.ParameterParseStatusType.Succeeded;
}
private (int Min, int Max) ParameterCount
{
get
{
var parameters = Method.GetParameters();
int optional = 0;
bool lastCommandIsParams = false;
foreach (var parameter in parameters)
{
if (parameter.IsOptional)
{
optional += 1;
}
if (parameter.ParameterType.IsArray && parameter.GetCustomAttribute<ParamArrayAttribute>() != null)
{
// If the parameter is a params array, then:
// 1. It's 'optional' in that you can pass in no
// values (so, for our purposes, the minimum
// number of parameters you need to pass is not
// changed)
// 2. The maximum number of parameters you can pass
// is now effectively unbounded.
lastCommandIsParams = true;
optional += 1;
}
}
int min = parameters.Length - optional;
int max = parameters.Length;
if (lastCommandIsParams)
{
max = int.MaxValue;
}
return (min, max);
}
}
internal CommandDispatchResult Invoke(MonoBehaviour dispatcher, List<string> parameters)
{
object? target;
if (DynamicallyFindsTarget)
{
// We need to find a target to call this method on.
if (parameters.Count == 0)
{
// We need at least one parameter, which is the
// component to look for
return new CommandDispatchResult(CommandDispatchResult.StatusType.InvalidParameterCount, YarnTask.CompletedTask)
{
Message = $"{this.Name} needs a target, but none was specified",
};
}
// First parameter is the name of a game object that has the
// component we're trying to call.
var gameObjectName = parameters[0];
parameters.RemoveAt(0);
var gameObject = GameObject.Find(gameObjectName);
if (gameObject == null)
{
// We couldn't find a target with this name.
return new CommandDispatchResult(CommandDispatchResult.StatusType.TargetMissingComponent)
{
Message = $"No game object named \"{gameObjectName}\" exists",
};
}
// We've found a target. Does it have a component that's
// the right type of object to call the method on?
var targetComponent = gameObject.GetComponent(this.DeclaringType);
if (targetComponent == null)
{
return new CommandDispatchResult(CommandDispatchResult.StatusType.TargetMissingComponent)
{
Message = $"{this.Name} can't be called on {gameObjectName}, because it doesn't have a {this.DeclaringType.Name}",
};
}
target = targetComponent;
}
else if (Method.IsStatic)
{
// The method is static; it therefore doesn't need a target.
target = null;
}
else if (Target != null)
{
// The method is an instance method, so use the target we've
// stored.
target = Target;
}
else
{
// We don't know what to call this method on.
throw new InvalidOperationException($"Internal error: {nameof(CommandRegistration)} \"{this.Name}\" has no {nameof(Target)}, but method is not static and ${DynamicallyFindsTarget} is false");
}
var parseArgsStatus = this.TryParseArgs(parameters.ToArray(), out var finalParameters, out var errorMessage);
if (parseArgsStatus != CommandDispatchResult.ParameterParseStatusType.Succeeded)
{
var status = parseArgsStatus switch
{
CommandDispatchResult.ParameterParseStatusType.Succeeded => CommandDispatchResult.StatusType.Succeeded,
CommandDispatchResult.ParameterParseStatusType.InvalidParameterType => CommandDispatchResult.StatusType.InvalidParameter,
CommandDispatchResult.ParameterParseStatusType.InvalidParameterCount => CommandDispatchResult.StatusType.InvalidParameterCount,
_ => throw new InvalidOperationException("Internal error: invalid parameter parse result " + parseArgsStatus),
};
return new CommandDispatchResult(status)
{
Message = errorMessage,
};
}
var returnValue = this.Method.Invoke(target, finalParameters);
if (returnValue is Coroutine coro)
{
// The method returned a Coroutine object.
return new CommandDispatchResult(
CommandDispatchResult.StatusType.Succeeded,
dispatcher.WaitForCoroutine(coro)
);
}
else if (returnValue is YarnTask yarnTask)
{
return new CommandDispatchResult(
CommandDispatchResult.StatusType.Succeeded,
yarnTask
);
}
#if UNITY_2023_1_OR_NEWER
else if (returnValue is Awaitable awaitable)
{
// The method returned an Awaitable. Convert it to a
// YarnTask. (Awaitables implement IEnumerator, so check
// this before testing against other IEnumerators like
// coroutines.)
return new CommandDispatchResult(
CommandDispatchResult.StatusType.Succeeded,
awaitable
);
}
#endif
else if (returnValue is IEnumerator enumerator)
{
// The method returned an IEnumerator.
return new CommandDispatchResult(
CommandDispatchResult.StatusType.Succeeded,
dispatcher.WaitForCoroutine(enumerator)
);
}
else if (returnValue is System.Threading.Tasks.Task task)
{
// The method returned a task. Convert it to a YarnTask.
return new CommandDispatchResult(
CommandDispatchResult.StatusType.Succeeded,
task
);
}
#if USE_UNITASK
else if (returnValue is Cysharp.Threading.Tasks.UniTask unitask)
{
// The method returned a UniTask. Convert it to a YarnTask.
return new CommandDispatchResult(
CommandDispatchResult.StatusType.Succeeded,
unitask
);
}
#endif
else
{
// The method returned no value.
return new CommandDispatchResult(CommandDispatchResult.StatusType.Succeeded);
}
}
public string UsageString
{
get
{
var components = new List<string>();
components.Add(Name);
if (DynamicallyFindsTarget)
{
var declaringTypeName = DeclaringType.Name;
components.Add($"target <i>({declaringTypeName})</i>");
}
foreach (var parameter in Method.GetParameters())
{
var type = parameter.ParameterType;
string typeName;
if (TypeFriendlyNames.TryGetValue(type, out typeName) == false)
{
typeName = type.Name;
}
string displayName = $"{parameter.Name} <i>({typeName})</i>";
if (parameter.IsOptional)
{
displayName = $"[{displayName} = {parameter.DefaultValue}]";
}
components.Add(displayName);
}
return string.Join(" ", components);
}
}
readonly Dictionary<Type, string> TypeFriendlyNames = new Dictionary<Type, string> {
{ typeof(int), "number" },
{ typeof(float), "number" },
{ typeof(double), "number" },
{ typeof(Decimal), "number" },
{ typeof(string), "string" },
{ typeof(bool), "bool" },
};
}
private Dictionary<string, CommandRegistration> _commands = new Dictionary<string, CommandRegistration>();
public Library Library { get; }
public IActionRegistration ActionRegistrar { get; }
public IEnumerable<ICommand> Commands => _commands.Values;
public Actions(IActionRegistration actionRegistrar, Library library)
{
Library = library;
ActionRegistrar = actionRegistrar;
}
private static string GetFullMethodName(MethodInfo method)
{
return $"{method.DeclaringType.FullName}.{method.Name}";
}
public void RegisterActions()
{
foreach (var registrationFunction in ActionRegistrationMethods)
{
registrationFunction.Invoke(ActionRegistrar, RegistrationType.Runtime);
}
}
public void AddCommandHandler(string commandName, Delegate handler)
{
if (commandName.Contains(' '))
{
Debug.LogError($"Failed to register command {commandName}: command names are not allowed to contain spaces.");
return;
}
if (_commands.ContainsKey(commandName))
{
Debug.LogError($"Failed to register command {commandName}: a command by this name has already been registered.");
return;
}
else
{
#if YARN_SOURCE_GENERATION_DEBUG_LOGGING
Debug.Log($"Registering command {commandName}");
#endif
_commands.Add(commandName, new CommandRegistration(commandName, handler));
}
}
public void AddFunction(string name, Delegate implementation)
{
if (name.Contains(' '))
{
Debug.LogError($"Cannot add function {name}: function names are not allowed to contain spaces.");
return;
}
if (Library.FunctionExists(name))
{
Debug.LogError($"Cannot add function {name}: one already exists");
return;
}
#if YARN_SOURCE_GENERATION_DEBUG_LOGGING
Debug.Log($"Registering command {name} from method {implementation.Method.DeclaringType.FullName}.{implementation.Method.Name}");
#endif
Library.RegisterFunction(name, implementation);
}
public void AddCommandHandler(string commandName, MethodInfo methodInfo)
{
if (commandName.Contains(' '))
{
Debug.LogError($"Failed to register command {commandName}: command names are not allowed to contain spaces.");
return;
}
if (_commands.ContainsKey(commandName))
{
Debug.LogError($"Failed to register command {commandName}: a command by this name has already been registered.");
return;
}
else
{
_commands.Add(commandName, new CommandRegistration(commandName, methodInfo));
}
}
public void RemoveCommandHandler(string commandName)
{
if (_commands.Remove(commandName) == false)
{
Debug.LogError($"Can't remove command {commandName}, because no command with this name is currently registered.");
}
}
public void RemoveFunction(string name)
{
if (Library.FunctionExists(name) == false)
{
Debug.LogError($"Cannot remove function {name}: no function with that name exists in the library");
return;
}
Library.DeregisterFunction(name);
}
public void SetupForProject(YarnProject yarnProject)
{
// no-op
}
CommandDispatchResult ICommandDispatcher.DispatchCommand(string command, MonoBehaviour coroutineHost)
{
var commandPieces = new List<string>(DialogueRunner.SplitCommandText(command));
if (commandPieces.Count == 0)
{
// No text was found inside the command, so we won't be able to
// find it.
return new CommandDispatchResult(CommandDispatchResult.StatusType.CommandUnknown, YarnTask.CompletedTask);
}
if (_commands.TryGetValue(commandPieces[0], out var registration))
{
// The first part of the command is the command name itself.
// Remove it to get the collection of parameters that were
// passed to the command.
commandPieces.RemoveAt(0);
return registration.Invoke(coroutineHost, commandPieces);
}
else
{
return new CommandDispatchResult(CommandDispatchResult.StatusType.CommandUnknown);
}
}
private static Converter[] CreateConverters(MethodInfo method)
{
ParameterInfo[] parameterInfos = method.GetParameters();
Converter[] result = new Converter[parameterInfos.Length];
int i = 0;
foreach (var parameterInfo in parameterInfos)
{
if (parameterInfo.ParameterType.IsArray)
{
// Array parameters are permitted, but only if they're the
// last parameter
if (i != parameterInfos.Length - 1)
{
throw new ArgumentException($"Can't register method {method.Name}: Parameter {i + 1} ({parameterInfo.Name}): array parameters are required to be last.");
}
}
result[i] = CreateConverter(parameterInfo, i);
i++;
}
return result;
}
private static System.Func<string, int, object?> CreateConverter(ParameterInfo parameter, int index)
{
var targetType = parameter.ParameterType;
string name = parameter.Name;
if (targetType.IsArray)
{
// This parameter is a params array. Make a converter for that
// array's element type; at dispatch time, we'll repeatedly call
// it with the arguments found in the command.
var paramsArrayType = targetType.GetElementType();
var elementConverter = CreateConverterFunction(paramsArrayType, name);
return elementConverter;
}
else
{
// This parameter is for a single value. Make a converter that
// receives a single string,
return CreateConverterFunction(targetType, name);
}
}
private static Converter CreateConverterFunction(Type targetType, string parameterName)
{
// well, I mean...
if (targetType == typeof(string)) { return (arg, i) => arg; }
// find the GameObject.
if (typeof(GameObject).IsAssignableFrom(targetType))
{
return (arg, i) => GameObject.Find(arg);
}
// find components of the GameObject with the component, if
// available
if (typeof(Component).IsAssignableFrom(targetType))
{
return (arg, i) =>
{
GameObject gameObject = GameObject.Find(arg);
if (gameObject == null)
{
return null;
}
return gameObject.GetComponentInChildren(targetType);
};
}
// bools can take "true" or "false", or the parameter name.
if (typeof(bool).IsAssignableFrom(targetType))
{
return (arg, i) =>
{
// If the argument is the name of the parameter, interpret
// the argument as 'true'.
if (arg.Equals(parameterName, StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
// If the argument can be parsed as boolean true or false,
// return that result.
if (bool.TryParse(arg, out bool res))
{
return res;
}
// We can't parse the argument.
throw new ArgumentException(
$"Can't convert the given parameter at position {i + 1} (\"{arg}\") to parameter " +
$"{parameterName} of type {typeof(bool).FullName}.");
};
}
// Fallback: try converting using IConvertible.
return (arg, i) =>
{
try
{
return Convert.ChangeType(arg, targetType, CultureInfo.InvariantCulture);
}
catch (Exception e)
{
throw new ArgumentException(
$"Can't convert the given parameter at position {i + 1} (\"{arg}\") to parameter " +
$"{parameterName} of type {targetType.FullName}: {e}", e);
}
};
}
internal static HashSet<ActionRegistrationMethod> ActionRegistrationMethods = new HashSet<ActionRegistrationMethod>();
public static void AddRegistrationMethod(ActionRegistrationMethod registerActions)
{
ActionRegistrationMethods.Add(registerActions);
}
public void AddCommandHandler(string commandName, Func<object> handler)
{
this.AddCommandHandler(commandName, (Delegate)handler);
}
public void RegisterFunctionDeclaration(string name, Type returnType, Type[] parameterTypes) { /* no-op */ }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4391b446168f14c48b3836dc19ddc1b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
#nullable enable
namespace Yarn.Unity
{
/// <summary>
/// Represents the result of attempting to locate and call a command.
/// </summary>
/// <seealso cref="DispatchCommandToGameObject(Command, Action)"/>
/// <seealso cref="DispatchCommandToRegisteredHandlers(Command, Action)"/>
internal struct CommandDispatchResult
{
internal enum ParameterParseStatusType
{
Succeeded,
InvalidParameterType,
InvalidParameterCount,
}
internal enum StatusType
{
Succeeded,
NoTargetFound,
TargetMissingComponent,
InvalidParameterCount,
InvalidParameter,
/// <summary>
/// The command could not be found.
/// </summary>
CommandUnknown,
};
internal StatusType Status;
internal string? Message;
internal YarnTask Task;
public CommandDispatchResult(StatusType status)
{
Status = status;
Task = YarnTask.CompletedTask;
Message = null;
}
public CommandDispatchResult(StatusType status, YarnTask task)
{
Status = status;
Task = task;
Message = null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 30bd9b6f785e7433091f2a4e6eae7397
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
internal class DemoAction
{
public static async System.Threading.Tasks.Task DemoCommandAsync()
{
await System.Threading.Tasks.Task.Delay(1000);
}
}
namespace Yarn.Unity
{
internal class DefaultActions : MonoBehaviour
{
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoadMethod]
#endif
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void AddRegisterFunction()
{
// When the domain is reloaded, scripts are recompiled, or the game
// starts, add RegisterActions as a method that populates a
// DialogueRunner or Library with commands and functions.
Actions.AddRegistrationMethod(RegisterActions);
}
public static void RegisterActions(IActionRegistration target, RegistrationType registrationType)
{
// Register the built-in methods and commands from Yarn Spinner for Unity.
target.AddCommandHandler<float>("wait", Wait);
}
#region Commands
/// <summary>
/// Yarn Spinner defines two built-in commands: "wait", and "stop".
/// Stop is defined inside the Virtual Machine (the compiler traps it
/// and makes it a special case.) Wait is defined here in Unity.
/// </summary>
/// <param name="duration">How long to wait, in seconds.</param>
[YarnCommand("wait")]
public static IEnumerator Wait(float duration)
{
yield return new WaitForSeconds(duration);
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b4a0cf97a220d5a4cb56a2509f5d51cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,327 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections;
using System.Reflection;
using UnityEngine;
#nullable enable
namespace Yarn.Unity
{
/// <summary>
/// Contains methods that allow adding and removing Yarn commands and
/// functions.
/// </summary>
public interface IActionRegistration
{
/// <summary>
/// Adds a command handler. Dialogue will pause execution after the
/// command is called.
/// </summary>
/// <remarks>
/// <para>When this command handler has been added, it can be called
/// from your Yarn scripts like so:</para>
///
/// <code lang="yarn">
/// &lt;&lt;commandName param1 param2&gt;&gt;
/// </code>
///
/// <para>If <paramref name="handler"/> is a method that returns a <see
/// cref="Coroutine"/>, when the command is run, the <see
/// cref="DialogueRunner"/> will wait for the returned coroutine to stop
/// before delivering any more content.</para>
/// <para>If <paramref name="handler"/> is a method that returns an <see
/// cref="IEnumerator"/>, when the command is run, the <see
/// cref="DialogueRunner"/> will start a coroutine using that method and
/// wait for that coroutine to stop before delivering any more content.
/// </para>
/// </remarks>
/// <param name="commandName">The name of the command.</param>
/// <param name="handler">The <see cref="CommandHandler"/> that will be
/// invoked when the command is called.</param>
void AddCommandHandler(string commandName, Delegate handler);
/// <inheritdoc cref="AddCommandHandler(string, Delegate)"/>
/// <param name="commandName">The name of the command.</param>
/// <param name="methodInfo">The method that will be invoked when the
/// command is called.</param>
void AddCommandHandler(string commandName, MethodInfo methodInfo);
/// <summary>
/// Removes a command handler.
/// </summary>
/// <param name="commandName">The name of the command to remove.</param>
void RemoveCommandHandler(string commandName);
/// <summary>
/// Add a new function that returns a value, so that it can be called
/// from Yarn scripts.
/// </summary>
/// <remarks>
/// <para>When this function has been registered, it can be called from
/// your Yarn scripts like so:</para>
///
/// <code lang="yarn">
/// &lt;&lt;if myFunction(1, 2) == true&gt;&gt;
/// myFunction returned true!
/// &lt;&lt;endif&gt;&gt;
/// </code>
///
/// <para>The <c>call</c> command can also be used to invoke the function:</para>
///
/// <code lang="yarn">
/// &lt;&lt;call myFunction(1, 2)&gt;&gt;
/// </code>
/// </remarks>
/// <param name="name">The name of the function to add.</param>
/// <param name="implementation">The <see cref="Delegate"/> that
/// should be invoked when this function is called.</param>
/// <seealso cref="Library"/>
void AddFunction(string name, Delegate implementation);
/// <summary>
/// Remove a registered function.
/// </summary>
/// <remarks>
/// After a function has been removed, it cannot be called from
/// Yarn scripts.
/// </remarks>
/// <param name="name">The name of the function to remove.</param>
/// <seealso cref="AddFunction(string, Delegate)"/>
void RemoveFunction(string name);
/// <summary>
/// Registers a function as existing, without supplying an implementation.
/// </summary>
/// <param name="name">The name of the function.</param>
/// <param name="returnType">The return type of the function.</param>
/// <param name="parameterTypes">The types of the function's parameters.</param>
void RegisterFunctionDeclaration(string name, Type returnType, Type[] parameterTypes);
}
/// <summary>
/// Contains extension methods for <see cref="IActionRegistration"/>
/// objects.
/// </summary>
public static class ActionRegistrationExtension
{
// These registrations for System.Action were generated by action-gyb.py
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler(this IActionRegistration registration, string commandName, System.Action handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1>(this IActionRegistration registration, string commandName, System.Action<T1> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2>(this IActionRegistration registration, string commandName, System.Action<T1, T2> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7, T8> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(this IActionRegistration registration, string commandName, System.Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
// These registrations for System.Threading.Tasks.Task were generated by action-gyb.py
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler(this IActionRegistration registration, string commandName, System.Func<System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1>(this IActionRegistration registration, string commandName, System.Func<T1, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2>(this IActionRegistration registration, string commandName, System.Func<T1, T2, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, System.Threading.Tasks.Task> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
// These registrations for YarnTask were generated by action-gyb.py
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler(this IActionRegistration registration, string commandName, System.Func<YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1>(this IActionRegistration registration, string commandName, System.Func<T1, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2>(this IActionRegistration registration, string commandName, System.Func<T1, T2, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, YarnTask> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
// These registrations for IEnumerator were generated by action-gyb.py
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler(this IActionRegistration registration, string commandName, System.Func<IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1>(this IActionRegistration registration, string commandName, System.Func<T1, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2>(this IActionRegistration registration, string commandName, System.Func<T1, T2, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, IEnumerator> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
// These registrations for Coroutine were generated by action-gyb.py
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler(this IActionRegistration registration, string commandName, System.Func<Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1>(this IActionRegistration registration, string commandName, System.Func<T1, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2>(this IActionRegistration registration, string commandName, System.Func<T1, T2, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>
public static void AddCommandHandler<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(this IActionRegistration registration, string commandName, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, Coroutine> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);
/// <inheritdoc cref="IActionRegistration.AddFunction(string, Delegate)"/>
/// <typeparam name="TResult">The result of the function.</typeparam>
public static void AddFunction<TResult>(this IActionRegistration registration, string name, System.Func<TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, TResult>(this IActionRegistration registration, string name, System.Func<T1, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, T2, TResult>(this IActionRegistration registration, string name, System.Func<T1, T2, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, T2, T3, TResult>(this IActionRegistration registration, string name, System.Func<T1, T2, T3, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, T2, T3, T4, TResult>(this IActionRegistration registration, string name, System.Func<T1, T2, T3, T4, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, T2, T3, T4, T5, TResult>(this IActionRegistration registration, string name, System.Func<T1, T2, T3, T4, T5, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, T2, T3, T4, T5, T6, TResult>(this IActionRegistration registration, string name, System.Func<T1, T2, T3, T4, T5, T6, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, T2, T3, T4, T5, T6, T7, TResult>(this IActionRegistration registration, string name, System.Func<T1, T2, T3, T4, T5, T6, T7, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this IActionRegistration registration, string name, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(this IActionRegistration registration, string name, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
/// <inheritdoc cref="AddFunction{TResult}(IActionRegistration, string, Func{TResult})"/>
public static void AddFunction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(this IActionRegistration registration, string name, System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> implementation) => registration.AddFunction(name, (Delegate)implementation);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2617d5a5b00346a095c9910f778653e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections.Generic;
using UnityEngine;
#nullable enable
namespace Yarn.Unity
{
interface ICommandDispatcher : IActionRegistration
{
CommandDispatchResult DispatchCommand(string command, MonoBehaviour coroutineHost);
void SetupForProject(YarnProject yarnProject);
IEnumerable<ICommand> Commands { get; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a7e8437a5e3540c7b04f1a91aec8809
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#nullable enable
namespace Yarn.Unity
{
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public abstract class YarnActionAttribute : Attribute
{
/// <summary>
/// The name of the command or function, as it exists in Yarn.
/// </summary>
/// <remarks>
/// This value does not have to be the same as the name of the method.
/// For example, you could have a method named "`WalkToPoint`", and
/// expose it to Yarn as a command named "`walk_to_point`".
/// </remarks>
public string? Name { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="YarnActionAttribute"/>
/// class.
/// </summary>
/// <param name="name">The name of the action. If not provided or <see
/// langword="null"/>, the name of the method is used instead.</param>
public YarnActionAttribute(string? name = null) => Name = name;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2f0c2f9c8c291c54a866e5d2cbda947f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections;
using UnityEngine;
#nullable enable
namespace Yarn.Unity
{
#region Class/Interface
/// <summary>
/// An attribute that marks a method on an object as a command.
/// </summary>
/// <remarks>
/// <para>
/// When a <see cref="DialogueRunner"/> receives a <see cref="Command"/>,
/// and no command handler has been installed for the command, it splits it
/// by spaces, and then checks to see if the second word, if any, is the
/// name of an object.
/// </para>
/// <para>
/// By default, it checks for any <see cref="GameObject"/>s in the scene. If
/// one is found, it is checked to see if any of the <see
/// cref="MonoBehaviour"/>s attached to the class has a <see
/// cref="YarnCommandAttribute"/> whose <see
/// cref="YarnActionAttribute.Name"/> matches the first word of the command.
/// </para>
/// <para>If the method is static, it will not try to use an object.</para>
/// <para>If a method is found, its parameters are checked:</para>
/// <list type="bullet">
/// <item>
/// If the method takes a single <see cref="string"/>[] parameter, the
/// method is called, and will be passed an array containing all words in
/// the command after the first two.
/// </item>
/// <item>
/// If the method takes a number of parameters equal to the number of words
/// in the command after the first two, it will be called with those words
/// as parameters.
/// </item>
/// <item>
/// If a parameter is a <see cref="GameObject"/>, we look up the object
/// using <see cref="GameObject.Find(string)"/>. As per the API, the game
/// object must be active.
/// </item>
/// <item>
/// If a parameter is assignable to <see cref="Component"/>, we will locate
/// the component based on the name of the object. As per the API of <see
/// cref="GameObject.Find(string)"/>, the game object must be active.
/// </item>
/// <item>
/// If a parameter is a <see cref="bool"/>, the string must be <c>true</c>
/// or <c>false</c> (as defined by the standard converter for <see
/// cref="string"/> to <see cref="bool"/>). However, we also allow for the
/// string to equal the parameter name, case insensitive. This allows us to
/// write commands with more self-documenting parameters, eg for a certain
/// <c>Move(bool wait)</c>, you could write <c>&lt;&lt;move wait&gt;&gt;</c>
/// instead of <c>&lt;&lt;move true&gt;&gt;</c>.
/// </item>
/// <item>
/// For any other type, we will attempt to convert using <see
/// cref="Convert.ChangeType(object, Type, IFormatProvider)"/> using the
/// <see cref="System.Globalization.CultureInfo.InvariantCulture"/> culture.
/// This means that you can implement <see cref="IConvertible"/> to add new
/// accepted types. (Do be aware that it's a non-CLS compliant interface,
/// according to its docs. Mono for Unity seems to implement it, but you may
/// have trouble if you use any other CLS implementation.)
/// </item>
/// <item>Otherwise, it will not be called, and a warning will be
/// issued.</item>
/// </list>
/// <para>This attribute may be attached to a coroutine or to an async
/// method.</para>
/// <para style="note">
/// The <see cref="DialogueRunner"/> determines if the method is a coroutine
/// if the method returns <see cref="IEnumerator"/>, or if the method
/// returns a <see cref="Coroutine"/> or a task.
/// </para>
/// <para>
/// If the method is a coroutine, returns a <see cref="Coroutine"/>, or
/// returns a task, the DialogueRunner will pause execution until the the
/// coroutine or task ends.
/// </para>
/// </remarks>
public class YarnCommandAttribute : YarnActionAttribute
{
/// <inheritdoc/>
public YarnCommandAttribute(string? name = null) => Name = name;
}
#endregion
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 02d713a1d2f0543e1bc85a3a92d8b0be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
#nullable enable
namespace Yarn.Unity.Attributes
{
public class YarnEnumParameterAttribute: YarnParameterAttribute
{
public string Name { get; set; }
public YarnEnumParameterAttribute(string name) => Name = name;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 16f4bd44fa86c426896ef49b7fd5b8ae

View File

@@ -0,0 +1,41 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#nullable enable
namespace Yarn.Unity
{
/// <summary>
/// Marks the method as a function to be registered with the running
/// instance's library.
/// </summary>
/// <remarks>
/// <para>
/// See <see cref="Library.RegisterFunction(string, Delegate)"/> and the
/// generic overloads for what is and is not valid.
/// </para>
/// <para>
/// This will throw an error if you attempt to add a function that has
/// more than 16 parameters, as that is the largest overload that
/// <see cref="Func{TResult}"/> etc has.
/// </para>
/// <para>
/// Yarn Spinner for Unity finds methods with the YarnFunction attribute by
/// reading your source code. If your project uses Unity 2021.1 or earlier,
/// you will need to tell Yarn Spinner for Unity to do this manually, by
/// opening the Window method and choosing Yarn Spinner -&gt; Update Yarn
/// Commands. You don't need to do this on later versions of Unity, as it
/// will be done for you automatically when your code compiles.
/// </para>
/// </remarks>
public class YarnFunctionAttribute : YarnActionAttribute
{
public YarnFunctionAttribute(string? name = null) => Name = name;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 28f9b4504ad08b44eacded4f51e04639
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#nullable enable
namespace Yarn.Unity.Attributes
{
public class YarnNodeParameterAttribute: YarnParameterAttribute {}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d85dfb63b41e44754af57565cc72b827

View File

@@ -0,0 +1,18 @@
/*
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#nullable enable
namespace Yarn.Unity.Attributes
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public abstract class YarnParameterAttribute : Attribute
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 27cc4a9336b0d4543a8885b64dfde71a

View File

@@ -0,0 +1,33 @@
all_types = ["System.Action", "System.Threading.Tasks.Task", "YarnTask", "IEnumerator", "Coroutine", "Awaitable", "UniTask"]
doc_template = '/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>'
imp_template = "public static void AddCommandHandler(this IActionRegistration registration, string commandName, System.Func<{0}> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);"
imp_numeric_template = "public static void AddCommandHandler<{1}>(this IActionRegistration registration, string commandName, System.Func<{1}, {0}> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);"
# System.Action has a slightly different signature so needs a tweaked template
imp_action_template = "public static void AddCommandHandler(this IActionRegistration registration, string commandName, System.Action handler) => registration.AddCommandHandler(commandName, (Delegate)handler);"
imp_action_numeric_template = "public static void AddCommandHandler<{1}>(this IActionRegistration registration, string commandName, System.Action<{1}> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);"
def gyb(count, types):
for type in types:
print(f"// These registrations for {type} were generated by action-gyb.py")
# generating the registration for the 0 parameter form
print(doc_template)
# true' if True else 'false'
template = imp_template if type != "System.Action" else imp_action_template
print(template.format(type))
# generating the registration for the 1->count parameter forms
for i in range(count):
print(doc_template)
# generating the <T1, T2> etc type values
r = ["T" + str(x) for x in range(1, i + 2)]
s = ", ".join(r)
template = imp_numeric_template if type != "System.Action" else imp_action_numeric_template
print(template.format(type, s))
print()
gyb(16, all_types)

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e1b7988914af942c8b524809f9eff521
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: