using System;
namespace Unity.Pipeline.CodeReload
{
///
/// Marks a method as reloadable: edit its body directly in the original source file and
/// apply the file with the reload_file command (or the interpreter-backed variants). The
/// running instance picks up the new body without a domain reload. Bodies may touch members of
/// any accessibility, including private/protected/internal ones of the target type.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class CodeReloadAttribute : Attribute
{
///
/// Optional identifier for this reloadable method.
/// If not specified, uses TypeName.MethodName format.
///
public string Id { get; set; }
///
/// Whether this method requires main thread execution.
/// Defaults to true for Unity API safety.
///
public bool RequireMainThread { get; set; } = true;
}
///
/// Marks a parameterless instance method to be invoked after a code reload is applied to its
/// declaring component. Fires once per reload_file that binds at least one override on
/// the type, on every live instance — a place to re-initialize or refresh state when the code is
/// swapped (analogous to a domain-reload-free OnEnable). The method runs on the main thread;
/// exceptions are logged, not propagated. Only UnityEngine.Object-derived types are supported
/// (instances are discovered via FindObjectsByType).
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[JetBrains.Annotations.MeansImplicitUse]
public class OnCodeReloadAttribute : Attribute
{
}
///
/// Marks a compiled static method as the code reload override for a specific [CodeReload]
/// method. Emitted by the reload pipeline on the code it generates from an edited source file
/// (see SourceCodeTransformer); user code does not write it by hand.
///
/// Override signature: the original method's signature plus the target instance as the first
/// parameter. Example: void Update() becomes static void Update(TargetType instance).
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class CodeReloadOverrideMethodAttribute : Attribute
{
///
/// Target method identifier in format "TypeName.MethodName"
/// Must match a method marked with [CodeReload].
///
public string TargetMethodId { get; }
///
/// Optional description of what this code reload does.
/// Useful for debugging and code reload management.
///
public string Description { get; set; }
/// Mark a method as the code-reload override for the given target method.
/// Target method identifier, "TypeName.MethodName".
public CodeReloadOverrideMethodAttribute(string targetMethodId)
{
TargetMethodId = targetMethodId ?? throw new ArgumentNullException(nameof(targetMethodId));
}
}
}