1.AssetBundle打包

unity 5.x版本AssetBundle打包,只需要设置好AssetBundle的名称后,unity会自动将其打包,无需处理其他,唯独需要做的是设置好个AssetBundle的名称。

注意:AssetBunlde的名称只能设置小写字母,即使你写成大写也会被自动转置成大写字母,而且名称中支持“/”,如:“AssetBundles/cube.unity3d”,.unity3d的后缀是自己设置的,可以不设置

代码:

  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.IO;
  4.  
  5. public class CreateAssetBundles : Editor {
  6.  
  7. [MenuItem("Tools/Build AssetBundles")]
  8. static void BuildAllAssetBundles()
  9. {
  10. BuildPipeline.BuildAssetBundles(Application.dataPath + "/AssetBundles", BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.Android);
  11. AssetDatabase.SaveAssets();
  12. AssetDatabase.Refresh();
  13. Debug.LogWarning("打包成功");
  14. }
  15.  
  16. [MenuItem("Tools/设置固定名")]
  17. public static void saveAsStaticName()
  18. {
  19. string Path = "Prefabs";
  20. string abName = "building.ab";
  21. SetVersionDirAssetName(Path, abName);//第一个参数是路径 第二个参数是Ab名字 默认前缀为 Application.dataPath + "/"+ Path
  22. }
  23.  
  24. [MenuItem("Tools/设定文件名")]
  25. public static void saveAsPrefabName()
  26. {
  27. string Path = "Prefabs";
  28. SetAssetNameAsPrefabName(Path);//第一个参数是路径
  29. }
  30.  
  31. public static void SetVersionDirAssetName(string fullPath, string abName)
  32. {
  33. var relativeLen = fullPath.Length + ; // Assets 长度
  34. fullPath = Application.dataPath + "/" + fullPath + "/";
  35.  
  36. if (Directory.Exists(fullPath))
  37. {
  38. EditorUtility.DisplayProgressBar("设置AssetName名称", "正在设置AssetName名称中...", 0f);
  39. var dir = new DirectoryInfo(fullPath);
  40. var files = dir.GetFiles("*", SearchOption.AllDirectories);
  41. for (var i = ; i < files.Length; ++i)
  42. {
  43. var fileInfo = files[i];
  44. EditorUtility.DisplayProgressBar("设置AssetName名称", "正在设置AssetName名称中...", 1f * i / files.Length);
  45. if (!fileInfo.Name.EndsWith(".meta"))
  46. {
  47. var basePath = fileInfo.FullName.Substring(fullPath.Length - relativeLen);//.Replace('\\', '/');
  48. var importer = AssetImporter.GetAtPath(basePath);
  49. if (importer && importer.assetBundleName != abName)
  50. {
  51. importer.assetBundleName = abName;
  52. }
  53. }
  54. }
  55. EditorUtility.ClearProgressBar();
  56. }
  57. }
  58.  
  59. public static void SetAssetNameAsPrefabName(string fullPath)
  60. {
  61. var relativeLen = fullPath.Length + ; // Assets 长度
  62. fullPath = Application.dataPath + "/" + fullPath + "/";
  63.  
  64. if (Directory.Exists(fullPath))
  65. {
  66. EditorUtility.DisplayProgressBar("设置AssetName名称", "正在设置AssetName名称中...", 0f);
  67. var dir = new DirectoryInfo(fullPath);
  68. var files = dir.GetFiles("*", SearchOption.AllDirectories);
  69. for (var i = ; i < files.Length; ++i)
  70. {
  71. var fileInfo = files[i];
  72. string abName = fileInfo.Name;
  73. EditorUtility.DisplayProgressBar("设置AssetName名称", "正在设置AssetName名称中...", 1f * i / files.Length);
  74. if (!fileInfo.Name.EndsWith(".meta"))
  75. {
  76. var basePath = fileInfo.FullName.Substring(fullPath.Length - relativeLen);//.Replace('\\', '/');
  77. var importer = AssetImporter.GetAtPath(basePath);
  78. //abName = AssetDatabase.AssetPathToGUID(basePath);
  79. if (importer && importer.assetBundleName != abName)
  80. {
  81. importer.assetBundleName = abName;
  82. }
  83. }
  84. }
  85. EditorUtility.ClearProgressBar();
  86. }
  87. }
  88.  
  89. /// <summary>
  90. /// AssetBundleManifestName == 对应AB依赖列表文件
  91. /// </summary>
  92.  
  93. private static string AssetBundle_BuildDirectory_Path = @Application.streamingAssetsPath + "/../../../" + "AssetBundles";
  94. private static string AssetBundle_TargetDirectory_Path = @Application.streamingAssetsPath + "/" + "ABFiles";
  95. [MenuItem("Tools/Asset Bundle/Build Asset Bundles", false, )]
  96. public static void BuildAssetBundleAndroid()
  97. {
  98. //Application.streamingAssetsPath对应的StreamingAssets的子目录
  99. DirectoryInfo AB_Directory = new DirectoryInfo(AssetBundle_BuildDirectory_Path);
  100. if (!AB_Directory.Exists)
  101. {
  102. AB_Directory.Create();
  103. }
  104. FileInfo[] filesAB = AB_Directory.GetFiles();
  105. foreach (var item in filesAB)
  106. {
  107. Debug.Log("******删除旧文件:" + item.FullName + "******");
  108. item.Delete();
  109. }
  110. #if UNITY_ANDROID
  111. BuildPipeline.BuildAssetBundles(AB_Directory.FullName, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.Android);
  112. #elif UNITY_IPHONE
  113. BuildPipeline.BuildAssetBundles(AB_Directory.FullName, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.iOS);
  114. #else
  115. BuildPipeline.BuildAssetBundles(AB_Directory.FullName, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows64);
  116. #endif
  117. Debug.Log("******AssetBundle打包完成******");
  118.  
  119. Debug.Log("将要转移的文件夹是:" + AssetBundle_TargetDirectory_Path);
  120. FileInfo[] filesAB_temp = AB_Directory.GetFiles();
  121.  
  122. DirectoryInfo streaming_Directory = new DirectoryInfo(AssetBundle_TargetDirectory_Path);
  123.  
  124. FileInfo[] streaming_files = streaming_Directory.GetFiles();
  125. foreach (var item in streaming_files)
  126. {
  127. item.Delete();
  128. }
  129. AssetDatabase.Refresh();
  130. foreach (var item in filesAB_temp)
  131. {
  132. if (item.Extension == "")
  133. {
  134. item.CopyTo(AssetBundle_TargetDirectory_Path + "/" + item.Name, true);
  135. }
  136. }
  137. AssetDatabase.Refresh();
  138. Debug.Log("******文件传输完成******");
  139. }
  140.  
  141. private static string _dirName = "";
  142. /// <summary>
  143. /// 批量命名所选文件夹下资源的AssetBundleName.
  144. /// </summary>
  145. [MenuItem("Tools/Asset Bundle/Set Asset Bundle Name")]
  146. static void SetSelectFolderFileBundleName()
  147. {
  148. UnityEngine.Object[] selObj = Selection.GetFiltered(typeof(Object), SelectionMode.Unfiltered);
  149. foreach (Object item in selObj)
  150. {
  151. string objPath = AssetDatabase.GetAssetPath(item);
  152. DirectoryInfo dirInfo = new DirectoryInfo(objPath);
  153. if (dirInfo == null)
  154. {
  155. Debug.LogError("******请检查,是否选中了非文件夹对象******");
  156. return;
  157. }
  158. _dirName = dirInfo.Name;
  159.  
  160. string filePath = dirInfo.FullName.Replace('\\', '/');
  161. filePath = filePath.Replace(Application.dataPath, "Assets");
  162. AssetImporter ai = AssetImporter.GetAtPath(filePath);
  163. ai.assetBundleName = _dirName;
  164.  
  165. SetAssetBundleName(dirInfo);
  166. }
  167. AssetDatabase.Refresh();
  168. Debug.Log("******批量设置AssetBundle名称成功******");
  169. }
  170. static void SetAssetBundleName(DirectoryInfo dirInfo)
  171. {
  172. FileSystemInfo[] files = dirInfo.GetFileSystemInfos();
  173. foreach (FileSystemInfo file in files)
  174. {
  175. if (file is FileInfo && file.Extension != ".meta" && file.Extension != ".txt")
  176. {
  177. string filePath = file.FullName.Replace('\\', '/');
  178. filePath = filePath.Replace(Application.dataPath, "Assets");
  179. AssetImporter ai = AssetImporter.GetAtPath(filePath);
  180. ai.assetBundleName = _dirName;
  181. }
  182. else if (file is DirectoryInfo)
  183. {
  184. string filePath = file.FullName.Replace('\\', '/');
  185. filePath = filePath.Replace(Application.dataPath, "Assets");
  186. AssetImporter ai = AssetImporter.GetAtPath(filePath);
  187. ai.assetBundleName = _dirName;
  188. SetAssetBundleName(file as DirectoryInfo);
  189. }
  190. }
  191. }
  192. /// <summary>
  193. /// 批量清空所选文件夹下资源的AssetBundleName.
  194. /// </summary>
  195. [MenuItem("Tools/Asset Bundle/Reset Asset Bundle Name")]
  196. static void ResetSelectFolderFileBundleName()
  197. {
  198. UnityEngine.Object[] selObj = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Unfiltered);
  199. foreach (UnityEngine.Object item in selObj)
  200. {
  201. string objPath = AssetDatabase.GetAssetPath(item);
  202. DirectoryInfo dirInfo = new DirectoryInfo(objPath);
  203. if (dirInfo == null)
  204. {
  205. Debug.LogError("******请检查,是否选中了非文件夹对象******");
  206. return;
  207. }
  208. _dirName = null;
  209.  
  210. string filePath = dirInfo.FullName.Replace('\\', '/');
  211. filePath = filePath.Replace(Application.dataPath, "Assets");
  212. AssetImporter ai = AssetImporter.GetAtPath(filePath);
  213. ai.assetBundleName = _dirName;
  214.  
  215. SetAssetBundleName(dirInfo);
  216. }
  217. AssetDatabase.Refresh();
  218. Debug.Log("******批量清除AssetBundle名称成功******");
  219. }
  220. }

