Skip to content

Game.UnityLicenseDependency

Assembly: Game
Namespace: Game.Modding.Toolchain.Dependencies

Type: class

Base: BaseDependency

Summary:
Manages the presence, installation and uninstallation (returning) of a Unity license required by the toolchain. Checks for license files in common Unity locations, waits for user activation when installing, and attempts to return a serial-based license via the Unity CLI when uninstalling. Uses CliWrap to invoke the Unity executable and reports state via the base dependency state machinery.


Fields

  • private static readonly string kSerialBasedLicenseFile
    Path to the serial-based Unity license file located in the common application data folder (Unity\Unity_lic.ulf). Used to detect a serial/license file that can be returned via the Unity CLI.

  • private static readonly string kNamedUserLicenseFile
    Path to the named-user (entitlement) Unity license file under the local application data folder (Unity\licenses\UnityEntitlementLicense.xml). Used as an alternative presence check for an activated Unity license.

Properties

  • public override string name { get; }
    Returns the user-visible name of the dependency: "Unity license".

  • public override string icon { get; }
    Path to the icon used in the UI: "Media/Toolchain/Unity.svg".

  • public override bool confirmUninstallation { get; }
    Indicates that uninstallation requires user confirmation (true).

  • public override LocalizedString installDescr { get; }
    Localized description shown for install: key "Options.WARN_TOOLCHAIN_INSTALL_UNITY_LICENSE".

  • public override LocalizedString uninstallMessage { get; }
    Localized message shown for uninstall/return: key "Options.WARN_TOOLCHAIN_UNITY_LICENSE_RETURN".

  • public override Type[] dependsOnInstallation { get; }
    Dependencies required before attempting installation. Contains UnityDependency so Unity must be present.

  • public override Type[] dependsOnUninstallation { get; }
    Dependencies required before attempting uninstallation. Contains UnityDependency.

  • public bool licenseExists { get; }
    Checks whether a Unity license is present by verifying either the serial-based license file or the named-user entitlement file exists. Returns true if either file exists.

Constructors

  • public UnityLicenseDependency()
    No explicit constructor in source; the default parameterless constructor is used. Initialization is minimal; most work happens in overridden methods as part of the toolchain lifecycle.

Methods

  • public override Task<bool> IsInstalled(CancellationToken token)
    Returns a completed Task with a boolean indicating whether the license exists (uses licenseExists property).

  • public override Task<bool> IsUpToDate(CancellationToken token)
    Always returns true (no concept of versioning for the license).

  • public override Task<bool> NeedDownload(CancellationToken token)
    Always returns false (license is not downloaded via the toolchain).

  • public override Task Download(CancellationToken token)
    No-op; returns a completed task.

  • public override async Task Install(CancellationToken token)
    Waits for the user to activate a Unity license. Behavior:

  • Sets dependency state to Installing with localized state key "WaitingUnityLicense".
  • Invokes the Unity executable once using CliWrap with arguments "-projectPath", UnityModProjectDependency.kProjectUnzipPath, "-quit" to trigger Unity activation UI/flow.
  • Waits (via AsyncUtils.WaitForAction) until licenseExists becomes true.
  • Throws OperationCanceledException when cancelled.
  • Propagates ToolchainException rethrows.
  • Wraps other exceptions in ToolchainException(ToolchainError.Install, this, inner).

  • public override async Task Uninstall(CancellationToken token)
    Attempts to return a serial-based Unity license (if present). Behavior:

  • If the serial-based license file exists (LongFile.Exists), sets state to Removing with key "ReturningUnityLicense".
  • Calls Unity with arguments "-returnlicense" and "-quit" via CliWrap, piping stdout/stderr to the dependency logger.
  • Throws OperationCanceledException when cancelled.
  • Propagates ToolchainException rethrows.
  • Wraps other exceptions in ToolchainException(ToolchainError.Uninstall, this, inner).

  • public override LocalizedString GetLocalizedState(bool includeProgress)
    Returns localized state strings based on base.state.m_State:

  • DependencyState.Installed => "Options.STATE_TOOLCHAIN[Activated]"
  • DependencyState.Installing => "Options.STATE_TOOLCHAIN[WaitingForActivation]"
  • DependencyState.NotInstalled => "Options.STATE_TOOLCHAIN[NotActivated]"
  • DependencyState.Removing => "Options.STATE_TOOLCHAIN[Returning]"
  • default => falls back to IToolchainDependency.GetLocalizedState(base.state, includeProgress)

Notes on errors and cancellation: - Install and Uninstall check the provided CancellationToken and will rethrow OperationCanceledException when cancellation is requested. - ToolchainException instances are rethrown unchanged so callers can handle specific toolchain errors. - Other exceptions are wrapped into ToolchainException with appropriate ToolchainError (Install or Uninstall).

Usage Example

// Example usage in an async context:
var dependency = new UnityLicenseDependency();
var ct = CancellationToken.None;

// Check if a Unity license is present
if (!await dependency.IsInstalled(ct))
{
    // Prompt user to activate Unity license in the Unity UI.
    // Install will launch Unity once to trigger activation and then wait until a license file is detected.
    await dependency.Install(ct);
}

// To return a serial-based license (if present):
await dependency.Uninstall(ct);