首页 > 技术文章 > u3d外部资源 打包与加载的问题

dragon2012 2014-08-07 16:39 原文

被坑了一下午,调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就是文件名,其实不是,是打包之前的文件名,我来个去

推荐阅读