上述代码中有一些测试函数,使用时可进行测试

2.AssetBundle加载

下述代码中,cube,sphere等都是在unity项目中自己创建的3d预制体,自行创建即可。创建完成使用1中的方法打包AssetBundle。注意代码中的cube大小写问题,小写的是设置的AssetBundle名称,大写的是Cube预制体的名称,不要混淆。

代码:

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class AssetBundleLoad : MonoBehaviour {
  6.  
  7. // Use this for initialization
  8. void Start () {
  9. this.load1();
  10. //this.load2();
  11. //this.load3();
  12. //this.load4();
  13. }
  14.  
  15. void load1()
  16. {
  17. //1.先加载cube后加载sphere
  18. //这种方式并没有先加载cube的依赖文件,按理说应该加载出来的cube上是sphere是missing的,但是unity5.6.3f1
  19. //加载并未missing,不知是不是unity版本的优化,不过好习惯还是先加载依赖文件,如load2()。
  20.  
  21. //加载assetbundlemanifest文件
  22. AssetBundle assetBundleManifest = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/AssetBundles");
  23. if(null != assetBundleManifest)
  24. {
  25. AssetBundleManifest manifest = assetBundleManifest.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
  26.  
  27. //加载cube
  28. AssetBundle bundle = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/cube.prefab");
  29. GameObject obj = bundle.LoadAsset<GameObject>("Cube");
  30. if(null != obj)
  31. {
  32. GameObject cube = Instantiate(obj);
  33. cube.transform.SetParent(GameObject.Find("UIRoot").transform);
  34. }
  35.  
  36. //加载cube的依赖文件
  37. string[] depends = manifest.GetAllDependencies("cube.prefab");
  38. AssetBundle[] dependsAssetbundle = new AssetBundle[depends.Length];
  39. for(int index = ; index < depends.Length; ++index)
  40. {
  41. dependsAssetbundle[index] = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/" + depends[index]);
  42.  
  43. obj = dependsAssetbundle[index].LoadAsset<GameObject>("Sphere");
  44. if (null != obj)
  45. {
  46. GameObject sphere = Instantiate(obj);
  47. sphere.transform.SetParent(GameObject.Find("UIRoot").transform);
  48. }
  49. }
  50. }
  51. }
  52.  
  53. void load2()
  54. {
  55. //2.先加载sphere再加载cube
  56.  
  57. //加载assetBundleManifest文件
  58. AssetBundle assetBundleManifest = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/AssetBundles");
  59. if(null != assetBundleManifest)
  60. {
  61. AssetBundleManifest manifest = assetBundleManifest.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
  62.  
  63. //加载cube依赖文件
  64. string[] depends = manifest.GetAllDependencies("cube.prefab");
  65. AssetBundle[] dependsAssetbundle = new AssetBundle[depends.Length];
  66. for (int index = ; index < depends.Length; ++index)
  67. {
  68. dependsAssetbundle[index] = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/" + depends[index]);
  69.  
  70. GameObject obj1 = dependsAssetbundle[index].LoadAsset<GameObject>("Sphere");
  71. if (null != obj1)
  72. {
  73. GameObject sphere = Instantiate(obj1);
  74. sphere.transform.SetParent(GameObject.Find("UIRoot").transform);
  75. }
  76. }
  77.  
  78. //加载cube
  79. AssetBundle bundle = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/cube.prefab");
  80. GameObject obj = bundle.LoadAsset<GameObject>("Cube");
  81. if(null != obj)
  82. {
  83. GameObject sphere = Instantiate(obj);
  84. sphere.transform.SetParent(GameObject.Find("UIRoot").transform);
  85. }
  86. }
  87. }
  88.  
  89. void load3()
  90. {
  91. //3.只加载cube不加载sphere
  92.  
  93. //无需加载assetBundleManifest文件,直接加载cube
  94. AssetBundle bundle = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/cube.prefab");
  95. GameObject obj = bundle.LoadAsset<GameObject>("Cube");
  96. if (null != obj)
  97. {
  98. GameObject sphere = Instantiate(obj);
  99. sphere.transform.SetParent(GameObject.Find("UIRoot").transform);
  100. }
  101. }
  102.  
  103. void load4()
  104. {
  105. //4.两个预制打包成同一个AssetBundle
  106.  
  107. //无需加载assetBundleManifest文件,直接加载cube
  108. AssetBundle bundle = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/cube2.prefab");
  109. GameObject obj = bundle.LoadAsset<GameObject>("Cube_1");
  110. if (null != obj)
  111. {
  112. GameObject cube = Instantiate(obj);
  113. cube.transform.SetParent(GameObject.Find("UIRoot").transform);
  114. }
  115.  
  116. obj = bundle.LoadAsset<GameObject>("Cube_2");
  117. if (null != obj)
  118. {
  119. GameObject cube = Instantiate(obj);
  120. cube.transform.SetParent(GameObject.Find("UIRoot").transform);
  121. }
  122. }
  123. }
  1. using UnityEngine;
  2.  
  3. public class Relation : MonoBehaviour {
  4. //挂在cube预制上的测试脚本
  5. public GameObject sphere_go;
  6. public GameObject capsule_go;
  7. // Use this for initialization
  8. void Start () {
  9. ScriptRelation t = new ScriptRelation();
  10. t.printLog();
  11. }
  12.  
  13. // Update is called once per frame
  14. void Update () {
  15.  
  16. }
  17. }
  1. using UnityEngine;
  2.  
  3. public class ScriptRelation{
  4.  
  5. public void printLog()
  6. {
  7. Debug.Log("xxxxxxxxxxxxxxxxxx");
  8. }
  9. }
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TestAssetBundle : MonoBehaviour {
  6.  
  7. public string AssetBundleName = "cube";
  8.  
  9. private string dir = "";
  10. private AssetBundle bundle = null;
  11. private Object asset = null;
  12. private GameObject go = null;
  13.  
  14. private AssetBundleManifest manifest = null;
  15.  
  16. // Use this for initialization
  17. void Start () {
  18. dir = Application.dataPath + "/AssetBundles/";
  19. }
  20.  
  21. void OnGUI()
  22. {
  23. if (GUILayout.Button("LoadAssetBundle", GUILayout.Width(), GUILayout.Height())) { LoadBundle(); }
  24. if (GUILayout.Button("LoadAsset", GUILayout.Width(), GUILayout.Height())) { LoadAsset(); }
  25. if (GUILayout.Button("Instantiate", GUILayout.Width(), GUILayout.Height())) { Instantiate(); }
  26. if (GUILayout.Button("Destory", GUILayout.Width(), GUILayout.Height())) { Destroy(); }
  27. if (GUILayout.Button("Unload", GUILayout.Width(), GUILayout.Height())) { UnLoad(); }
  28. if (GUILayout.Button("UnloadForce", GUILayout.Width(), GUILayout.Height())) { UnLoadForce(); }
  29. if (GUILayout.Button("UnloadUnusedAssets", GUILayout.Width(), GUILayout.Height())) { UnloadUnusedAssets(); }
  30.  
  31. //bundle依赖包加载
  32. if (GUILayout.Button("LoadAssetBundleManifest", GUILayout.Width(), GUILayout.Height())) { LoadAssetBundleManifest(); }
  33. if (GUILayout.Button("LoadBundleAndDeps", GUILayout.Width(), GUILayout.Height())) { LoadBundleAndDeps(); }
  34. }
  35.  
  36. void LoadBundle()
  37. {
  38. bundle = AssetBundle.LoadFromFile(System.IO.Path.Combine(dir, AssetBundleName));
  39. if(null == bundle)
  40. {
  41. Debug.LogError("LoadBundle Failed");
  42. }
  43. }
  44.  
  45. void LoadAsset()
  46. {
  47. if (null == bundle) return;
  48.  
  49. asset = bundle.LoadAsset<Object>("Cube");
  50. if (null == asset) Debug.LogError("LoadAsset Failed");
  51. }
  52.  
  53. void Instantiate()
  54. {
  55. if (null == asset) return;
  56.  
  57. go = GameObject.Instantiate<Object>(asset) as GameObject;
  58. if (null == go) Debug.LogError("Instantiate Failed");
  59. else
  60. {
  61. go.transform.SetParent(GameObject.Find("UIRoot").transform);
  62. }
  63. }
  64.  
  65. void Destroy()
  66. {
  67. if (null == go) return;
  68.  
  69. GameObject.Destroy(go);
  70. go = null;
  71. }
  72.  
  73. /**
  74. * AssetBundle.unload(bool unloadAllLoadedObjects) 接口用来卸载AssetBundle文件。
  75. * 参数为false时,调用该接口后,只会卸载AssetBundle对象自身,并不会影响AssetBundle中加载的Assets。
  76. * 参数为true时,除了AssetBundle对象自身,所有从当前AssetBundle中加载的Assets也会被同时卸载,不管这个Assets是否还在使用中。
  77. * 官方推荐参数一般设置为false,只有当很明确知道从AssetsBundle中加载的Assets不会被任何对象引用时,才将参数设置成true。
  78. **/
  79. void UnLoad()
  80. {
  81. if (null == bundle) return;
  82.  
  83. bundle.Unload(false);
  84. //GameObject.Instantiate<Object>(asset); //asset可用
  85. asset = null;
  86. bundle = null;
  87. }
  88.  
  89. void UnLoadForce()
  90. {
  91. if (null == bundle) return;
  92.  
  93. bundle.Unload(true);
  94. //GameObject.Instantiate<Object>(asset); //报错:asset已被销毁
  95. asset = null;
  96. bundle = null;
  97. }
  98.  
  99. void UnloadUnusedAssets()
  100. {
  101. Resources.UnloadUnusedAssets();
  102. }
  103.  
  104. void LoadAssetBundleManifest()
  105. {
  106. var bundle = AssetBundle.LoadFromFile(System.IO.Path.Combine(dir, "AssetBundles"));
  107. manifest = bundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
  108.  
  109. //unload
  110. bundle.Unload(false);
  111. bundle = null;
  112. }
  113.  
  114. void LoadBundleAndDeps()
  115. {
  116. string bundleName = "cube";
  117.  
  118. string[] dependence = manifest.GetDirectDependencies(bundleName);
  119. for(int i=; i<dependence.Length; ++i)
  120. {
  121. AssetBundle.LoadFromFile(System.IO.Path.Combine(dir, dependence[i]));
  122. }
  123.  
  124. var bundle = AssetBundle.LoadFromFile(System.IO.Path.Combine(dir, bundleName));
  125. var asset = bundle.LoadAsset<GameObject>("Cube");
  126. bundle.Unload(false);
  127. bundle = null;
  128. go = GameObject.Instantiate<GameObject>(asset);
  129. }
  130. }

