Version: 2022.2

BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension

切换到手册

描述

禁用按照带扩展名的文件名称查找资源包 LoadAsset。

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

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

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

另请参阅:BuildAssetBundleOptions.DisableFileNameLoading。

//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 with Extension”. Click these menu items to build an AssetBundle into a folder.

using UnityEngine; using UnityEditor;

public class Example { //Creates a new menu (Build Asset Bundles) and item (Normal) in the Editor [MenuItem("Build Asset Bundles/Normal")] static void BuildABsNone() { //Build AssetBundles with no special options //They will be written in the custom folder ("MyAssetBuilds") which needs to exist prior to this call. BuildPipeline.BuildAssetBundles("Assets/MyAssetBuilds", BuildAssetBundleOptions.None, BuildTarget.StandaloneOSX); }

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