文档

Unity Engine

Unity Engine

ContentLoadManager

The ContentLoadManager offers APIs for accessing content that has been built. It is primarily used to register content directories and access root content.
阅读时间1 分钟最后更新于 1 个月前

Definition

  • Type: Class
  • Namespace: Unity.Loading
  • Assembly: UnityEngine.ContentLoadModule
public static class ContentLoadManager

Remarks

In the Editor this is not typically used, because the content is available directly in the project using AssetDatabase and EditorSceneManager calls. However, it can be useful in Editor play mode to run the same loading case as the runtime and to try out the output of your content directory build, directly inside the Editor.

Examples

using Unity.Loading;using UnityEngine;namespace BuildDocExamples{ public class ContentLoadManager_GetRootAssetsExample : MonoBehaviour { // Example catalog ScriptableObject with a Loadable field public class MyContentCatalog : ScriptableObject { public Loadable<Texture2D> previewIcon; } void Start() { // After deploying a content directory next to the player, register it once at startup: var handle = ContentLoadManager.RegisterContentDirectory("/path/to/BuiltContent"); foreach (var catalog in ContentLoadManager.GetRootAssets<MyContentCatalog>()) { catalog.previewIcon.Load(); try { Texture2D icon = catalog.previewIcon.Target; // Use the icon... } finally { catalog.previewIcon.Release(); } } ContentLoadManager.UnregisterContentDirectory(handle); } }}

Static Methods

Method

Description

GetContentDirectoriesRetrieves an ordered list of content directories.
GetRootAssetsRetrieve all root assets of a specific type from all registered content directories.
RegisterContentDirectoryAdd the built-content in a directory to the ContentLoadManager. This makes it possible to load the contained Scenes and Assets.
UnregisterContentDirectoryRemove access to content that had been loaded from a content directory.