上述代码有两个测试脚本,AssetBundleLoad.cs只做了AssetBudle加载的测试。TestAssetBundle.cs做了AssetBundle加载,卸载,使用等测试,比较完整。

3.unity项目中的3个特殊文件夹

a.Resources(只读)

Resources文件夹下的资源会被全部打包到apk或者ipa里面,相当与一个unity默认的AssetBundle,按理说是可以将游戏中所有的资源全部放在Resources进行加载,但是

Resources下的文件数量会影响游戏的启动速度,越多越慢。其次游戏为了降低drawcall,需要对相同材质的图像打包图集,但是如果放在Resources里面是没法打包图集的。

Resources下的资源打包时会进行压缩

b.StreamingAssets(只读)

StreamingAssets文件夹下的资源会被全部打包到apk或者ipa里面

StreamingAssets文件夹下的资源不会影响游戏启动速度

StreamingAssets文件夹下的资源不会被压缩,所以占用内存较大

c.persistentDataPath(可读写)

persistentDataPath文件夹在unity项目中是不存在的,他是程序的沙盒文件夹,只有你游戏安装完成之后,才会存在这个目录,但是它可读写。

综上三种文件夹,我们自己在使用时,Resources里面放的资源只是在本地开发阶段使用,打包的时候会把Resources中的文件都考本出去打成AssetBundle包,然后再将打包好的AssetBundle放到StreamingAssets文件夹下打包apk。

