Skip to content

Game.UI.Menu.AssetUploadUtils

Assembly:
Assembly-CSharp (game)

Namespace:
Game.UI.Menu

Type:
public static class

Base:
static helper class (no explicit base)

Summary:
Utility helpers used by the in-game asset/mod upload UI. Contains routines to validate external links, copy various asset types between local asset databases (including maps, savegames, prefabs and their dependencies), collect prefab dependencies and assets used by prefabs, generate thumbnail atlases, and obtain preview URIs. Intended for preparing assets for upload/export and to manage references that need special handling (platform-specific assets, binary packing, external references).


Fields

  • private static Colossal.Logging.ILog sLog
    A logger instance used for error and debug logging inside the utility methods. Typically obtained with LogManager.GetLogger("AssetUpload").

Properties

  • public static IModsUploadSupport.ExternalLinkData defaultExternalLink { get; }
    Returns a default ExternalLinkData object with:
  • m_Type set to the first accepted external link type (IModsUploadSupport.ExternalLinkInfo.kAcceptedTypes[0].m_Type)
  • m_URL set to an empty string.
    Used as a default/placeholder external link value in UI code.

Constructors

  • None (static class)
    This is a static helper class — there are no public instance constructors.

Methods

  • public static bool LockLinkType(string url, out string type)
    Determines if a provided URL matches one of the known external link provider patterns (IModsUploadSupport.ExternalLinkInfo.kAcceptedTypes[i].m_URLs).
    Parameters:
  • url: the URL to inspect.
  • out type: set to the matched external link type string when a match is found.
    Returns: true if a provider pattern is matched and type is set; false otherwise.
    Notes: Performs case-insensitive comparisons and accepts both "host/" and "https://host/" prefixed forms when matching.

  • public static bool ValidateExternalLink(IModsUploadSupport.ExternalLinkData link)
    Validates a single ExternalLinkData.
    Behavior:

  • Accepts empty or whitespace URLs (returns true).
  • If non-empty, calls LockLinkType to ensure the URL pattern matches the declared m_Type.
    Returns true when valid; false when the URL does not match the declared type.

  • public static bool ValidateExternalLinks(IEnumerable<IModsUploadSupport.ExternalLinkData> links)
    Validates a sequence of ExternalLinkData objects by calling ValidateExternalLink for each. Returns false on the first invalid link; true if all are valid.

  • public static bool ValidateForumLink(string link)
    Simple validator for a forum link: returns true for empty/whitespace strings or when the link contains "paradoxplaza.com" (case-insensitive).

  • public static AssetData CopyPreviewImage(AssetData asset, ILocalAssetDatabase database, AssetDataPath path)
    Attempts to copy/convert the preview image for an asset into the provided database at the given path.
    Behavior:

  • If asset is ImageAsset: calls ImageAsset.Save with JPG format.
  • If asset is TextureAsset: calls SaveAsImageAsset to produce a JPG ImageAsset.
  • Exceptions are caught and logged; on error returns null.
    Returns the saved ImageAsset (AssetData) on success or null on failure.

  • public static void CopyAsset(AssetData asset, ILocalAssetDatabase database, Dictionary<AssetData, AssetData> processed, HashSet<IModsUploadSupport.ModInfo.ModDependency> externalReferences, bool copyReverseDependencies, bool binaryPackAssets, int platformID = 0)
    High-level copy entry point for an arbitrary asset. Dispatches to specialized copying depending on asset type:

  • MapMetadata -> CopyMap
  • SaveGameMetadata -> CopySave
  • PrefabAsset -> CopyPrefab (collects dependencies, may binary-pack prefabs, records external references for platform-specific assets)
  • Otherwise -> CopyAssetGeneric (keeps original GUID)
    Parameters:
  • asset: asset to copy
  • database: destination local asset database
  • processed: mapping of already processed source->destination assets to avoid duplication
  • externalReferences: set that will be populated with platform-specific dependencies (when source asset metadata platformID differs from platformID param)
  • copyReverseDependencies: if true, collect extra prefab dependencies (reverse links)
  • binaryPackAssets: if true, PrefabAssets may be binary-packed into the destination database (uses PrefabBase cloning)
  • platformID: platform filter; assets with SourceMeta.platformID > 0 and not matching this will be recorded as external references instead of copied

  • public static void CopyMap(MapMetadata metadata, ILocalAssetDatabase database, Dictionary<AssetData, AssetData> processed)
    Copies a map metadata and its related data into the destination database. Steps:

  • Copies MapInfo via .Copy(), copies underlying MapData via CopyAssetGeneric.
  • Copies preview, thumbnail, locale assets and climate asset where present.
  • Copies the MapMetadata itself and fixes its target reference, then calls Save() on metadata to persist.

  • public static void CopySave(SaveGameMetadata metadata, ILocalAssetDatabase database, Dictionary<AssetData, AssetData> processed)
    Copies a savegame metadata and its SaveInfo/SaveGameData into the destination database. Copies preview if present and persists the copied metadata.

  • public static void CopyPrefab(PrefabAsset prefabAsset, ILocalAssetDatabase database, Dictionary<AssetData, AssetData> processed, HashSet<IModsUploadSupport.ModInfo.ModDependency> externalReferences, bool copyReverseDependencies, bool binaryPackAssets, int platformID = 0)
    Copies a prefab and all of its non-game assets (dependencies) into the destination database. Main behavior:

  • Uses CollectPrefabAssetDependencies to gather dependent AssetData (optionally including reverse dependencies).
  • Skips assets already present in processed.
  • If an asset's SourceMeta.platformID is non-zero and does not match platformID, that asset is not copied; instead an external dependency entry is added to externalReferences.
  • If binaryPackAssets is true and the asset is a PrefabAsset, the prefab is loaded, cloned (PrefabBase.Clone) and saved into the destination database as a binary prefab asset (ContentType.Binary) without Unity dependencies.
  • Otherwise uses CopyAssetGeneric to copy the asset (with keepGuid set to false for LocaleAsset by default).
    Note: processed is updated mapping source->destination assets to prevent double-copying.

  • public static T CopyAssetGeneric<T>(T asset, ILocalAssetDatabase database, Dictionary<AssetData, AssetData> processed, bool keepGuid = false) where T : AssetData
    Generic copying helper that:

  • If asset already in processed returns the previously copied asset (typed).
  • Opens the source asset read stream, creates a new asset in destination database (database.AddAsset), copies bytes to destination write stream, and stores mapping in processed.
    Returns the newly created typed asset.

  • public static AssetData CopyAssetGeneric(AssetData asset, ILocalAssetDatabase database, Dictionary<AssetData, AssetData> processed, bool keepGuid = false)
    Non-generic variant of CopyAssetGeneric that works with AssetData base type. Same behavior as generic version but returns AssetData.

  • public static bool TryGetPreview(AssetData asset, out AssetData result)
    Tries to obtain a preview image asset from the supplied asset:

  • For SaveGameMetadata -> returns saveGameMetadata.target.preview
  • For MapMetadata -> returns mapMetadata.target.preview
  • For PrefabAsset -> loads prefab, tries to find a UIObject component and extract its m_Icon as an ImageAsset (using UIExtensions.TryGetImageAsset) Returns true and sets result when found; otherwise returns false and result = null.

  • public static string GetImageURI(AssetData asset)
    Returns a URI string for the asset's image:

  • If ImageAsset or TextureAsset, invokes ToUri on it.
  • Otherwise returns MenuHelpers.defaultPreview.ToUri() (a fallback preview image).

  • public static void CollectPrefabAssetDependencies(PrefabAsset prefabAsset, HashSet<AssetData> dependencies, bool collectReverseDependencies)
    Gathers AssetData objects referenced by the prefab and adds them to dependencies (excluding those from the game's built-in database). Steps:

  • Collects PrefabBase dependency graph via CollectPrefabDependencies.
  • For each PrefabBase found, calls GetAssets to collect associated AssetData (geometry, surfaces, textures, locale, icons).
  • Adds assets whose database != AssetDatabase.game.

  • public static void CollectPrefabDependencies(PrefabBase mainPrefab, HashSet<PrefabBase> prefabs, bool collectReverseDependencies)
    Collects the dependency graph of PrefabBase objects reachable from mainPrefab:

  • Depth-first traversal using a stack.
  • For each prefab, collects ComponentBase dependencies and then optionally augments the list via CollectExtraPrefabDependencies (reverse links / special zone/assetpack handling).
  • Adds prefabs to the prefabs set when they are external (prefab.asset.database != AssetDatabase.game).

  • private static void CollectExtraPrefabDependencies(PrefabBase prefab, PrefabBase mainPrefab, List<PrefabBase> prefabDependencies)
    Handles special dependency cases when collectReverseDependencies is enabled:

  • If prefab is a ZonePrefab and either equals mainPrefab or is an AssetPackItem containing mainPrefab, searches global prefab assets for SpawnableBuilding prefabs referencing this zone type and adds them.
  • If prefab is an AssetPackPrefab and equals mainPrefab, searches global prefab assets for AssetPackItem components that reference the pack and adds them.
    This method queries AssetDatabase.global.

  • private static void GetAssets(PrefabBase prefab, List<AssetData> assets)
    Collects AssetData referenced by a PrefabBase instance:

  • Adds prefab.asset.
  • If RenderPrefab: adds geometryAsset and surfaceAssets and associated texture assets (loads surface properties).
  • Adds locale assets returned by EditorPrefabUtils.GetLocaleAssets.
  • Adds icons returned by EditorPrefabUtils.GetIcons.
    This method is used when assembling the full set of assets to copy.

  • public static void CreateThumbnailAtlas(Dictionary<AssetData, AssetData> processed, ILocalAssetDatabase database)
    Creates an atlas (AtlasFrame) for preview thumbnails of processed prefabs and updates the copied prefabs to reference atlas URIs:

  • Iterates processed keys (source assets) and for each processed PrefabAsset attempts to locate icon ImageAssets in the processed mapping.
  • Tries to add each icon image to the atlasFrame (atlasFrame.TryAdd using ((ImageAsset)value).Load()).
  • If added, sets the corresponding component field on the copied prefab to a placeholder thumbnail URI ("thumbnail://insert thumbnail URI here") and saves the prefab.
  • If at least one thumbnail was added, adds the atlas to the destination database (database.AddAsset("ThumbnailAtlas", atlasFrame)) and deletes the original image assets from the database.
    Notes:
  • The method logs debug text to UnityEngine.Debug when adding icons.
  • It mutates the destination prefab assets and deletes the per-icon image assets in favor of a single atlas asset.

Usage Example

// Example: copy a prefab and its dependencies into a destination database
var processed = new Dictionary<AssetData, AssetData>();
var externalRefs = new HashSet<IModsUploadSupport.ModInfo.ModDependency>();
bool copyReverseDependencies = true;
bool binaryPackAssets = false;
int targetPlatformId = 0; // only copy assets intended for all platforms

AssetUploadUtils.CopyAsset(myPrefabAsset, destinationDatabase, processed, externalRefs, copyReverseDependencies, binaryPackAssets, targetPlatformId);

// After copying many assets you can create a thumbnail atlas to consolidate icons:
AssetUploadUtils.CreateThumbnailAtlas(processed, destinationDatabase);

// Example: validate an external link
var link = new IModsUploadSupport.ExternalLinkData { m_Type = "youtube", m_URL = "https://youtube.com/..." };
if (!AssetUploadUtils.ValidateExternalLink(link)) {
    // report validation error to user
}

Notes and tips: - Many methods expect a live ILocalAssetDatabase destination and a processed dictionary for de-duplication. Pass the same processed dictionary for an entire copy operation. - CopyPrefab records platform-specific external references instead of copying assets for mismatched platform IDs — those must be handled separately (e.g., listed as required dependencies). - Copying binary-packed prefabs uses PrefabBase.Clone and saves a binary prefab without Unity dependencies; use with caution and test in-editor/game to ensure compatibility.