禁用通过文件名(含扩展名)加载资源包。
资源包默认有三种查找同一资源的方式:完整资源路径、资源文件名和资源文件名(含扩展名)。完整路径会被序列化到资源包中,而文件名和文件名(含扩展名)是在从文件加载资源包时生成的。
示例:“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); } }