Rocky Lai 的技术博客

学习、思考、分享


  • 首页

  • 归档

  • 分类

  • 标签

  • 关于

AssetBundle 使用模式 (2)

发表于 2017-10-27   |   分类于 UnityKB

## 4.4. Patching with AssetBundles

给 AssetBundle 打补丁


Patching AssetBundles is as simple as downloading a new AssetBundle and replacing the existing one. If WWW.LoadFromCacheOrDownload or UnityWebRequest are used to manage an application’s cached AssetBundles, this is as simple as passing a different version parameter to the chosen API. (See the above links to the scripting reference for more details.)

给 AssetBundle 打补丁就如简单地下载一个新的 AssetBundle 然后替换已存在的。如果 WWW.LoadFromCacheOrDownload or UnityWebRequest 被用来管理应用已缓存的 AssetBundle,这个过程就是给所选的 API 传递不同的版本号一样简单。(可以参考上面的脚本参考链接来查看更多详情。)


The more difficult problem to solve in the patching system is detecting which AssetBundles to replace. A patching system requires two lists of information:

A list of the currently downloaded AssetBundles, and their versioning information A list of the AssetBundles on the server, and their versioning information

更困难的问题是解决补丁系统探测哪个 AssetBundle 需要被替换。一个补丁系统需要两个信息列表:

阅读全文 »

AssetBundle 使用模式 (1)

发表于 2017-04-18   |   分类于 UnityKB

This is the fifth chapter in a series of articles covering Assets, Resources and resource management in Unity 5.

这是 Unity 5 [资产, 资源和资源管理系列文章] 的第五篇。(译者注:原文太长,我拆分成了两部分,这是第一部分。)


The previous chapter in this series covered the fundamentals of AssetBundles, in particular the low-level behavior of various loading APIs. This chapter discusses problems and potential solutions to various aspects of using AssetBundles in practice.

上一篇文章涵盖了 [AssetBundle 基本知识],特别是多种加载用的 API 的底层行为。这篇会讨论真实使用 AssetBundle 碰到的问题和可能的解决方案。


### 4.1. Managing loaded Assets

管理加载后的资产


It is particularly critical to carefully control the size and number of loaded Objects in memory-sensitive environments. Unity does not automatically unload Objects when they are removed from the active scene. Asset cleanup is triggered at specific times, and it can also be triggered manually.

在性能要求高的环境中,要特别严格地,小心翼翼地控制加载的对象的数量和大小。当对象从当前场景中移除时,Unity 不会自动的卸载他们。资产的清理是在特殊的时间触发,当然它也可以手动来触发。


AssetBundles themselves must be carefully managed. An AssetBundle backed by a file on local storage (either in the Unity cache or one loaded via AssetBundle.LoadFromFile) has minimal memory overhead, rarely more than 10-40 kilobytes. This overhead can still become problematic when a large number of AssetBundles are present.

AssetBundle 必须要仔细的管理。来自本地存储文件的 AssetBundle(不管是从缓存或者是通过 AssetBundle.LoadFromFile加载的) 会有最小内存开销,一般不超过 10-40 kb。当存在大量 AssetBundle 时,这种开销仍然可能成为问题。


As most projects allow users to re-experience content (such as replaying a level), it’s important to know when to load or unload an AssetBundle. If an AssetBundle is unloaded improperly, it can cause Object duplication in memory. Improperly unloading AssetBundles can also result in undesirable behavior in certain circumstances, such as causing textures to go missing. To understand why this can happen, refer to the Inter-Object references section of the Assets, Objects, and serialization chapter.

大多数项目都允许用户对内容再次体验(比如重新玩一个关卡),知道什么时候加载和卸载 AssetBundle 是很重要的。如果一个 AssetBundle 被错误卸载,可能会引起内存中对象重复。错误卸载也可以在某些情况下引起不希望的结果,比如引起纹理丢失。要理解为什么这个会发生,请参照 [资产,对象和序列化] 章节的 内部对象引用 小结。


The most important thing to understand when managing assets and AssetBundles is the difference in behavior when calling AssetBundle.Unload with either a true or false argument.

要理解何时去管理资产和 AssetBunle,最重要的是理解调用 AssetBundle.Unload 的不同行为,不管其参数是 true 还是 false.


This API unloads the header information of the AssetBundle being called. The argument indicates whether to also unload all Objects instantiated from this AssetBundle. If it is true, then all Objects originating from the AssetBundle will also be immediately unloaded - even if they are currently being used in the active scene.
阅读全文 »

AssetBundle 基本知识

发表于 2017-01-08   |   分类于 UnityKB

This is the fourth chapter in a series of articles covering Assets, Resources and resource management in Unity 5.

这是 Unity 5 [资产, 资源和资源管理系列文章] 的第四篇。


