被坑了一下午,調bug,u3d外部加載資源一會可以,一會不行,始終找不到問題,最后快下班的時候,重新試了一下,原來是資源打包之前的文件名,和之后的加載資源名必須一樣
[MenuItem("Custom Editor/Build AssetBundle From Selection Twice")] static void ExportResourceNoTrack() { // Bring up save panel string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d"); if (path.Length != 0) { // Build the resource file from the active selection. BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path); } }
打包代碼,他會把你當前選中的資源打包起來,當前的名字會被記錄下來
TextAsset txt = m_Download.assetBundle.Load(filename, typeof(TextAsset)) as TextAsset;
這個是加載資源的名字,我以為這個filename就是文件名,其實不是,是打包之前的文件名,我來個去