Version: 2021.3

BuildAssetBundleOptions.DisableLoadAssetByFileName

切换到手册

描述

禁用按照文件名称查找资源包 LoadAsset。

默认情况下,可通过三种方式查找资源包中的相同资源:完整资源路径、资源文件名称和带扩展名的资源文件名称。完整路径在资源包中进行了序列化,而文件名称以及带扩展名的文件名称是在从文件中加载资源包时生成的。

示例:“Assets/Prefabs/Player.prefab”、“Player”和“Player.prefab”

此选项将在资源包上设置一个标志,以防止创建资源文件名称查找。此选项会保存资源包的运行时内存和加载性能。

另请参阅:BuildAssetBundleOptions.DisableLoadAssetByFileNameLoadingWithExtension。

//Create a folder (right click in the Assets folder and go to Create>Folder), and name it “Editor” if it doesn’t already exist
//Place this script in the Editor folder

//This script creates a new Menu named “Build Asset” and new options within the menu named “Normal” and “Disable Load Asset By filename”. Click these menu items to build an AssetBundle into a folder.

using UnityEngine; using UnityEditor;

public class Example : MonoBehaviour { //Creates a new menu (Build Asset Bundles) and item (Normal) in the Editor [MenuItem("Build Asset Bundles/Normal")] static void BuildABsNone() { //Create a folder to put the Asset Bundle in. // This puts the bundles in your custom folder (this case it's "MyAssetBuilds") within the Assets folder. //Build AssetBundles with no special options BuildPipeline.BuildAssetBundles("Assets/MyAssetBuilds", BuildAssetBundleOptions.None, BuildTarget.StandaloneOSX); }

//Creates a new item (Disable Load Asset By Name) in the new Build Asset Bundles menu [MenuItem("Build Asset Bundles/Disable Load Asset By Name ")] static void BuildABsDisable() { //Build the AssetBundles in this mode BuildPipeline.BuildAssetBundles("Assets/MyAssetBuilds", BuildAssetBundleOptions.DisableLoadAssetByFileName, BuildTarget.StandaloneOSX); } }