游戏运行时再将资源考本到persistentDataPath文件夹下,因为这个目录可读写,所以能够用来做资源热更新。

如有错误,敬请指正。

///////////****以下摘自:http://www.cnblogs.com/jiangshuai52511/p/6437239.html  作者:凉城旧巷旧少年 ******/////////

5.3.针对项目的建议

由于以上分析的几种加载手段各有各的使用情景和特点。因此建议在我们的项目中按照以下情景使用这些方法:

  • 随游戏一同发布的AssetBundle(一般位于StreamingAssets文件夹中):
  • 在打AssetBundle包时,使用LZ4压缩格式进行打包(开启BuildAssetBundleOptions.ChunkBasedCompression即可)。
  • 在运行时需要加载AssetBundle对象时,使用LoadFromFile方法进行加载。
  • 这样做的好处是:即可以将AssetBundle文件压缩,又可以兼顾加载速度,且节约内存。
  • 作为更新包,需要从服务端下载的AssetBundle:
  • 在打AssetBundle包时,使用默认的LZMA格式压缩。
  • 使用http://WWW.LoadFromCacheOrDownload方法下载并缓存AssetBundle包文件。
  • 这样做的好处是:获得了最大的压缩率,在下载过程中可以减少数据传输量。同时,在本地磁盘创建缓存之后,又可以兼顾之后的加载速度,且节约内存。
  • 我们自己进行加密的AssetBundle:
  • 在打AssetBundle包时,使用LZ4压缩格式进行打包(开启BuildAssetBundleOptions.ChunkBasedCompression即可)。
  • 在运行时需要加载AssetBundle对象时,使用LoadFromMemory方法进行加载。(这也是从内存中使用流数据加载AssetBundle对象的仅有的使用场景。)
  • 我们自己压缩的AssetBundle:
  • 我们自己也可以使用第三方库或工具对生成的AssetBundle包文件进行压缩,如果需要这样做,则我们最好不要再使用Unity3D对 AssetBundle进行压缩,因此在打包时选择开启 BuildAssetBundleOptions.UncompressedAssetBundle。
  • 在运行时需要加载AssetBundle对象时,使用LoadFromFileAsync方法进行异步加载。