This chapter discusses AssetBundles. It introduces the fundamental systems upon which AssetBundles are built, as well as the core APIs used to interact with AssetBundles. In particular, it discusses both the loading and unloading of AssetBundles themselves, as well as the loading and unloading of specific Asset and Objects from AssetBundles.

这篇将会探讨 AssetBundle,并介绍构建 AssetBundle 的基本系统和与它交互的核心 API。这篇文章也会特别地介绍 AssetBundle 和 AssetBundle 内的资产与对象的加载和卸载。


For more patterns and best practices on the uses of AssetBundles, see the next chapter in this series.

更多关于 AssetBundle 的使用模式和最佳实践,请看本系列文章中的下一篇。


### 3.1. Overview

概况


The AssetBundle system provides a method for storing one or more files in an archival format that Unity can index. The purpose of the system is to provide a data delivery method compatible with Unity’s serialization system. AssetBundles are Unity’s primary tool for the delivery and updating of non-code content after installation. This permits developers to reduce shipped asset size, minimize runtime memory pressure, and selectively load content that is optimized for the end-user’s device.

AssetBundle 系统提供了一种可以把一个或者多个文件存储到一个能被 Unity 识别的存档的方法。这个系统的目的是提供一个可以和 Unity 的序列化系统兼容的数据推送方法。AssetBundle 是 Unity 用来在应用安装后推送或者更新非代码内容的主力工具。开发者能够用它来减少资产的体积,缩短运行时内存压力,以及在不同的用户终端有选择的加载内容。

阅读全文 »

Hello 2017

发表于 2016-12-31   |   分类于 一点一滴

Goodbye 2016, Hello 2017 ~~ 愿新的一年打败各种 BUG~~

Resources 文件夹

发表于 2016-12-28   |   分类于 UnityKB

The Resources folder
—-

This is the third chapter in a series of articles covering Assets, Resources and resource management in Unity 5.

这是 Unity 5 [资产, 资源和资源管理系列文章]的第三篇。


This chapter discusses the Resources system. This is the system that allows developers to store Assets within one or more folders named Resources and to load or unload Objects
from those Assets at runtime using the Resources API.

这个章节将讨论 Resources 系统。这个系统可以让开发者通过 Resources API 加载或卸载存储在在一个或多个以 Resources 命名的文件夹中的资产。


### 2.1. Best Practices for the Resources System

Resources 系统的最佳实践


Don’t use it.

下面情况不要使用它

阅读全文 »

资源和 AssetBundle 指导

发表于 2016-12-15   |   分类于 UnityKB
This is a series of articles that provides an in-depth discussion of Assets and resource management in the Unity engine. It seeks to provide expert developers with deep, source-level knowledge of Unity’s Asset and serialization systems. It examines both the technical underpinnings of Unity’s AssetBundle system and the current best practices for employing them.

这是深度探讨 Unity 引擎中资源(Resource)和资产(Asset) 管理的系列文章。文章试图给高级开发者提供 Unity 资产和序列化系统的底层、代码级的知识,并且审视 Unity 的 AssetBundle 系统技术基础和当前使用它们的最佳实践。


The guide is broken down into four chapteros:

1. Assets, Objects and serialization discusses the low-level details of how Unity serializes Assets and handles references between Assets. It is strongly recommended that readers begin with this chapter as it defines terminology used throughout the guide.
2. The Resources folder discusses the built-in Resources API.
3. AssetBundle fundamentals builds on the information in chapter 1 to describe how AssetBundles operate, and discusses both the loading of AssetBundles and the loading of Assets from AssetBundles.
4. AssetBundle usage patterns is a long article discussing many of the topics surrounding the practical uses of AssetBundles. It includes sections on assigning Assets to AssetBundles and on managing loaded Assets, and describes many common pitfalls encountered by developers using AssetBundles.

系列文章将会拆分为四个章节:

  1. [资产,对象和序列化] 章节探讨 Unity 如何序列化资产和处理它们之间的引用的底层细节。强烈推荐从读者从这章开始阅读,因为它定义了贯穿这系列文章的术语。
  2. [Resources 文件夹] 探讨内置的 Resources API.
  3. [AssetBundle 基本知识] 在第一章的基础上描述 AssetBundles 怎么运转和加载 AssetBundles 及从 AssetBundles 加载资产。
  4. AssetBundle 使用模式 是一篇探讨很多 AssetBundle 的实际用途。它包括了给 AssetBundles 添加资产 和管理加载后的资产并描述了开发者使用 AssetBundles 时经常碰到的陷阱。

Note: This guide’s terms for Objects and Assets differ from Unity’s public API naming conventions.

注意:这系列文章中的对象和资产有别与 Unity API 命名约定中的对象和资产。

阅读全文 »
12…8
Rocky Lai

Rocky Lai

48 日志
4 分类
14 标签
GitHub 邮件
© 2014 - 2017 Rocky Lai
由 Hexo 强力驱动
主题 - NexT.Mist