Runtime Studio API

Import Processor API

Register support for your own runtime file formats without replacing the import workflow.

Import Processor API

The Asset Importer plugin can support custom file formats without replacing the existing import workflow. Imported assets automatically use Import Review, duplicate detection, the Project panel, persistence, export, and runtime libraries.

Import pipeline

When a player imports a file, Runtime Studio:

  1. Creates a RuntimeAssetImportRequest.
  2. Finds registered IAssetImportProcessor instances.
  3. Calls CanImport on each processor.
  4. Uses the highest-priority processor that accepts the request.
  5. Imports one or more RuntimeImportedAsset values.
  6. Shows the results in Import Review.
  7. Adds approved assets to the runtime Project panel.

Create a processor

A processor identifies supported files, imports the source, and returns one or more RuntimeImportedAsset values.

csharp
using System;
using System.Collections.Generic;
using System.Text;
using Fullscreen.RuntimeStudio.AssetImporter.Runtime;
using UnityEngine;

public sealed class MyTextImportProcessor : IAssetImportProcessor
{
    public string ProcessorId => "my-game.text.processor";
    public string ImporterId => "my-game.text";
    public int Priority => 100;

    public bool CanImport(RuntimeAssetImportRequest request)
    {
        return string.Equals(
            request?.Extension,
            "txt",
            StringComparison.OrdinalIgnoreCase);
    }

    public IEnumerable<RuntimeImportedAsset> Import(RuntimeAssetImportRequest request)
    {
        var textAsset = new TextAsset(Encoding.UTF8.GetString(request.Bytes));
        textAsset.name = request.NameWithoutExtension;
        textAsset.hideFlags = HideFlags.DontSave;

        yield return new RuntimeImportedAsset(
            Guid.NewGuid().ToString("N"),
            textAsset,
            textAsset.name,
            request.TargetFolder,
            ImporterId,
            request.FileName,
            request.Bytes,
            "text/plain");
    }
}

Register the processor

Register the processor and file type from an IEditorModule.

csharp
public sealed class MyImportModule : IEditorModule
{
    public void Register(EditorModuleBuilder builder)
    {
        builder
            .AddDefaultAssetImportProcessor(new MyTextImportProcessor())
            .AddDefaultAssetImportFileType(
                new AssetImportFileType(
                    "my-game.text.files",
                    "Text Files",
                    "txt"));
    }
}

AssetImportFileType adds the format to the Runtime Studio file picker and the WebGL file browser. Direct registry registration is also available when a project needs it.

Multiple assets and sidecar files

One source file can produce models, materials, textures, animation clips, meshes, archive contents, or other multiple results. Give all results from one source a shared sourceId and a unique resultId for each output.

Use request.TryGetSourceFile to access a sidecar file such as an .mtl, texture, binary payload, or metadata file. Package related files in a .zip when distributing content to players.

Useful runtime classes

RuntimeImportedAssetManager parses and imports runtime assets. Its useful methods include TryImportBytes, TryImportRequest, and AddImportedAssets.

AssetImportProcessorRegistry registers processors. AssetImportFileTypeRegistry registers file extensions for the picker. RuntimeAssetImporterRegistry reports whether the current pipeline supports a file type.

ProcessorId identifies the registration and can change without breaking saved imports. ImporterId identifies imported assets in save data. Do not change ImporterId after shipping, or existing imported assets may not restore correctly.