AssetBundle.CreateFromFile使用时注意事项

在使用AssetBundle.CreateFromFile加载AssetBundle时有两点需要注意


1:在创建资源包时需要选择不压缩(unity5.x资源打包方式)

AssetBundleManifest amf  = BuildPipeline.BuildAssetBundles(assetPath , abbs ,BuildAssetBundleOptions.UncompressedAssetBundle , bTarget);

2:在读取时需要注意文件路径

如果打的 AssetBundle 包b.unity3d放在工程目录下的asb文件夹下,则此时路径为:Application.dataPath  + "/ASB/b.unity3d"

AssetBundle asb = AssetBundle.CreateFromFile(Application.dataPath  + "/ASB/b.unity3d");


附:

若使用www加载本地AssetBundle则需要在路径前加“file://”即

"file://" + Application.dataPath  + "/ASB/b.unity3d"


StreamingAssets目录下的资源不同平台的路径:

#if UNITY_EDITOR
		#if UNITY_EDITOR_OSX
		path = "file://" + Application.streamingAssetsPath+"/ASB_Ios/sound.unity3d";
		#else
		path = "file://" + Application.streamingAssetsPath+"/ASB_Android/sound.unity3d";
		#endif
#elif UNITY_ANDROID
		path = Application.streamingAssetsPath+"/ASB_Android/sound.unity3d";
#elif UNITY_IOS
		path = "file://"+Application.streamingAssetsPath+"/ASB_Ios/sound.unity3d";
	//	path = "file://"+Application.dataPath + "/Raw/ASB_Ios/sound.unity3d";// + filename;
#else
		path = Application.streamingAssetsPath+"/ASB_Android/sound.unity3d";
#endif



资源打包: http://blog.csdn.net/fucun1984686003/article/details/51683035

猜你喜欢

转载自blog.csdn.net/fucun1984686003/article/details/51682845