禁用 Asset Bundle LoadAsset 按文件名查找。
默认情况下,Asset Bundle 有三种查找相同资源的方法:完整资源路径、资源文件名以及带扩展名的资源文件名。完整路径序列化到 Asset Bundle 中,而文件名和带扩展名的文件名在从文件中加载 Asset Bundle 时生成。
示例:“Assets/Prefabs/Player.prefab”,“Player”和“Player.prefab”
此选项将在 Asset Bundle 中设置一个标志来防止创建资源文件名查找。此选项可节省运行时内存并提高资源包的加载性能。
其他资源: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 { //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) 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); } }