///////////****以上摘自:http://www.cnblogs.com/jiangshuai52511/p/6437239.html  作者:凉城旧巷旧少年 ******/////////

参考文章:

http://www.xuanyusong.com/archives/3229

http://www.cnblogs.com/AaronBlogs/p/6837682.html

http://www.cnblogs.com/kanekiken/p/7533510.html

http://www.cnblogs.com/murongxiaopifu/p/4199541.html

http://www.cnblogs.com/jiangshuai52511/p/6437239.html

http://blog.csdn.net/u010377179/article/category/6413676/3

http://blog.csdn.net/suifcd/article/details/51570003

AssetBundle内存相关:

http://blog.csdn.net/sgnyyy/article/details/39268215

Unity3d 5.x AssetBundle打包与加载的更多相关文章

  1. Unity5 AssetBundle 打包以及加载

    using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEditor; us ...

  2. [Unity] unity5.3 assetbundle打包及加载

    Unity5.3更新了assetbundle的打包和加载api,下面简单介绍使用方法及示例代码. 在Unity中选中一个prefab查看Inspector窗口,有两个位置可以进行assetbundle ...

  3. AssetBundle资源打包与加载

    AssetBundle资源打包  1.AssetLabels资源标签 文件名:资源打包成AssetBundle后的文件名,类似于压缩包的名字 后缀:自定义 文件名和后缀名都是小写格式(大写会自动转为小 ...

  4. unity中ScriptableObject在assetbundle中的加载

    转载请标明出处:http://www.cnblogs.com/zblade/ 以前都是写一些个人的调研博客,从今天开始,也写一些个人在开发中遇到的一些可以分享的趟坑博客,为后续的开发人员提供一些绵薄之 ...

  5. Assetbundle管理与加载

    最近在做项目优化的时候发现公司的项目用的还是老式的WWW去加载assetbundle资源的形式,而且是通过在两个Update里面分开加载AB和Asset的,这样虽然避免了协程的的使用,但是把一件事分开 ...

  6. Assetbundle创建与加载

    [Assetbundle创建与加载] Unity有两种动态加载机制:一种是Resource.Load.一种是AssetBundle.Assetbundle是Unity Pro提供的功能,它可以把多个游 ...

  7. Unity3d通用工具类之数据配置加载类-ini配置文件加载

    Unity3d通用工具类之数据配置加载类-ini配置文件加载 上次我们讲过xml文件的加载配置管理,今天我们换个配置文件,也是比较常见的配置文件.ini格式的数据. 按照国际管理先贴一张啥是.ini文 ...

  8. Unity3D AssetBundle的打包与加载

    在Unity项目开发过程中,当要做热更新时常常使用一个叫做AssetBundle的东西,这里做一点个人的学习记录 步骤1: 设置打包标签:具体步骤----进入Unity,选择某一资源然后看右下角,在那 ...

  9. KEngine:Unity3D资源的打包、加载、调试监控

    资源模块做什么? 资源模块——ResourceModule,是KEngine中最核心的模块,其他模块基本或多或少的对它有依赖,它主要的功能是:资源打包.路径定义.资源管理.资源调试. 资源模块对Uni ...

随机推荐

  1. js清除cookie有时无法清除

    最近写页面遇到一个问题,退出的时候需要清除cookie,但是刚开始一直清除不掉,代码如下: //清除函数 function delCookie(name) { var date= new Date() ...

  2. 《RabbitMQ Tutorial》译文 第 6 章 远程过程调用(RPC)

    原文来自 RabbitMQ 英文官网的教程(6.Remote procedure call - RPC),其示例代码采用了 .NET C# 语言. In the second tutorial we ...

  3. (转)java内部类详解

    本文转自http://www.cnblogs.com/dolphin0520/p/3811445.html,谢谢作者 说起内部类这个词,想必很多人都不陌生,但是又会觉得不熟悉.原因是平时编写代码时可能 ...

  4. sql对每一条记录都给他一个随机的数。

    update [WonyenMall].[dbo].[T_Real_Commodity] set increment=FLOOR(RAND(ABS(CHECKSUM(NEWID()))) * 100) ...

  5. iOS Button 上文字图片位置的设置

    1. 添加图片+文字/文字+图片 ,不分前后,图片默认在文字前边 加空格隔开 UIButton * button =[[UIButton alloc] initWithFrame:CGRectMake ...

  6. Java I/O---输入与输出

    编程语言的I/O类库中常使用流这个抽象概念, 它代表任何有能力产出数据的数据源对象或者是有能力接收数据的接收端对象. "流" 屏蔽了实际的I/O设备中处理数据的细节.Java类库中 ...

  7. Cat 客户端采用什么策略上报消息树

    策略分类 目前搞清楚两种 第一种(蓝色):默认服务器列表中选一个,算法核心是根据应用名的哈希值取模.也就是说同一个应用始终打到同一台服务器上,如果这台服务器挂了,另选一台服务器. 第二种(红色):应用 ...

  8. lesson - 8 课程笔记 tar / gzip /bzip2 / xz /

    作用:为linux的文件和目录创建档案,也可以在档案中改变文件,或者向档案中加入新的文件即用来压缩和解压文件.tar本身不具有压缩功能.他是调用压缩功能实现的  语法:tar[必要参数][选择参数][ ...

  9. 基于telegraf+influxdb+grafana进行postgresql数据库监控

    前言 随着公司postgresql数据库被广泛应用,尤其是最近多个项目在做性能测试的时候都是基于postgresql的数据库,为了确定性能瓶颈是否会出现在数据库中,数据库监控也被我推上了日程.在网上找 ...

  10. 阅读MDN文档之CSS选择器介绍(一)

    本文为阅读MDN文档笔记 目录 Different types of Selectors Attribute Selectors Presence and value attribute select ...